[LoongArch][Clang] Make the parameters and return value of {x,}vorn.v builti ns ...
[llvm-project.git] / clang / test / SemaOpenACC / loop-construct-collapse-clause.cpp
blobdc954e36d765dad0617e957ad4cd7e8683ac3c74
1 // RUN: %clang_cc1 %s -fopenacc -verify
4 void only_for_loops() {
5 // expected-error@+3{{OpenACC 'loop' construct can only be applied to a 'for' loop}}
6 // expected-note@+1{{'loop' construct is here}}
7 #pragma acc loop collapse(1)
8 while(true);
10 // expected-error@+3{{OpenACC 'loop' construct can only be applied to a 'for' loop}}
11 // expected-note@+1{{'loop' construct is here}}
12 #pragma acc loop collapse(1)
13 do{}while(true);
17 void only_one_on_loop() {
18 // expected-error@+2{{OpenACC 'collapse' clause cannot appear more than once on a 'loop' directive}}
19 // expected-note@+1{{previous clause is here}}
20 #pragma acc loop collapse(1) collapse(1)
21 for(unsigned i = 0; i < 5; ++i);
24 constexpr int three() { return 3; }
25 constexpr int one() { return 1; }
26 constexpr int neg() { return -1; }
27 constexpr int zero() { return 0; }
29 struct NotConstexpr {
30 constexpr NotConstexpr(){};
32 operator int(){ return 1; }
34 struct ConvertsNegative {
35 constexpr ConvertsNegative(){};
37 constexpr operator int(){ return -1; }
39 struct ConvertsOne{
40 constexpr ConvertsOne(){};
42 constexpr operator int(){ return 1; }
45 struct ConvertsThree{
46 constexpr ConvertsThree(){};
48 constexpr operator int(){ return 3; }
51 template <typename T, int Val>
52 void negative_constexpr_templ() {
53 // expected-error@+3 2{{OpenACC 'collapse' clause loop count must be a positive integer value, evaluated to 0}}
54 // expected-note@#NCETN1{{in instantiation of function template specialization 'negative_constexpr_templ<int, -1>'}}
55 // expected-note@#NCET1{{in instantiation of function template specialization 'negative_constexpr_templ<int, 1>'}}
56 #pragma acc loop collapse(T{})
57 for(unsigned i = 0; i < 5; ++i)
58 for(unsigned j = 0; j < 5; ++j);
60 // expected-error@+1{{OpenACC 'collapse' clause loop count must be a positive integer value, evaluated to -1}}
61 #pragma acc loop collapse(Val)
62 for(unsigned i = 0; i < 5; ++i)
63 for(unsigned j = 0; j < 5; ++j);
66 void negative_constexpr(int i) {
67 #pragma acc loop collapse(2)
68 for(unsigned i = 0; i < 5; ++i)
69 for(unsigned j = 0; j < 5; ++j);
71 #pragma acc loop collapse(1)
72 for(unsigned i = 0; i < 5; ++i)
73 for(unsigned j = 0; j < 5; ++j);
75 // expected-error@+1{{OpenACC 'collapse' clause loop count must be a positive integer value, evaluated to 0}}
76 #pragma acc loop collapse(0)
77 for(unsigned i = 0; i < 5; ++i)
78 for(unsigned j = 0; j < 5; ++j);
80 // expected-error@+1{{OpenACC 'collapse' clause loop count must be a positive integer value, evaluated to -1}}
81 #pragma acc loop collapse(-1)
82 for(unsigned i = 0; i < 5; ++i)
83 for(unsigned j = 0; j < 5; ++j);
85 #pragma acc loop collapse(one())
86 for(unsigned i = 0; i < 5; ++i)
87 for(unsigned j = 0; j < 5; ++j);
89 // expected-error@+1{{OpenACC 'collapse' clause loop count must be a positive integer value, evaluated to 0}}
90 #pragma acc loop collapse(zero())
91 for(unsigned i = 0; i < 5; ++i)
92 for(unsigned j = 0; j < 5; ++j);
94 // expected-error@+1{{OpenACC 'collapse' clause loop count must be a positive integer value, evaluated to -1}}
95 #pragma acc loop collapse(neg())
96 for(unsigned i = 0; i < 5; ++i)
97 for(unsigned j = 0; j < 5; ++j);
99 // expected-error@+1{{OpenACC 'collapse' clause loop count must be a constant expression}}
100 #pragma acc loop collapse(NotConstexpr{})
101 for(unsigned i = 0; i < 5; ++i)
102 for(unsigned j = 0; j < 5; ++j);
104 // expected-error@+1{{OpenACC 'collapse' clause loop count must be a positive integer value, evaluated to -1}}
105 #pragma acc loop collapse(ConvertsNegative{})
106 for(unsigned i = 0; i < 5; ++i)
107 for(unsigned j = 0; j < 5; ++j);
109 #pragma acc loop collapse(ConvertsOne{})
110 for(unsigned i = 0; i < 5; ++i)
111 for(unsigned j = 0; j < 5; ++j);
113 negative_constexpr_templ<int, -1>(); // #NCETN1
115 negative_constexpr_templ<int, 1>(); // #NCET1
118 template<unsigned Val>
119 void depth_too_high_templ() {
120 // expected-error@+2{{'collapse' clause specifies a loop count greater than the number of available loops}}
121 // expected-note@+1{{active 'collapse' clause defined here}}
122 #pragma acc loop collapse(Val)
123 for(unsigned i = 0; i < 5; ++i)
124 for(unsigned j = 0; j < 5; ++j);
127 void depth_too_high() {
128 depth_too_high_templ<3>(); // expected-note{{in instantiation of function template specialization}}
130 // expected-error@+2{{'collapse' clause specifies a loop count greater than the number of available loops}}
131 // expected-note@+1{{active 'collapse' clause defined here}}
132 #pragma acc loop collapse(3)
133 for(unsigned i = 0; i < 5; ++i)
134 for(unsigned j = 0; j < 5; ++j);
136 // expected-error@+2{{'collapse' clause specifies a loop count greater than the number of available loops}}
137 // expected-note@+1{{active 'collapse' clause defined here}}
138 #pragma acc loop collapse(three())
139 for(unsigned i = 0; i < 5; ++i)
140 for(unsigned j = 0; j < 5; ++j);
142 // expected-error@+2{{'collapse' clause specifies a loop count greater than the number of available loops}}
143 // expected-note@+1{{active 'collapse' clause defined here}}
144 #pragma acc loop collapse(ConvertsThree{})
145 for(unsigned i = 0; i < 5; ++i)
146 for(unsigned j = 0; j < 5; ++j);
149 template<typename T, unsigned Three>
150 void not_single_loop_templ() {
151 T Arr[5];
152 // expected-error@+2{{'collapse' clause specifies a loop count greater than the number of available loops}}
153 // expected-note@+1 2{{active 'collapse' clause defined here}}
154 #pragma acc loop collapse(3)
155 for(auto x : Arr) {
156 for(auto y : Arr){
157 do{}while(true); // expected-error{{do loop cannot appear in intervening code of a 'loop' with a 'collapse' clause}}
161 // expected-error@+2{{'collapse' clause specifies a loop count greater than the number of available loops}}
162 // expected-note@+1 2{{active 'collapse' clause defined here}}
163 #pragma acc loop collapse(Three)
164 for(unsigned i = 0; i < 5; ++i) {
165 for(unsigned j = 0; j < 5; ++j) {
166 do{}while(true); // expected-error{{do loop cannot appear in intervening code of a 'loop' with a 'collapse' clause}}
170 #pragma acc loop collapse(Three)
171 for(unsigned i = 0; i < 5; ++i) {
172 for(unsigned j = 0; j < 5; ++j) {
173 for(unsigned k = 0; k < 5;++k) {
174 do{}while(true);
178 // expected-error@+2{{'collapse' clause specifies a loop count greater than the number of available loops}}
179 // expected-note@+1 2{{active 'collapse' clause defined here}}
180 #pragma acc loop collapse(Three)
181 for(auto x : Arr) {
182 for(auto y: Arr) {
183 do{}while(true); // expected-error{{do loop cannot appear in intervening code of a 'loop' with a 'collapse' clause}}
187 #pragma acc loop collapse(Three)
188 for(auto x : Arr) {
189 for(auto y: Arr) {
190 for(auto z: Arr) {
191 do{}while(true);
197 void not_single_loop() {
198 not_single_loop_templ<int, 3>(); // expected-note{{in instantiation of function template}}
200 // expected-note@+1{{active 'collapse' clause defined here}}
201 #pragma acc loop collapse(3)
202 for(unsigned i = 0; i < 5; ++i) {
203 for(unsigned j = 0; j < 5; ++j) {
204 for(unsigned k = 0; k < 5;++k);
206 while(true); // expected-error{{while loop cannot appear in intervening code of a 'loop' with a 'collapse' clause}}
209 // expected-note@+1{{active 'collapse' clause defined here}}
210 #pragma acc loop collapse(3)
211 for(unsigned i = 0; i < 5; ++i) {
212 for(unsigned j = 0; j < 5; ++j) {
213 for(unsigned k = 0; k < 5;++k);
215 do{}while(true); // expected-error{{do loop cannot appear in intervening code of a 'loop' with a 'collapse' clause}}
218 // expected-error@+2{{'collapse' clause specifies a loop count greater than the number of available loops}}
219 // expected-note@+1 2{{active 'collapse' clause defined here}}
220 #pragma acc loop collapse(3)
221 for(unsigned i = 0; i < 5; ++i) {
222 for(unsigned j = 0; j < 5; ++j) {
223 while(true); // expected-error{{while loop cannot appear in intervening code of a 'loop' with a 'collapse' clause}}
226 // expected-error@+2{{'collapse' clause specifies a loop count greater than the number of available loops}}
227 // expected-note@+1 2{{active 'collapse' clause defined here}}
228 #pragma acc loop collapse(3)
229 for(unsigned i = 0; i < 5; ++i) {
230 for(unsigned j = 0; j < 5; ++j) {
231 do{}while(true); // expected-error{{do loop cannot appear in intervening code of a 'loop' with a 'collapse' clause}}
235 #pragma acc loop collapse(2)
236 for(unsigned i = 0; i < 5; ++i) {
237 for(unsigned j = 0; j < 5; ++j) {
238 do{}while(true);
241 #pragma acc loop collapse(2)
242 for(unsigned i = 0; i < 5; ++i) {
243 for(unsigned j = 0; j < 5; ++j) {
244 while(true);
248 int Arr[5];
249 // expected-error@+2{{'collapse' clause specifies a loop count greater than the number of available loops}}
250 // expected-note@+1 2{{active 'collapse' clause defined here}}
251 #pragma acc loop collapse(3)
252 for(auto x : Arr) {
253 for(auto y : Arr){
254 do{}while(true); // expected-error{{do loop cannot appear in intervening code of a 'loop' with a 'collapse' clause}}
258 // expected-note@+1 {{active 'collapse' clause defined here}}
259 #pragma acc loop collapse(3)
260 for(unsigned i = 0; i < 5; ++i) {
261 for(unsigned j = 0; j < 5; ++j) {
262 for(unsigned k = 0; k < 5;++k);
264 // expected-error@+1{{more than one for-loop in a loop associated with OpenACC 'loop' construct with a 'collapse' clause}}
265 for(unsigned k = 0; k < 5;++k);
268 // expected-note@+1 {{active 'collapse' clause defined here}}
269 #pragma acc loop collapse(3)
270 for(unsigned i = 0; i < 5; ++i) {
271 for(unsigned j = 0; j < 5; ++j) {
272 for(unsigned k = 0; k < 5;++k);
273 // expected-error@+1{{more than one for-loop in a loop associated with OpenACC 'loop' construct with a 'collapse' clause}}
274 for(unsigned k = 0; k < 5;++k);
278 for(unsigned k = 0; k < 5;++k);
279 #pragma acc loop collapse(3)
280 for(unsigned i = 0; i < 5; ++i) {
281 for(unsigned j = 0; j < 5; ++j) {
282 for(unsigned k = 0; k < 5;++k);
287 template<unsigned Two, unsigned Three>
288 void no_other_directives() {
289 #pragma acc loop collapse(Two)
290 for(unsigned i = 0; i < 5; ++i) {
291 for(unsigned j = 0; j < 5; ++j) {// last loop associated with the top level.
292 // expected-error@+1{{'collapse' clause specifies a loop count greater than the number of available loops}}
293 #pragma acc loop collapse(Three) // expected-note 2{{active 'collapse' clause defined here}}
294 for(unsigned k = 0; k < 6;++k) {
295 for(unsigned l = 0; l < 5; ++l) {
296 // expected-error@+1{{OpenACC 'serial' construct cannot appear in intervening code of a 'loop' with a 'collapse' clause}}
297 #pragma acc serial
303 #pragma acc loop collapse(Two)// expected-note{{active 'collapse' clause defined here}}
304 for(unsigned i = 0; i < 5; ++i) {
305 for(unsigned j = 0; j < 5; ++j) {// last loop associated with the top level.
306 #pragma acc loop collapse(Three)
307 for(unsigned k = 0; k < 6;++k) {
308 for(unsigned l = 0; l < 5; ++l) {
309 for(unsigned m = 0; m < 5; ++m);
313 // expected-error@+1{{OpenACC 'serial' construct cannot appear in intervening code of a 'loop' with a 'collapse' clause}}
314 #pragma acc serial
319 void no_other_directives() {
320 no_other_directives<2,3>(); // expected-note{{in instantiation of function template specialization}}
322 // Ok, not inside the intervening list
323 #pragma acc loop collapse(2)
324 for(unsigned i = 0; i < 5; ++i) {
325 for(unsigned j = 0; j < 5; ++j) {
326 #pragma acc data // expected-warning{{OpenACC construct 'data' not yet implemented}}
329 // expected-note@+1{{active 'collapse' clause defined here}}
330 #pragma acc loop collapse(2)
331 for(unsigned i = 0; i < 5; ++i) {
332 // expected-error@+1{{OpenACC 'data' construct cannot appear in intervening code of a 'loop' with a 'collapse' clause}}
333 #pragma acc data // expected-warning{{OpenACC construct 'data' not yet implemented}}
334 for(unsigned j = 0; j < 5; ++j) {
339 void call();
341 template<unsigned Two>
342 void intervening_without_force_templ() {
343 // expected-note@+1{{active 'collapse' clause defined here}}
344 #pragma acc loop collapse(2)
345 for(unsigned i = 0; i < 5; ++i) {
346 // expected-error@+1{{inner loops must be tightly nested inside a 'collapse' clause on a 'loop' construct}}
347 call();
348 for(unsigned j = 0; j < 5; ++j);
351 // expected-note@+1{{active 'collapse' clause defined here}}
352 #pragma acc loop collapse(Two)
353 for(unsigned i = 0; i < 5; ++i) {
354 // expected-error@+1{{inner loops must be tightly nested inside a 'collapse' clause on a 'loop' construct}}
355 call();
356 for(unsigned j = 0; j < 5; ++j);
359 // expected-note@+1{{active 'collapse' clause defined here}}
360 #pragma acc loop collapse(2)
361 for(unsigned i = 0; i < 5; ++i) {
362 for(unsigned j = 0; j < 5; ++j);
363 // expected-error@+1{{inner loops must be tightly nested inside a 'collapse' clause on a 'loop' construct}}
364 call();
367 #pragma acc loop collapse(force:2)
368 for(unsigned i = 0; i < 5; ++i) {
369 call();
370 for(unsigned j = 0; j < 5; ++j);
373 #pragma acc loop collapse(force:Two)
374 for(unsigned i = 0; i < 5; ++i) {
375 call();
376 for(unsigned j = 0; j < 5; ++j);
380 #pragma acc loop collapse(force:2)
381 for(unsigned i = 0; i < 5; ++i) {
382 for(unsigned j = 0; j < 5; ++j);
383 call();
386 #pragma acc loop collapse(force:Two)
387 for(unsigned i = 0; i < 5; ++i) {
388 for(unsigned j = 0; j < 5; ++j);
389 call();
392 #pragma acc loop collapse(Two)
393 for(unsigned i = 0; i < 5; ++i) {
394 for(unsigned j = 0; j < 5; ++j) {
395 call();
399 #pragma acc loop collapse(Two)
400 for(unsigned i = 0; i < 5; ++i) {
403 for(unsigned j = 0; j < 5; ++j) {
404 call();
410 #pragma acc loop collapse(force:Two)
411 for(unsigned i = 0; i < 5; ++i) {
412 for(unsigned j = 0; j < 5; ++j) {
413 call();
417 // expected-note@+1{{active 'collapse' clause defined here}}
418 #pragma acc loop collapse(Two)
419 for(unsigned i = 0; i < 5; ++i) {
420 for(unsigned j = 0; j < 5; ++j);
421 // expected-error@+1{{inner loops must be tightly nested inside a 'collapse' clause on a 'loop' construct}}
422 call();
425 #pragma acc loop collapse(2)
426 // expected-error@+2{{OpenACC 'loop' construct must have a terminating condition}}
427 // expected-note@-2{{'loop' construct is here}}
428 for(int i = 0;;++i)
429 // expected-error@+2{{OpenACC 'loop' construct must have a terminating condition}}
430 // expected-note@-5{{'loop' construct is here}}
431 for(int j = 0;;++j)
432 for(;;);
435 void intervening_without_force() {
436 intervening_without_force_templ<2>(); // expected-note{{in instantiation of function template specialization}}
437 // expected-note@+1{{active 'collapse' clause defined here}}
438 #pragma acc loop collapse(2)
439 for(unsigned i = 0; i < 5; ++i) {
440 // expected-error@+1{{inner loops must be tightly nested inside a 'collapse' clause on a 'loop' construct}}
441 call();
442 for(unsigned j = 0; j < 5; ++j);
445 // expected-note@+1{{active 'collapse' clause defined here}}
446 #pragma acc loop collapse(2)
447 for(unsigned i = 0; i < 5; ++i) {
448 for(unsigned j = 0; j < 5; ++j);
449 // expected-error@+1{{inner loops must be tightly nested inside a 'collapse' clause on a 'loop' construct}}
450 call();
453 // The below two are fine, as they use the 'force' tag.
454 #pragma acc loop collapse(force:2)
455 for(unsigned i = 0; i < 5; ++i) {
456 call();
457 for(unsigned j = 0; j < 5; ++j);
460 #pragma acc loop collapse(force:2)
461 for(unsigned i = 0; i < 5; ++i) {
462 for(unsigned j = 0; j < 5; ++j);
463 call();
466 #pragma acc loop collapse(2)
467 for(unsigned i = 0; i < 5; ++i) {
468 for(unsigned j = 0; j < 5; ++j) {
469 call();
472 #pragma acc loop collapse(2)
473 for(unsigned i = 0; i < 5; ++i) {
476 for(unsigned j = 0; j < 5; ++j) {
477 call();
483 #pragma acc loop collapse(force:2)
484 for(unsigned i = 0; i < 5; ++i) {
485 for(unsigned j = 0; j < 5; ++j) {
486 call();
490 #pragma acc loop collapse(2)
491 // expected-error@+2{{OpenACC 'loop' construct must have a terminating condition}}
492 // expected-note@-2{{'loop' construct is here}}
493 for(int i = 0;;++i)
494 // expected-error@+2{{OpenACC 'loop' construct must have a terminating condition}}
495 // expected-note@-5{{'loop' construct is here}}
496 for(int j = 0;;++j)
497 for(;;);