1 // RUN: %clang_cc1 -triple=powerpc-apple-darwin8 -target-feature +altivec -fsyntax-only -verify=expected,nonaix -std=c++11 %s
2 // RUN: %clang_cc1 -triple=powerpc64-unknown-linux-gnu -target-feature +altivec -fsyntax-only -verify=expected,nonaix -std=c++11 %s
3 // RUN: %clang_cc1 -triple=powerpc64le-unknown-linux-gnu -target-feature +altivec -fsyntax-only -verify=expected,nonaix -std=c++11 %s
4 // RUN: %clang_cc1 -triple=powerpc-ibm-aix -target-feature +altivec -fsyntax-only -verify=expected,aix -std=c++11 %s
5 // RUN: %clang_cc1 -triple=powerpc64-ibm-aix -target-feature +altivec -fsyntax-only -verify=expected,aix -std=c++11 %s
6 #include <altivec.h>
7 
8 __vector char vv_c;
9 __vector signed char vv_sc;
10 __vector unsigned char vv_uc;
11 __vector short vv_s;
12 __vector signed  short vv_ss;
13 __vector unsigned  short vv_us;
14 __vector short int vv_si;
15 __vector signed short int vv_ssi;
16 __vector unsigned short int vv_usi;
17 __vector int vv_i;
18 __vector signed int vv_sint;
19 __vector unsigned int vv_ui;
20 __vector float vv_f;
21 __vector bool char vv_bc;
22 __vector bool short vv_bs;
23 __vector bool int vv_bi;
24 __vector __bool char vv___bc;
25 __vector __bool short vv___bs;
26 __vector __bool int vv___bi;
27 __vector __pixel vv_p;
28 __vector pixel vv__p;
29 __vector int vf__r();
30 void vf__a(__vector int a);
31 void vf__a2(int b, __vector int a);
32 
33 vector char v_c;
34 vector signed char v_sc;
35 vector unsigned char v_uc;
36 vector short v_s;
37 vector signed  short v_ss;
38 vector unsigned  short v_us;
39 vector short int v_si;
40 vector signed short int v_ssi;
41 vector unsigned short int v_usi;
42 vector int v_i;
43 vector signed int v_sint;
44 vector unsigned int v_ui;
45 vector float v_f;
46 vector bool char v_bc;
47 vector bool short v_bs;
48 vector bool int v_bi;
49 vector __bool char v___bc;
50 vector __bool short v___bs;
51 vector __bool int v___bi;
52 vector __pixel v_p;
53 vector pixel v__p;
54 vector int f__r();
55 void f_a(vector int a);
56 void f_a2(int b, vector int a);
57 
58 vector int v = (vector int)(-1);
59 
60 // These should have errors on AIX and warnings otherwise.
61 __vector long vv_l;                 // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
62                                     // aix-error@-1 {{cannot use 'long' with '__vector'}}
63 __vector signed long vv_sl;         // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
64                                     // aix-error@-1 {{cannot use 'long' with '__vector'}}
65 __vector unsigned long vv_ul;       // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
66                                     // aix-error@-1 {{cannot use 'long' with '__vector'}}
67 __vector long int vv_li;            // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
68                                     // aix-error@-1 {{cannot use 'long' with '__vector'}}
69 __vector signed long int vv_sli;    // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
70                                     // aix-error@-1 {{cannot use 'long' with '__vector'}}
71 __vector unsigned long int vv_uli;  // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
72                                     // aix-error@-1 {{cannot use 'long' with '__vector'}}
73 vector long v_l;                    // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
74                                     // aix-error@-1 {{cannot use 'long' with '__vector'}}
75 vector signed long v_sl;            // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
76                                     // aix-error@-1 {{cannot use 'long' with '__vector'}}
77 vector unsigned long v_ul;          // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
78                                     // aix-error@-1 {{cannot use 'long' with '__vector'}}
79 vector long int v_li;               // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
80                                     // aix-error@-1 {{cannot use 'long' with '__vector'}}
81 vector signed long int v_sli;       // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
82                                     // aix-error@-1 {{cannot use 'long' with '__vector'}}
83 vector unsigned long int v_uli;     // nonaix-warning {{Use of 'long' with '__vector' is deprecated}}
84                                     // aix-error@-1 {{cannot use 'long' with '__vector'}}
85 
86 // These should have warnings.
87 __vector long double  vv_ld;        // expected-error {{cannot use 'long double' with '__vector'}}
88 vector long double  v_ld;           // expected-error {{cannot use 'long double' with '__vector'}}
89 
90 // These should have errors.
91 __vector double vv_d1;               // expected-error {{use of 'double' with '__vector' requires VSX support to be enabled (available on POWER7 or later)}}
92 vector double v_d2;                  // expected-error {{use of 'double' with '__vector' requires VSX support to be enabled (available on POWER7 or later)}}
93 __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}}
94 __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}}
95 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}}
96 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}}
97 __vector long double  vv_ld3;        // expected-error {{cannot use 'long double' with '__vector'}}
98 vector long double  v_ld4;           // expected-error {{cannot use 'long double' with '__vector'}}
99 vector bool v_b;                     // expected-error {{C++ requires a type specifier for all declarations}}
100 vector bool float v_bf;              // expected-error {{cannot use 'float' with '__vector bool'}}
101 vector bool double v_bd;             // expected-error {{cannot use 'double' with '__vector bool'}}
102 vector bool pixel v_bp;              // expected-error {{cannot use '__pixel' with '__vector bool'}}
103 vector bool signed char v_bsc;       // expected-error {{cannot use 'signed' with '__vector bool'}}
104 vector bool unsigned int v_bsc2;     // expected-error {{cannot use 'unsigned' with '__vector bool'}}
105 vector bool long v_bl;               // expected-error {{cannot use 'long' with '__vector bool'}}
106 vector __bool float v___bf;          // expected-error {{cannot use 'float' with '__vector bool'}}
107 vector __bool double v___bd;         // expected-error {{cannot use 'double' with '__vector bool'}}
108 vector __bool pixel v___bp;          // expected-error {{cannot use '__pixel' with '__vector bool'}}
109 vector __bool signed char v___bsc;   // expected-error {{cannot use 'signed' with '__vector bool'}}
110 vector __bool unsigned int v___bsc2; // expected-error {{cannot use 'unsigned' with '__vector bool'}}
111 vector __bool long v___bl;           // expected-error {{cannot use 'long' with '__vector bool'}}
112 
113 // vector long is deprecated, but vector long long is not.
114 vector long long v_ll;
115 vector signed long long v_sll;
116 vector unsigned long long v_ull;
117 
118 void f() {
119   __vector unsigned int v = {0,0,0,0};
120   __vector int v__cast = (__vector int)v;
121   __vector int v_cast = (vector int)v;
122   __vector char vb_cast = (vector char)v;
123 
124   // Check some casting between gcc and altivec vectors.
125   #define gccvector __attribute__((vector_size(16)))
126   gccvector unsigned int gccv = {0,0,0,0};
127   gccvector unsigned int gccv1 = gccv;
128   gccvector int gccv2 = (gccvector int)gccv;
129   gccvector unsigned int gccv3 = v;
130   __vector unsigned int av = gccv;
131   __vector int avi = (__vector int)gccv;
132   gccvector unsigned int gv = v;
133   gccvector int gvi = (gccvector int)v;
134   __attribute__((vector_size(8))) unsigned int gv8;
135   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)}}
136   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)}}
137 
138   v = gccv;
139   __vector unsigned int tv = gccv;
140   gccv = v;
141   gccvector unsigned int tgv = v;
142 }
143 
144 // Now for the C++ version:
145 
146 class vc__v {
147   __vector int v;
148   __vector int f__r();
149   void f__a(__vector int a);
150   void f__a2(int b, __vector int a);
151 };
152 
153 class c_v {
154   vector int v;
155   vector int f__r();
156   void f__a(vector int a);
157   void f__a2(int b, vector int a);
158 };
159 
160 
161 // bug 6895 - Vectorl literal casting confusion.
162 vector char v1 = (vector char)((vector int)(1, 2, 3, 4));
163 vector char v2 = (vector char)((vector float)(1.0f, 2.0f, 3.0f, 4.0f));
164 vector char v3 = (vector char)((vector int)('a', 'b', 'c', 'd'));
165 vector int v4 = (vector int)(1, 2, 3, 4);
166 vector float v5 = (vector float)(1.0f, 2.0f, 3.0f, 4.0f);
167 vector char v6 = (vector char)((vector int)(1+2, -2, (int)(2.0 * 3), -(5-3)));
168 
169 // bug 7553 - Problem with '==' and vectors
170 void func() {
171   bool res_b;
172   res_b = (vv_sc == vv_sc);
173   res_b = (vv_uc != vv_uc);
174   res_b = (vv_s > vv_s);
175   res_b = (vv_us >= vv_us);
176   res_b = (vv_i < vv_i);
177   res_b = (vv_ui <= vv_ui);
178   res_b = (vv_f <= vv_f);
179 }
180 
181 // vecreturn attribute test
182 struct Vector
183 {
184 	__vector float xyzw;
185 } __attribute__((vecreturn));
186 
187 Vector Add(Vector lhs, Vector rhs)
188 {
189 	Vector result;
190 	result.xyzw = vec_add(lhs.xyzw, rhs.xyzw);
191 	return result; // This will (eventually) be returned in a register
192 }
193 
194 // vecreturn attribute test - should error because of virtual function.
195 class VectorClassNonPod
196 {
197 	__vector float xyzw;
198 public:
199   VectorClassNonPod() {}
200   virtual ~VectorClassNonPod() {}
201 } __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)}}
202 
203 // vecreturn attribute test - should error because of virtual function.
204 class VectorClassMultipleMembers
205 {
206 public:
207 	__vector float xyzw;
208 	__vector float abcd;
209 } __attribute__((vecreturn));     // expected-error {{the vecreturn attribute can only be used on a class or structure with one member, which must be a vector}}
210 
211 template<typename... Args> void PR16874() {
212 	(void) (Args::foo()...); // expected-error {{expression contains unexpanded parameter pack 'Args'}} expected-error {{expected ')'}} expected-note {{to match this '('}}
213 }
214 
215