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