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