1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple=powerpc-apple-darwin8 -faltivec -fsyntax-only -verify %s
2*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -triple=powerpc64-unknown-linux-gnu -faltivec -fsyntax-only -verify %s
3*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -triple=powerpc64le-unknown-linux-gnu -faltivec -fsyntax-only -verify %s
4f4a2713aSLionel Sambuc
5f4a2713aSLionel Sambuc __vector char vv_c;
6f4a2713aSLionel Sambuc __vector signed char vv_sc;
7f4a2713aSLionel Sambuc __vector unsigned char vv_uc;
8f4a2713aSLionel Sambuc __vector short vv_s;
9f4a2713aSLionel Sambuc __vector signed short vv_ss;
10f4a2713aSLionel Sambuc __vector unsigned short vv_us;
11f4a2713aSLionel Sambuc __vector short int vv_si;
12f4a2713aSLionel Sambuc __vector signed short int vv_ssi;
13f4a2713aSLionel Sambuc __vector unsigned short int vv_usi;
14f4a2713aSLionel Sambuc __vector int vv_i;
15f4a2713aSLionel Sambuc __vector signed int vv_sint;
16f4a2713aSLionel Sambuc __vector unsigned int vv_ui;
17f4a2713aSLionel Sambuc __vector float vv_f;
18f4a2713aSLionel Sambuc __vector bool char vv_bc;
19f4a2713aSLionel Sambuc __vector bool short vv_bs;
20f4a2713aSLionel Sambuc __vector bool int vv_bi;
21*0a6a1f1dSLionel Sambuc __vector __bool char vv___bc;
22*0a6a1f1dSLionel Sambuc __vector __bool short vv___bs;
23*0a6a1f1dSLionel Sambuc __vector __bool int vv_bi;
24f4a2713aSLionel Sambuc __vector __pixel vv_p;
25f4a2713aSLionel Sambuc __vector pixel vv__p;
26f4a2713aSLionel Sambuc __vector int vf__r();
27f4a2713aSLionel Sambuc void vf__a(__vector int a);
28f4a2713aSLionel Sambuc void vf__a2(int b, __vector int a);
29f4a2713aSLionel Sambuc
30f4a2713aSLionel Sambuc vector char v_c;
31f4a2713aSLionel Sambuc vector signed char v_sc;
32f4a2713aSLionel Sambuc vector unsigned char v_uc;
33f4a2713aSLionel Sambuc vector short v_s;
34f4a2713aSLionel Sambuc vector signed short v_ss;
35f4a2713aSLionel Sambuc vector unsigned short v_us;
36f4a2713aSLionel Sambuc vector short int v_si;
37f4a2713aSLionel Sambuc vector signed short int v_ssi;
38f4a2713aSLionel Sambuc vector unsigned short int v_usi;
39f4a2713aSLionel Sambuc vector int v_i;
40f4a2713aSLionel Sambuc vector signed int v_sint;
41f4a2713aSLionel Sambuc vector unsigned int v_ui;
42f4a2713aSLionel Sambuc vector float v_f;
43f4a2713aSLionel Sambuc vector bool char v_bc;
44f4a2713aSLionel Sambuc vector bool short v_bs;
45f4a2713aSLionel Sambuc vector bool int v_bi;
46*0a6a1f1dSLionel Sambuc vector __bool char v___bc;
47*0a6a1f1dSLionel Sambuc vector __bool short v___bs;
48*0a6a1f1dSLionel Sambuc vector __bool int v___bi;
49f4a2713aSLionel Sambuc vector __pixel v_p;
50f4a2713aSLionel Sambuc vector pixel v__p;
51f4a2713aSLionel Sambuc vector int f__r();
52f4a2713aSLionel Sambuc void f_a(vector int a);
53f4a2713aSLionel Sambuc void f_a2(int b, vector int a);
54f4a2713aSLionel Sambuc
55f4a2713aSLionel Sambuc vector int v = (vector int)(-1);
56f4a2713aSLionel Sambuc
57f4a2713aSLionel Sambuc // These should have warnings.
58f4a2713aSLionel Sambuc __vector long vv_l; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
59f4a2713aSLionel Sambuc __vector signed long vv_sl; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
60f4a2713aSLionel Sambuc __vector unsigned long vv_ul; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
61f4a2713aSLionel Sambuc __vector long int vv_li; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
62f4a2713aSLionel Sambuc __vector signed long int vv_sli; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
63f4a2713aSLionel Sambuc __vector unsigned long int vv_uli; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
64f4a2713aSLionel Sambuc vector long v_l; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
65f4a2713aSLionel Sambuc vector signed long v_sl; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
66f4a2713aSLionel Sambuc vector unsigned long v_ul; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
67f4a2713aSLionel Sambuc vector long int v_li; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
68f4a2713aSLionel Sambuc vector signed long int v_sli; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
69f4a2713aSLionel Sambuc vector unsigned long int v_uli; // expected-warning {{Use of 'long' with '__vector' is deprecated}}
70*0a6a1f1dSLionel Sambuc __vector long double vv_ld; // expected-error {{cannot use 'long double' with '__vector'}}
71*0a6a1f1dSLionel Sambuc vector long double v_ld; // expected-error {{cannot use 'long double' with '__vector'}}
72f4a2713aSLionel Sambuc vector bool v_b; // expected-warning {{type specifier missing, defaults to 'int'}}
73*0a6a1f1dSLionel Sambuc vector __bool v___b; // expected-warning {{type specifier missing, defaults to 'int'}}
74f4a2713aSLionel Sambuc
75f4a2713aSLionel Sambuc // These should have errors.
76*0a6a1f1dSLionel Sambuc __vector double vv_d1; // expected-error {{use of 'double' with '__vector' requires VSX support to be enabled (available on the POWER7 or later)}}
77*0a6a1f1dSLionel Sambuc vector double v_d2; // expected-error {{use of 'double' with '__vector' requires VSX support to be enabled (available on the POWER7 or later)}}
78*0a6a1f1dSLionel Sambuc __vector long double vv_ld3; // expected-error {{cannot use 'long double' with '__vector'}}
79*0a6a1f1dSLionel Sambuc vector long double v_ld4; // expected-error {{cannot use 'long double' with '__vector'}}
80f4a2713aSLionel Sambuc vector bool float v_bf; // expected-error {{cannot use 'float' with '__vector bool'}}
81f4a2713aSLionel Sambuc vector bool double v_bd; // expected-error {{cannot use 'double' with '__vector bool'}}
82f4a2713aSLionel Sambuc vector bool pixel v_bp; // expected-error {{cannot use '__pixel' with '__vector bool'}}
83f4a2713aSLionel Sambuc vector bool signed char v_bsc; // expected-error {{cannot use 'signed' with '__vector bool'}}
84f4a2713aSLionel Sambuc vector bool unsigned int v_bsc2; // expected-error {{cannot use 'unsigned' with '__vector bool'}}
85f4a2713aSLionel Sambuc vector bool long v_bl; // expected-error {{cannot use 'long' with '__vector bool'}}
86f4a2713aSLionel Sambuc vector bool long long v_bll; // expected-error {{cannot use 'long long' with '__vector bool'}}
87*0a6a1f1dSLionel Sambuc vector __bool float v___bf; // expected-error {{cannot use 'float' with '__vector bool'}}
88*0a6a1f1dSLionel Sambuc vector __bool double v___bd; // expected-error {{cannot use 'double' with '__vector bool'}}
89*0a6a1f1dSLionel Sambuc vector __bool pixel v___bp; // expected-error {{cannot use '__pixel' with '__vector bool'}}
90*0a6a1f1dSLionel Sambuc vector __bool signed char v___bsc; // expected-error {{cannot use 'signed' with '__vector bool'}}
91*0a6a1f1dSLionel Sambuc vector __bool unsigned int v___bsc2; // expected-error {{cannot use 'unsigned' with '__vector bool'}}
92*0a6a1f1dSLionel Sambuc vector __bool long v___bl; // expected-error {{cannot use 'long' with '__vector bool'}}
93*0a6a1f1dSLionel Sambuc vector __bool long long v___bll; // expected-error {{cannot use 'long long' with '__vector bool'}}
94*0a6a1f1dSLionel Sambuc
95*0a6a1f1dSLionel Sambuc // vector long is deprecated, but vector long long is not.
96*0a6a1f1dSLionel Sambuc vector long long v_ll;
97*0a6a1f1dSLionel Sambuc vector signed long long v_sll;
98*0a6a1f1dSLionel Sambuc vector unsigned long long v_ull;
99f4a2713aSLionel Sambuc
100f4a2713aSLionel Sambuc typedef char i8;
101f4a2713aSLionel Sambuc typedef short i16;
102f4a2713aSLionel Sambuc typedef int i32;
103f4a2713aSLionel Sambuc struct S {
104f4a2713aSLionel Sambuc // i8, i16, i32 here are field names, not type names.
105f4a2713aSLionel Sambuc vector bool i8; // expected-error {{requires a specifier or qualifier}}
106f4a2713aSLionel Sambuc vector pixel i16;
107f4a2713aSLionel Sambuc vector long i32; // expected-warning {{deprecated}}
108f4a2713aSLionel Sambuc };
109f4a2713aSLionel Sambuc
f()110f4a2713aSLionel Sambuc void f() {
111f4a2713aSLionel Sambuc __vector unsigned int v = {0,0,0,0};
112f4a2713aSLionel Sambuc __vector int v__cast = (__vector int)v;
113f4a2713aSLionel Sambuc __vector int v_cast = (vector int)v;
114f4a2713aSLionel Sambuc __vector char vb_cast = (vector char)v;
115f4a2713aSLionel Sambuc
116f4a2713aSLionel Sambuc // Check some casting between gcc and altivec vectors.
117f4a2713aSLionel Sambuc #define gccvector __attribute__((vector_size(16)))
118f4a2713aSLionel Sambuc gccvector unsigned int gccv = {0,0,0,0};
119f4a2713aSLionel Sambuc gccvector unsigned int gccv1 = gccv;
120f4a2713aSLionel Sambuc gccvector int gccv2 = (gccvector int)gccv;
121f4a2713aSLionel Sambuc gccvector unsigned int gccv3 = v;
122f4a2713aSLionel Sambuc __vector unsigned int av = gccv;
123f4a2713aSLionel Sambuc __vector int avi = (__vector int)gccv;
124f4a2713aSLionel Sambuc gccvector unsigned int gv = v;
125f4a2713aSLionel Sambuc gccvector int gvi = (gccvector int)v;
126f4a2713aSLionel Sambuc __attribute__((vector_size(8))) unsigned int gv8;
127*0a6a1f1dSLionel Sambuc gv8 = gccv; // expected-error {{assigning to '__attribute__((__vector_size__(2 * sizeof(unsigned int)))) unsigned int' (vector of 2 'unsigned int' values) from incompatible type '__attribute__((__vector_size__(4 * sizeof(unsigned int)))) unsigned int' (vector of 4 'unsigned int' values)}}
128*0a6a1f1dSLionel Sambuc av = gv8; // expected-error {{assigning to '__vector unsigned int' (vector of 4 'unsigned int' values) from incompatible type '__attribute__((__vector_size__(2 * sizeof(unsigned int)))) unsigned int' (vector of 2 'unsigned int' values)}}
129f4a2713aSLionel Sambuc
130f4a2713aSLionel Sambuc v = gccv;
131f4a2713aSLionel Sambuc __vector unsigned int tv = gccv;
132f4a2713aSLionel Sambuc gccv = v;
133f4a2713aSLionel Sambuc gccvector unsigned int tgv = v;
134f4a2713aSLionel Sambuc
135f4a2713aSLionel Sambuc int res_i;
136f4a2713aSLionel Sambuc // bug 7553 - Problem with '==' and vectors
137f4a2713aSLionel Sambuc res_i = (vv_sc == vv_sc);
138f4a2713aSLionel Sambuc res_i = (vv_uc != vv_uc);
139f4a2713aSLionel Sambuc res_i = (vv_s > vv_s);
140f4a2713aSLionel Sambuc res_i = (vv_us >= vv_us);
141f4a2713aSLionel Sambuc res_i = (vv_i < vv_i);
142f4a2713aSLionel Sambuc res_i = (vv_ui <= vv_ui);
143f4a2713aSLionel Sambuc res_i = (vv_f <= vv_f);
144f4a2713aSLionel Sambuc }
145f4a2713aSLionel Sambuc
146f4a2713aSLionel Sambuc // bug 6895 - Vectorl literal casting confusion.
147f4a2713aSLionel Sambuc vector char v1 = (vector char)((vector int)(1, 2, 3, 4));
148f4a2713aSLionel Sambuc vector char v2 = (vector char)((vector float)(1.0f, 2.0f, 3.0f, 4.0f));
149f4a2713aSLionel Sambuc vector char v3 = (vector char)((vector int)('a', 'b', 'c', 'd'));
150f4a2713aSLionel Sambuc vector int v4 = (vector int)(1, 2, 3, 4);
151f4a2713aSLionel Sambuc vector float v5 = (vector float)(1.0f, 2.0f, 3.0f, 4.0f);
152f4a2713aSLionel Sambuc vector char v6 = (vector char)((vector int)(1+2, -2, (int)(2.0 * 3), -(5-3)));
153