xref: /minix3/external/bsd/llvm/dist/clang/test/Parser/cxx-altivec.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple=powerpc-apple-darwin8 -faltivec -fsyntax-only -verify -std=c++11 %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc __vector char vv_c;
4*f4a2713aSLionel Sambuc __vector signed char vv_sc;
5*f4a2713aSLionel Sambuc __vector unsigned char vv_uc;
6*f4a2713aSLionel Sambuc __vector short vv_s;
7*f4a2713aSLionel Sambuc __vector signed  short vv_ss;
8*f4a2713aSLionel Sambuc __vector unsigned  short vv_us;
9*f4a2713aSLionel Sambuc __vector short int vv_si;
10*f4a2713aSLionel Sambuc __vector signed short int vv_ssi;
11*f4a2713aSLionel Sambuc __vector unsigned short int vv_usi;
12*f4a2713aSLionel Sambuc __vector int vv_i;
13*f4a2713aSLionel Sambuc __vector signed int vv_sint;
14*f4a2713aSLionel Sambuc __vector unsigned int vv_ui;
15*f4a2713aSLionel Sambuc __vector float vv_f;
16*f4a2713aSLionel Sambuc __vector bool char vv_bc;
17*f4a2713aSLionel Sambuc __vector bool short vv_bs;
18*f4a2713aSLionel Sambuc __vector bool int vv_bi;
19*f4a2713aSLionel Sambuc __vector __pixel vv_p;
20*f4a2713aSLionel Sambuc __vector pixel vv__p;
21*f4a2713aSLionel Sambuc __vector int vf__r();
22*f4a2713aSLionel Sambuc void vf__a(__vector int a);
23*f4a2713aSLionel Sambuc void vf__a2(int b, __vector int a);
24*f4a2713aSLionel Sambuc 
25*f4a2713aSLionel Sambuc vector char v_c;
26*f4a2713aSLionel Sambuc vector signed char v_sc;
27*f4a2713aSLionel Sambuc vector unsigned char v_uc;
28*f4a2713aSLionel Sambuc vector short v_s;
29*f4a2713aSLionel Sambuc vector signed  short v_ss;
30*f4a2713aSLionel Sambuc vector unsigned  short v_us;
31*f4a2713aSLionel Sambuc vector short int v_si;
32*f4a2713aSLionel Sambuc vector signed short int v_ssi;
33*f4a2713aSLionel Sambuc vector unsigned short int v_usi;
34*f4a2713aSLionel Sambuc vector int v_i;
35*f4a2713aSLionel Sambuc vector signed int v_sint;
36*f4a2713aSLionel Sambuc vector unsigned int v_ui;
37*f4a2713aSLionel Sambuc vector float v_f;
38*f4a2713aSLionel Sambuc vector bool char v_bc;
39*f4a2713aSLionel Sambuc vector bool short v_bs;
40*f4a2713aSLionel Sambuc vector bool int v_bi;
41*f4a2713aSLionel Sambuc vector __pixel v_p;
42*f4a2713aSLionel Sambuc vector pixel v__p;
43*f4a2713aSLionel Sambuc vector int f__r();
44*f4a2713aSLionel Sambuc void f_a(vector int a);
45*f4a2713aSLionel Sambuc void f_a2(int b, vector int a);
46*f4a2713aSLionel Sambuc 
47*f4a2713aSLionel Sambuc vector int v = (vector int)(-1);
48*f4a2713aSLionel Sambuc 
49*f4a2713aSLionel Sambuc // These should have warnings.
50*f4a2713aSLionel Sambuc __vector long vv_l;                 // expected-warning {{Use of 'long' with '__vector' is deprecated}}
51*f4a2713aSLionel Sambuc __vector signed long vv_sl;         // expected-warning {{Use of 'long' with '__vector' is deprecated}}
52*f4a2713aSLionel Sambuc __vector unsigned long vv_ul;       // expected-warning {{Use of 'long' with '__vector' is deprecated}}
53*f4a2713aSLionel Sambuc __vector long int vv_li;            // expected-warning {{Use of 'long' with '__vector' is deprecated}}
54*f4a2713aSLionel Sambuc __vector signed long int vv_sli;    // expected-warning {{Use of 'long' with '__vector' is deprecated}}
55*f4a2713aSLionel Sambuc __vector unsigned long int vv_uli;  // expected-warning {{Use of 'long' with '__vector' is deprecated}}
56*f4a2713aSLionel Sambuc vector long v_l;                    // expected-warning {{Use of 'long' with '__vector' is deprecated}}
57*f4a2713aSLionel Sambuc vector signed long v_sl;            // expected-warning {{Use of 'long' with '__vector' is deprecated}}
58*f4a2713aSLionel Sambuc vector unsigned long v_ul;          // expected-warning {{Use of 'long' with '__vector' is deprecated}}
59*f4a2713aSLionel Sambuc vector long int v_li;               // expected-warning {{Use of 'long' with '__vector' is deprecated}}
60*f4a2713aSLionel Sambuc vector signed long int v_sli;       // expected-warning {{Use of 'long' with '__vector' is deprecated}}
61*f4a2713aSLionel Sambuc vector unsigned long int v_uli;     // expected-warning {{Use of 'long' with '__vector' is deprecated}}
62*f4a2713aSLionel Sambuc __vector long double  vv_ld;        // expected-warning {{Use of 'long' with '__vector' is deprecated}} expected-error {{cannot use 'double' with '__vector'}}
63*f4a2713aSLionel Sambuc vector long double  v_ld;           // expected-warning {{Use of 'long' with '__vector' is deprecated}} expected-error {{cannot use 'double' with '__vector'}}
64*f4a2713aSLionel Sambuc 
65*f4a2713aSLionel Sambuc // These should have errors.
66*f4a2713aSLionel Sambuc __vector double vv_d1;               // expected-error {{cannot use 'double' with '__vector'}}
67*f4a2713aSLionel Sambuc vector double v_d2;                  // expected-error {{cannot use 'double' with '__vector'}}
68*f4a2713aSLionel Sambuc __vector long double  vv_ld3;        // expected-warning {{Use of 'long' with '__vector' is deprecated}} expected-error {{cannot use 'double' with '__vector'}}
69*f4a2713aSLionel Sambuc vector long double  v_ld4;           // expected-warning {{Use of 'long' with '__vector' is deprecated}} expected-error {{cannot use 'double' with '__vector'}}
70*f4a2713aSLionel Sambuc vector bool v_b;                     // expected-error {{C++ requires a type specifier for all declarations}}
71*f4a2713aSLionel Sambuc vector bool float v_bf;              // expected-error {{cannot use 'float' with '__vector bool'}}
72*f4a2713aSLionel Sambuc vector bool double v_bd;             // expected-error {{cannot use 'double' with '__vector bool'}}
73*f4a2713aSLionel Sambuc vector bool pixel v_bp;              // expected-error {{cannot use '__pixel' with '__vector bool'}}
74*f4a2713aSLionel Sambuc vector bool signed char v_bsc;       // expected-error {{cannot use 'signed' with '__vector bool'}}
75*f4a2713aSLionel Sambuc vector bool unsigned int v_bsc2;      // expected-error {{cannot use 'unsigned' with '__vector bool'}}
76*f4a2713aSLionel Sambuc vector bool long v_bl;               // expected-error {{cannot use 'long' with '__vector bool'}}
77*f4a2713aSLionel Sambuc vector bool long long v_bll;         // expected-error {{cannot use 'long long' with '__vector bool'}}
78*f4a2713aSLionel Sambuc 
79*f4a2713aSLionel Sambuc void f() {
80*f4a2713aSLionel Sambuc   __vector unsigned int v = {0,0,0,0};
81*f4a2713aSLionel Sambuc   __vector int v__cast = (__vector int)v;
82*f4a2713aSLionel Sambuc   __vector int v_cast = (vector int)v;
83*f4a2713aSLionel Sambuc   __vector char vb_cast = (vector char)v;
84*f4a2713aSLionel Sambuc 
85*f4a2713aSLionel Sambuc   // Check some casting between gcc and altivec vectors.
86*f4a2713aSLionel Sambuc   #define gccvector __attribute__((vector_size(16)))
87*f4a2713aSLionel Sambuc   gccvector unsigned int gccv = {0,0,0,0};
88*f4a2713aSLionel Sambuc   gccvector unsigned int gccv1 = gccv;
89*f4a2713aSLionel Sambuc   gccvector int gccv2 = (gccvector int)gccv;
90*f4a2713aSLionel Sambuc   gccvector unsigned int gccv3 = v;
91*f4a2713aSLionel Sambuc   __vector unsigned int av = gccv;
92*f4a2713aSLionel Sambuc   __vector int avi = (__vector int)gccv;
93*f4a2713aSLionel Sambuc   gccvector unsigned int gv = v;
94*f4a2713aSLionel Sambuc   gccvector int gvi = (gccvector int)v;
95*f4a2713aSLionel Sambuc   __attribute__((vector_size(8))) unsigned int gv8;
96*f4a2713aSLionel Sambuc   gv8 = gccv;     // expected-error {{assigning to '__attribute__((__vector_size__(2 * sizeof(unsigned int)))) unsigned int' from incompatible type '__attribute__((__vector_size__(4 * sizeof(unsigned int)))) unsigned int'}}
97*f4a2713aSLionel Sambuc   av = gv8;       // expected-error {{assigning to '__vector unsigned int' from incompatible type '__attribute__((__vector_size__(2 * sizeof(unsigned int)))) unsigned int'}}
98*f4a2713aSLionel Sambuc 
99*f4a2713aSLionel Sambuc   v = gccv;
100*f4a2713aSLionel Sambuc   __vector unsigned int tv = gccv;
101*f4a2713aSLionel Sambuc   gccv = v;
102*f4a2713aSLionel Sambuc   gccvector unsigned int tgv = v;
103*f4a2713aSLionel Sambuc }
104*f4a2713aSLionel Sambuc 
105*f4a2713aSLionel Sambuc // Now for the C++ version:
106*f4a2713aSLionel Sambuc 
107*f4a2713aSLionel Sambuc class vc__v {
108*f4a2713aSLionel Sambuc   __vector int v;
109*f4a2713aSLionel Sambuc   __vector int f__r();
110*f4a2713aSLionel Sambuc   void f__a(__vector int a);
111*f4a2713aSLionel Sambuc   void f__a2(int b, __vector int a);
112*f4a2713aSLionel Sambuc };
113*f4a2713aSLionel Sambuc 
114*f4a2713aSLionel Sambuc class c_v {
115*f4a2713aSLionel Sambuc   vector int v;
116*f4a2713aSLionel Sambuc   vector int f__r();
117*f4a2713aSLionel Sambuc   void f__a(vector int a);
118*f4a2713aSLionel Sambuc   void f__a2(int b, vector int a);
119*f4a2713aSLionel Sambuc };
120*f4a2713aSLionel Sambuc 
121*f4a2713aSLionel Sambuc 
122*f4a2713aSLionel Sambuc // bug 6895 - Vectorl literal casting confusion.
123*f4a2713aSLionel Sambuc vector char v1 = (vector char)((vector int)(1, 2, 3, 4));
124*f4a2713aSLionel Sambuc vector char v2 = (vector char)((vector float)(1.0f, 2.0f, 3.0f, 4.0f));
125*f4a2713aSLionel Sambuc vector char v3 = (vector char)((vector int)('a', 'b', 'c', 'd'));
126*f4a2713aSLionel Sambuc vector int v4 = (vector int)(1, 2, 3, 4);
127*f4a2713aSLionel Sambuc vector float v5 = (vector float)(1.0f, 2.0f, 3.0f, 4.0f);
128*f4a2713aSLionel Sambuc vector char v6 = (vector char)((vector int)(1+2, -2, (int)(2.0 * 3), -(5-3)));
129*f4a2713aSLionel Sambuc 
130*f4a2713aSLionel Sambuc // bug 7553 - Problem with '==' and vectors
131*f4a2713aSLionel Sambuc void func() {
132*f4a2713aSLionel Sambuc   bool res_b;
133*f4a2713aSLionel Sambuc   res_b = (vv_sc == vv_sc);
134*f4a2713aSLionel Sambuc   res_b = (vv_uc != vv_uc);
135*f4a2713aSLionel Sambuc   res_b = (vv_s > vv_s);
136*f4a2713aSLionel Sambuc   res_b = (vv_us >= vv_us);
137*f4a2713aSLionel Sambuc   res_b = (vv_i < vv_i);
138*f4a2713aSLionel Sambuc   res_b = (vv_ui <= vv_ui);
139*f4a2713aSLionel Sambuc   res_b = (vv_f <= vv_f);
140*f4a2713aSLionel Sambuc }
141*f4a2713aSLionel Sambuc 
142*f4a2713aSLionel Sambuc // vecreturn attribute test
143*f4a2713aSLionel Sambuc struct Vector
144*f4a2713aSLionel Sambuc {
145*f4a2713aSLionel Sambuc 	__vector float xyzw;
146*f4a2713aSLionel Sambuc } __attribute__((vecreturn));
147*f4a2713aSLionel Sambuc 
148*f4a2713aSLionel Sambuc Vector Add(Vector lhs, Vector rhs)
149*f4a2713aSLionel Sambuc {
150*f4a2713aSLionel Sambuc 	Vector result;
151*f4a2713aSLionel Sambuc 	result.xyzw = vec_add(lhs.xyzw, rhs.xyzw);
152*f4a2713aSLionel Sambuc 	return result; // This will (eventually) be returned in a register
153*f4a2713aSLionel Sambuc }
154*f4a2713aSLionel Sambuc 
155*f4a2713aSLionel Sambuc // vecreturn attribute test - should error because of virtual function.
156*f4a2713aSLionel Sambuc class VectorClassNonPod
157*f4a2713aSLionel Sambuc {
158*f4a2713aSLionel Sambuc 	__vector float xyzw;
159*f4a2713aSLionel Sambuc public:
160*f4a2713aSLionel Sambuc   VectorClassNonPod() {}
161*f4a2713aSLionel Sambuc   virtual ~VectorClassNonPod() {}
162*f4a2713aSLionel Sambuc } __attribute__((vecreturn));     // expected-error {{the vecreturn attribute can only be used on a POD (plain old data) class or structure (i.e. no virtual functions)}}
163*f4a2713aSLionel Sambuc 
164*f4a2713aSLionel Sambuc // vecreturn attribute test - should error because of virtual function.
165*f4a2713aSLionel Sambuc class VectorClassMultipleMembers
166*f4a2713aSLionel Sambuc {
167*f4a2713aSLionel Sambuc public:
168*f4a2713aSLionel Sambuc 	__vector float xyzw;
169*f4a2713aSLionel Sambuc 	__vector float abcd;
170*f4a2713aSLionel Sambuc } __attribute__((vecreturn));     // expected-error {{the vecreturn attribute can only be used on a class or structure with one member, which must be a vector}}
171*f4a2713aSLionel Sambuc 
172*f4a2713aSLionel Sambuc template<typename... Args> void PR16874() {
173*f4a2713aSLionel Sambuc 	(void) (Args::foo()...); // expected-error {{expression contains unexpanded parameter pack 'Args'}} expected-error {{expected ')'}} expected-note {{to match this '('}}
174*f4a2713aSLionel Sambuc }
175