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