vector-cast.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // RUN: %clang_cc1 -fsyntax-only %s -verify -Wvector-conversion
  2. typedef long long t1 __attribute__ ((vector_size (8)));
  3. typedef char t2 __attribute__ ((vector_size (16)));
  4. typedef float t3 __attribute__ ((vector_size (16)));
  5. void f()
  6. {
  7. t1 v1;
  8. t2 v2;
  9. t3 v3;
  10. v2 = (t2)v1; // expected-error {{invalid conversion between vector type \
  11. 't2' (vector of 16 'char' values) and 't1' (vector of 1 'long long' value) of different size}}
  12. v1 = (t1)v2; // expected-error {{invalid conversion between vector type \
  13. 't1' (vector of 1 'long long' value) and 't2' (vector of 16 'char' values) of different size}}
  14. v3 = (t3)v2;
  15. v1 = (t1)(char *)10; // expected-error {{invalid conversion between vector \
  16. type 't1' (vector of 1 'long long' value) and scalar type 'char *'}}
  17. v1 = (t1)(long long)10;
  18. v1 = (t1)(short)10; // expected-error {{invalid conversion between vector \
  19. type 't1' (vector of 1 'long long' value) and integer type 'short' of different size}}
  20. long long r1 = (long long)v1;
  21. short r2 = (short)v1; // expected-error {{invalid conversion between vector \
  22. type 't1' (vector of 1 'long long' value) and integer type 'short' of different size}}
  23. char *r3 = (char *)v1; // expected-error {{invalid conversion between vector\
  24. type 't1' (vector of 1 'long long' value) and scalar type 'char *'}}
  25. }
  26. void f2(t2 X); // expected-note{{passing argument to parameter 'X' here}}
  27. void f3(t3 Y) {
  28. f2(Y); // expected-warning {{incompatible vector types passing 't3' (vector of 4 'float' values) to parameter of type 't2' (vector of 16 'char' values)}}
  29. }
  30. typedef float float2 __attribute__ ((vector_size (8)));
  31. void f4() {
  32. float2 f2;
  33. double d;
  34. f2 += d;
  35. d += f2;
  36. }
  37. // rdar://15931426
  38. // Don't permit a lax conversion to and from a pointer type.
  39. typedef short short_sizeof_pointer __attribute__((vector_size(sizeof(void*))));
  40. void f5() {
  41. short_sizeof_pointer v;
  42. void *ptr;
  43. v = ptr; // expected-error-re {{assigning to 'short_sizeof_pointer' (vector of {{[0-9]+}} 'short' values) from incompatible type 'void *'}}
  44. ptr = v; // expected-error {{assigning to 'void *' from incompatible type 'short_sizeof_pointer'}}
  45. }