Home | History | Annotate | Download | only in Sema
      1 // RUN: %clang_cc1 -fsyntax-only %s -verify -Wvector-conversion
      2 
      3 typedef long long t1 __attribute__ ((vector_size (8)));
      4 typedef char t2 __attribute__ ((vector_size (16)));
      5 typedef float t3 __attribute__ ((vector_size (16)));
      6 typedef short s2 __attribute__ ((vector_size(4)));
      7 
      8 typedef enum { Evalue = 0x10000 } E;
      9 
     10 void f()
     11 {
     12   t1 v1;
     13   t2 v2;
     14   t3 v3;
     15   s2 v4;
     16   E e;
     17 
     18   e = (E)v4;
     19   v4 = (s2)e;
     20 
     21   v2 = (t2)v1; // expected-error {{invalid conversion between vector type \
     22 't2' (vector of 16 'char' values) and 't1' (vector of 1 'long long' value) of different size}}
     23   v1 = (t1)v2; // expected-error {{invalid conversion between vector type \
     24 't1' (vector of 1 'long long' value) and 't2' (vector of 16 'char' values) of different size}}
     25   v3 = (t3)v2;
     26 
     27   v1 = (t1)(char *)10; // expected-error {{invalid conversion between vector \
     28 type 't1' (vector of 1 'long long' value) and scalar type 'char *'}}
     29   v1 = (t1)(long long)10;
     30   v1 = (t1)(short)10; // expected-error {{invalid conversion between vector \
     31 type 't1' (vector of 1 'long long' value) and integer type 'short' of different size}}
     32 
     33   long long r1 = (long long)v1;
     34   short r2 = (short)v1; // expected-error {{invalid conversion between vector \
     35 type 't1' (vector of 1 'long long' value) and integer type 'short' of different size}}
     36   char *r3 = (char *)v1; // expected-error {{invalid conversion between vector\
     37  type 't1' (vector of 1 'long long' value) and scalar type 'char *'}}
     38 }
     39 
     40 
     41 void f2(t2 X); // expected-note{{passing argument to parameter 'X' here}}
     42 
     43 void f3(t3 Y) {
     44   f2(Y);  // expected-warning {{incompatible vector types passing 't3' (vector of 4 'float' values) to parameter of type 't2' (vector of 16 'char' values)}}
     45 }
     46 
     47 typedef float float2 __attribute__ ((vector_size (8)));
     48 typedef __attribute__((vector_size(8))) double float64x1_t;
     49 typedef __attribute__((vector_size(16))) double float64x2_t;
     50 float64x1_t vget_low_f64(float64x2_t __p0);
     51 
     52 void f4() {
     53   float2 f2;
     54   double d, a, b, c;
     55   float64x2_t v = {0.0, 1.0};
     56   f2 += d;
     57   a = 3.0 + vget_low_f64(v);
     58   b = vget_low_f64(v) + 3.0;
     59   c = vget_low_f64(v);
     60   // LAX conversions within compound assignments are not supported.
     61   // FIXME: This diagnostic is inaccurate.
     62   d += f2; // expected-error {{cannot convert between vector values of different size}}
     63   c -= vget_low_f64(v); // expected-error {{cannot convert between vector values of different size}}
     64   // LAX conversions between scalar and vector types require same size and one element sized vectors.
     65   d = f2; // expected-error {{assigning to 'double' from incompatible type 'float2'}}
     66   d = d + f2; // expected-error {{assigning to 'double' from incompatible type 'float2'}}
     67 }
     68 
     69 // rdar://15931426
     70 // Don't permit a lax conversion to and from a pointer type.
     71 typedef short short_sizeof_pointer __attribute__((vector_size(sizeof(void*))));
     72 void f5() {
     73   short_sizeof_pointer v;
     74   void *ptr;
     75   v = ptr; // expected-error-re {{assigning to 'short_sizeof_pointer' (vector of {{[0-9]+}} 'short' values) from incompatible type 'void *'}}
     76   ptr = v; // expected-error {{assigning to 'void *' from incompatible type 'short_sizeof_pointer'}}
     77 }
     78