1 // RUN: %clang_cc1 -triple powerpc64le-unknown-unknown -fsyntax-only \
2 // RUN:   -fcxx-exceptions -target-cpu future %s -verify
3 
4 // vector quad
5 
6 // alias
7 using vq_t = __vector_quad;
testVQAlias(int * inp,int * outp)8 void testVQAlias(int *inp, int *outp) {
9   vq_t *vqin = (vq_t *)inp;
10   vq_t *vqout = (vq_t *)outp;
11   *vqout = *vqin;
12 }
13 
14 class TestClassVQ {
15   // method argument
16 public:
testVQArg1(__vector_quad vq,int * ptr)17   void testVQArg1(__vector_quad vq, int *ptr) { // expected-error {{invalid use of PPC MMA type}}
18     __vector_quad *vqp = (__vector_quad *)ptr;
19     *vqp = vq;
20     *vqp1 = vq;
21   }
testVQArg2(const __vector_quad vq,int * ptr)22   void testVQArg2(const __vector_quad vq, int *ptr) { // expected-error {{invalid use of PPC MMA type}}
23     __vector_quad *vqp = (__vector_quad *)ptr;
24     *vqp = vq;
25     *vqp2 = vq;
26   }
testVQArg3(__vector_quad * vq,int * ptr)27   void testVQArg3(__vector_quad *vq, int *ptr) {
28     __vector_quad *vqp = (__vector_quad *)ptr;
29     *vqp = *vq;
30     vqp1 = vqp;
31   }
testVQArg4(const __vector_quad * const vq,int * ptr)32   void testVQArg4(const __vector_quad *const vq, int *ptr) {
33     __vector_quad *vqp = (__vector_quad *)ptr;
34     *vqp = *vq;
35     vqp2 = vqp;
36   }
testVQArg5(__vector_quad vqa[],int * ptr)37   void testVQArg5(__vector_quad vqa[], int *ptr) {
38     __vector_quad *vqp = (__vector_quad *)ptr;
39     *vqp = vqa[0];
40     *vqp1 = vqa[1];
41   }
testVQArg6(const vq_t vq,int * ptr)42   void testVQArg6(const vq_t vq, int *ptr) { // expected-error {{invalid use of PPC MMA type}}
43     __vector_quad *vqp = (__vector_quad *)ptr;
44     *vqp = vq;
45     *vqp2 = vq;
46   }
testVQArg7(const vq_t * vq,int * ptr)47   void testVQArg7(const vq_t *vq, int *ptr) {
48     __vector_quad *vqp = (__vector_quad *)ptr;
49     *vqp = *vq;
50     vqp1 = vqp;
51   }
52 
53   // method return
testVQRet1(int * ptr)54   __vector_quad testVQRet1(int *ptr) { // expected-error {{invalid use of PPC MMA type}}
55     __vector_quad *vqp = (__vector_quad *)ptr;
56     vq1 = *vqp;
57     return *vqp; // expected-error {{invalid use of PPC MMA type}}
58   }
59 
testVQRet2(int * ptr)60   __vector_quad *testVQRet2(int *ptr) {
61     __vector_quad *vqp = (__vector_quad *)ptr;
62     vq2 = *vqp;
63     return vqp + 2;
64   }
65 
testVQRet3(int * ptr)66   const __vector_quad *testVQRet3(int *ptr) {
67     __vector_quad *vqp = (__vector_quad *)ptr;
68     vqp1 = vqp;
69     return vqp + 2;
70   }
71 
testVQRet4(int * ptr)72   const vq_t testVQRet4(int *ptr) { // expected-error {{invalid use of PPC MMA type}}
73     __vector_quad *vqp = (__vector_quad *)ptr;
74     vqp2 = vqp;
75     return *vqp; // expected-error {{invalid use of PPC MMA type}}
76   }
77 
testVQRet5(int * ptr)78   const vq_t *testVQRet5(int *ptr) {
79     __vector_quad *vqp = (__vector_quad *)ptr;
80     vq1 = *vqp;
81     return vqp + 2;
82   }
83 
84   // template argument
85   template <typename T = __vector_quad>
testVQTemplate(T v,T * p)86   void testVQTemplate(T v, T *p) { // expected-note {{candidate template ignored: substitution failure [with T = __vector_quad]: invalid use of PPC MMA type}} \
87                                          expected-note {{candidate template ignored: substitution failure [with T = __vector_quad]: invalid use of PPC MMA type}}
88     *(p + 1) = v;
89   }
90 
91   // class field
92 public:
93   __vector_quad vq1; // expected-error {{invalid use of PPC MMA type}}
94   __vector_quad *vqp1;
95 
96 private:
97   vq_t vq2; // expected-error {{invalid use of PPC MMA type}}
98   vq_t *vqp2;
99 };
100 
101 // template
102 template <typename T>
103 class ClassTemplateVQ1 {
104   T t; // expected-error {{invalid use of PPC MMA type}}
105 };
106 template <typename T>
107 class ClassTemplateVQ2 {
108   T *t;
109 };
110 template <typename T>
111 class ClassTemplateVQ3 {
foo(T t)112   int foo(T t) { return 10; }
113 };
114 template <typename T, typename... Ts>
115 class ClassTemplateVQ4 {
116 public:
operator ()(Ts...) const117   T operator()(Ts...) const {} // expected-error {{invalid use of PPC MMA type}}
118 };
testVQTemplate()119 void testVQTemplate() {
120   ClassTemplateVQ1<__vector_quad> t1; // expected-note {{in instantiation of template class 'ClassTemplateVQ1<__vector_quad>' requested here}}
121   ClassTemplateVQ1<__vector_quad *> t2;
122   ClassTemplateVQ2<__vector_quad> t3;
123   ClassTemplateVQ2<__vector_quad *> t4;
124 
125   ClassTemplateVQ3<int(int, int, int)> t5;
126   // The following case is not prevented but it ok, this function type cannot be
127   // instantiated because we prevent any function from returning an MMA type.
128   ClassTemplateVQ3<__vector_quad(int, int, int)> t6;
129   ClassTemplateVQ3<int(__vector_quad, int, int)> t7; // expected-error {{invalid use of PPC MMA type}}
130 
131   ClassTemplateVQ4<int, int, int, __vector_quad> t8; // expected-note {{in instantiation of template class 'ClassTemplateVQ4<int, int, int, __vector_quad>' requested here}}
132   ClassTemplateVQ4<int, int, int, __vector_quad *> t9;
133 
134   TestClassVQ tc;
135   __vector_quad vq;
136   __vector_quad *vqp = &vq;
137   tc.testVQTemplate(&vq, &vqp);
138   tc.testVQTemplate<vq_t *>(&vq, &vqp);
139   tc.testVQTemplate(vq, vqp);       // expected-error {{no matching member function for call to 'testVQTemplate'}}
140   tc.testVQTemplate<vq_t>(vq, vqp); // expected-error {{no matching member function for call to 'testVQTemplate'}}
141 }
142 
143 // trailing return type
testVQTrailing1()144 auto testVQTrailing1() {
145   __vector_quad vq;
146   return vq; // expected-error {{invalid use of PPC MMA type}}
147 }
testVQTrailing2()148 auto testVQTrailing2() {
149   __vector_quad *vqp;
150   return vqp;
151 }
testVQTrailing3()152 auto testVQTrailing3() -> vq_t { // expected-error {{invalid use of PPC MMA type}}
153   __vector_quad vq;
154   return vq; // expected-error {{invalid use of PPC MMA type}}
155 }
testVQTrailing4()156 auto testVQTrailing4() -> vq_t * {
157   __vector_quad *vqp;
158   return vqp;
159 }
160 
161 // new/delete
testVQNewDelete()162 void testVQNewDelete() {
163   __vector_quad *vqp1 = new __vector_quad;
164   __vector_quad *vqp2 = new __vector_quad[100];
165   delete vqp1;
166   delete[] vqp2;
167 }
168 
169 // lambdas expressions
TestVQLambda()170 void TestVQLambda() {
171   auto f1 = [](void *ptr) -> __vector_quad {
172     __vector_quad *vqp = (__vector_quad *)ptr;
173     return *vqp; // expected-error {{invalid use of PPC MMA type}}
174   };
175   auto f2 = [](void *ptr) {
176     __vector_quad *vqp = (__vector_quad *)ptr;
177     return *vqp; // expected-error {{invalid use of PPC MMA type}}
178   };
179   auto f3 = [] { __vector_quad vq; __builtin_mma_xxsetaccz(&vq); return vq; }; // expected-error {{invalid use of PPC MMA type}}
180 }
181 
182 // cast
TestVQCast()183 void TestVQCast() {
184   __vector_quad vq;
185   int *ip = reinterpret_cast<int *>(&vq);
186   __vector_quad *vq2 = reinterpret_cast<__vector_quad *>(ip);
187 }
188 
189 // throw
TestVQThrow()190 void TestVQThrow() {
191   __vector_quad vq;
192   throw vq; // expected-error {{invalid use of PPC MMA type}}
193 }
194 
195 // vector pair
196 
197 // alias
198 using vp_t = __vector_pair;
testVPAlias(int * inp,int * outp)199 void testVPAlias(int *inp, int *outp) {
200   vp_t *vpin = (vp_t *)inp;
201   vp_t *vpout = (vp_t *)outp;
202   *vpout = *vpin;
203 }
204 
205 class TestClassVP {
206   // method argument
207 public:
testVPArg1(__vector_pair vp,int * ptr)208   void testVPArg1(__vector_pair vp, int *ptr) { // expected-error {{invalid use of PPC MMA type}}
209     __vector_pair *vpp = (__vector_pair *)ptr;
210     *vpp = vp;
211     *vpp1 = vp;
212   }
testVPArg2(const __vector_pair vp,int * ptr)213   void testVPArg2(const __vector_pair vp, int *ptr) { // expected-error {{invalid use of PPC MMA type}}
214     __vector_pair *vpp = (__vector_pair *)ptr;
215     *vpp = vp;
216     *vpp2 = vp;
217   }
testVPArg3(__vector_pair * vp,int * ptr)218   void testVPArg3(__vector_pair *vp, int *ptr) {
219     __vector_pair *vpp = (__vector_pair *)ptr;
220     *vpp = *vp;
221     vpp1 = vpp;
222   }
testVPArg4(const __vector_pair * const vp,int * ptr)223   void testVPArg4(const __vector_pair *const vp, int *ptr) {
224     __vector_pair *vpp = (__vector_pair *)ptr;
225     *vpp = *vp;
226     vpp2 = vpp;
227   }
testVPArg5(__vector_pair vpa[],int * ptr)228   void testVPArg5(__vector_pair vpa[], int *ptr) {
229     __vector_pair *vpp = (__vector_pair *)ptr;
230     *vpp = vpa[0];
231     *vpp1 = vpa[1];
232   }
testVPArg6(const vp_t vp,int * ptr)233   void testVPArg6(const vp_t vp, int *ptr) { // expected-error {{invalid use of PPC MMA type}}
234     __vector_pair *vpp = (__vector_pair *)ptr;
235     *vpp = vp;
236     *vpp2 = vp;
237   }
testVPArg7(const vp_t * vp,int * ptr)238   void testVPArg7(const vp_t *vp, int *ptr) {
239     __vector_pair *vpp = (__vector_pair *)ptr;
240     *vpp = *vp;
241     vpp1 = vpp;
242   }
243 
244   // method return
testVPRet1(int * ptr)245   __vector_pair testVPRet1(int *ptr) { // expected-error {{invalid use of PPC MMA type}}
246     __vector_pair *vpp = (__vector_pair *)ptr;
247     vp1 = *vpp;
248     return *vpp; // expected-error {{invalid use of PPC MMA type}}
249   }
250 
testVPRet2(int * ptr)251   __vector_pair *testVPRet2(int *ptr) {
252     __vector_pair *vpp = (__vector_pair *)ptr;
253     vp2 = *vpp;
254     return vpp + 2;
255   }
256 
testVPRet3(int * ptr)257   const __vector_pair *testVPRet3(int *ptr) {
258     __vector_pair *vpp = (__vector_pair *)ptr;
259     vpp1 = vpp;
260     return vpp + 2;
261   }
262 
testVPRet4(int * ptr)263   const vp_t testVPRet4(int *ptr) { // expected-error {{invalid use of PPC MMA type}}
264     __vector_pair *vpp = (__vector_pair *)ptr;
265     vpp2 = vpp;
266     return *vpp; // expected-error {{invalid use of PPC MMA type}}
267   }
268 
testVPRet5(int * ptr)269   const vp_t *testVPRet5(int *ptr) {
270     __vector_pair *vpp = (__vector_pair *)ptr;
271     vp1 = *vpp;
272     return vpp + 2;
273   }
274 
275   // template argument
276   template <typename T = __vector_pair>
testVPTemplate(T v,T * p)277   void testVPTemplate(T v, T *p) { // expected-note {{candidate template ignored: substitution failure [with T = __vector_pair]: invalid use of PPC MMA type}} \
278                                          expected-note {{candidate template ignored: substitution failure [with T = __vector_pair]: invalid use of PPC MMA type}}
279     *(p + 1) = v;
280   }
281 
282   // class field
283 public:
284   __vector_pair vp1; // expected-error {{invalid use of PPC MMA type}}
285   __vector_pair *vpp1;
286 
287 private:
288   vp_t vp2; // expected-error {{invalid use of PPC MMA type}}
289   vp_t *vpp2;
290 };
291 
292 // template
293 template <typename T>
294 class ClassTemplateVP1 {
295   T t; // expected-error {{invalid use of PPC MMA type}}
296 };
297 template <typename T>
298 class ClassTemplateVP2 {
299   T *t;
300 };
301 template <typename T>
302 class ClassTemplateVP3 {
foo(T t)303   int foo(T t) { return 10; }
304 };
305 template <typename T, typename... Ts>
306 class ClassTemplateVP4 {
307 public:
operator ()(Ts...) const308   T operator()(Ts...) const {} // expected-error {{invalid use of PPC MMA type}}
309 };
testVPTemplate()310 void testVPTemplate() {
311   ClassTemplateVP1<__vector_pair> t1; // expected-note {{in instantiation of template class 'ClassTemplateVP1<__vector_pair>' requested here}}
312   ClassTemplateVP1<__vector_pair *> t2;
313   ClassTemplateVP2<__vector_pair> t3;
314   ClassTemplateVP2<__vector_pair *> t4;
315 
316   ClassTemplateVP3<int(int, int, int)> t5;
317   // The following case is not prevented but it ok, this function type cannot be
318   // instantiated because we prevent any function from returning an MMA type.
319   ClassTemplateVP3<__vector_pair(int, int, int)> t6;
320   ClassTemplateVP3<int(__vector_pair, int, int)> t7; // expected-error {{invalid use of PPC MMA type}}
321 
322   ClassTemplateVP4<int, int, int, __vector_pair> t8; // expected-note {{in instantiation of template class 'ClassTemplateVP4<int, int, int, __vector_pair>' requested here}}
323   ClassTemplateVP4<int, int, int, __vector_pair *> t9;
324 
325   TestClassVP tc;
326   __vector_pair vp;
327   __vector_pair *vpp = &vp;
328   tc.testVPTemplate(&vp, &vpp);
329   tc.testVPTemplate<vp_t *>(&vp, &vpp);
330   tc.testVPTemplate(vp, vpp);       // expected-error {{no matching member function for call to 'testVPTemplate'}}
331   tc.testVPTemplate<vp_t>(vp, vpp); // expected-error {{no matching member function for call to 'testVPTemplate'}}
332 }
333 
334 // trailing return type
testVPTrailing1()335 auto testVPTrailing1() {
336   __vector_pair vp;
337   return vp; // expected-error {{invalid use of PPC MMA type}}
338 }
testVPTrailing2()339 auto testVPTrailing2() {
340   __vector_pair *vpp;
341   return vpp;
342 }
testVPTrailing3()343 auto testVPTrailing3() -> vp_t { // expected-error {{invalid use of PPC MMA type}}
344   __vector_pair vp;
345   return vp; // expected-error {{invalid use of PPC MMA type}}
346 }
testVPTrailing4()347 auto testVPTrailing4() -> vp_t * {
348   __vector_pair *vpp;
349   return vpp;
350 }
351 
352 // new/delete
testVPNewDelete()353 void testVPNewDelete() {
354   __vector_pair *vpp1 = new __vector_pair;
355   __vector_pair *vpp2 = new __vector_pair[100];
356   delete vpp1;
357   delete[] vpp2;
358 }
359 
360 // lambdas expressions
TestVPLambda()361 void TestVPLambda() {
362   auto f1 = [](void *ptr) -> __vector_pair {
363     __vector_pair *vpp = (__vector_pair *)ptr;
364     return *vpp; // expected-error {{invalid use of PPC MMA type}}
365   };
366   auto f2 = [](void *ptr) {
367     __vector_pair *vpp = (__vector_pair *)ptr;
368     return *vpp; // expected-error {{invalid use of PPC MMA type}}
369   };
370   auto f3 = [](vector unsigned char vc) { __vector_pair vp; __builtin_vsx_assemble_pair(&vp, vc, vc); return vp; }; // expected-error {{invalid use of PPC MMA type}}
371 }
372 
373 // cast
TestVPCast()374 void TestVPCast() {
375   __vector_pair vp;
376   int *ip = reinterpret_cast<int *>(&vp);
377   __vector_pair *vp2 = reinterpret_cast<__vector_pair *>(ip);
378 }
379 
380 // throw
TestVPThrow()381 void TestVPThrow() {
382   __vector_pair vp;
383   throw vp; // expected-error {{invalid use of PPC MMA type}}
384 }
385