[flang][OpenMP] 'no_openmp_constructs' added to clang broke flang build (#126145)
[llvm-project.git] / clang / test / SemaOpenACC / combined-construct-tile-clause.cpp
blob00c551e163666ae58daec2c74bfd971bd59508ba
1 // RUN: %clang_cc1 %s -fopenacc -verify
3 constexpr int three() { return 3; }
4 constexpr int one() { return 1; }
5 constexpr int neg() { return -1; }
6 constexpr int zero() { return 0; }
8 struct NotConstexpr {
9 constexpr NotConstexpr(){};
11 operator int(){ return 1; }
13 struct ConvertsNegative {
14 constexpr ConvertsNegative(){};
16 constexpr operator int(){ return -1; }
18 struct ConvertsOne{
19 constexpr ConvertsOne(){};
21 constexpr operator int(){ return 1; }
24 struct ConvertsThree{
25 constexpr ConvertsThree(){};
27 constexpr operator int(){ return 3; }
30 template<typename T, int Val>
31 void negative_zero_constexpr_templ() {
32 // expected-error@+1 2{{OpenACC 'tile' clause size expression must be positive integer value, evaluated to 0}}
33 #pragma acc serial loop tile(*, T{})
34 for(int i = 0; i < 5; ++i)
35 for(int j = 0; j < 5; ++j);
37 // expected-error@+1{{OpenACC 'tile' clause size expression must be positive integer value, evaluated to -1}}
38 #pragma acc parallel loop tile(Val, *)
39 for(int i = 0; i < 5; ++i)
40 for(int j = 0; j < 5; ++j);
42 // expected-error@+1{{OpenACC 'tile' clause size expression must be positive integer value, evaluated to 0}}
43 #pragma acc kernels loop tile(zero(), *)
44 for(int i = 0; i < 5; ++i)
45 for(int j = 0; j < 5; ++j);
48 void negative_zero_constexpr() {
49 negative_zero_constexpr_templ<int, 1>(); // expected-note{{in instantiation of function template specialization}}
50 negative_zero_constexpr_templ<int, -1>(); // expected-note{{in instantiation of function template specialization}}
52 // expected-error@+1{{OpenACC 'tile' clause size expression must be positive integer value, evaluated to 0}}
53 #pragma acc serial loop tile(0, *)
54 for(int i = 0; i < 5; ++i)
55 for(int j = 0; j < 5; ++j);
57 // expected-error@+1{{OpenACC 'tile' clause size expression must be positive integer value, evaluated to 0}}
58 #pragma acc parallel loop tile(1, 0)
59 for(int i = 0; i < 5; ++i)
60 for(int j = 0; j < 5; ++j);
62 // expected-error@+1{{OpenACC 'tile' clause size expression must be positive integer value, evaluated to -1}}
63 #pragma acc kernels loop tile(1, -1)
64 for(int i = 0; i < 5; ++i)
65 for(int j = 0; j < 5; ++j);
67 // expected-error@+1{{OpenACC 'tile' clause size expression must be positive integer value, evaluated to -1}}
68 #pragma acc parallel loop tile(-1, 0)
69 for(int i = 0; i < 5; ++i)
70 for(int j = 0; j < 5; ++j);
72 // expected-error@+1{{OpenACC 'tile' clause size expression must be positive integer value, evaluated to 0}}
73 #pragma acc serial loop tile(zero(), 0)
74 for(int i = 0; i < 5; ++i)
75 for(int j = 0; j < 5; ++j);
77 // expected-error@+1{{OpenACC 'tile' clause size expression must be positive integer value, evaluated to -1}}
78 #pragma acc kernels loop tile(1, neg())
79 for(int i = 0; i < 5; ++i)
80 for(int j = 0; j < 5; ++j);
82 // expected-error@+1{{OpenACC 'tile' clause size expression must be an asterisk or a constant expression}}
83 #pragma acc parallel loop tile(NotConstexpr{})
84 for(int i = 0; i < 5; ++i);
86 // expected-error@+1{{OpenACC 'tile' clause size expression must be positive integer value, evaluated to -1}}
87 #pragma acc serial loop tile(1, ConvertsNegative{})
88 for(int i = 0; i < 5; ++i)
89 for(int j = 0; j < 5; ++j);
91 #pragma acc kernels loop tile(*, ConvertsOne{})
92 for(int i = 0; i < 5; ++i)
93 for(int j = 0; j < 5; ++j);
96 template<unsigned One>
97 void only_for_loops_templ() {
98 // expected-note@+1{{'parallel loop' construct is here}}
99 #pragma acc parallel loop tile(One)
100 // expected-error@+1{{OpenACC 'parallel loop' construct can only be applied to a 'for' loop}}
101 while(true);
103 // expected-note@+1{{'serial loop' construct is here}}
104 #pragma acc serial loop tile(One)
105 // expected-error@+1{{OpenACC 'serial loop' construct can only be applied to a 'for' loop}}
106 do {} while(true);
108 // expected-error@+1{{'tile' clause specifies a loop count greater than the number of available loops}}
109 #pragma acc kernels loop tile(One, 2) // expected-note 2{{active 'tile' clause defined here}}
110 for(int i = 0; i < 5; ++i)
111 // expected-error@+1{{while loop cannot appear in intervening code of a 'kernels loop' with a 'tile' clause}}
112 while(true);
114 // expected-error@+1{{'tile' clause specifies a loop count greater than the number of available loops}}
115 #pragma acc serial loop tile(One, 2) // expected-note 2{{active 'tile' clause defined here}}
116 for(int i = 0; i < 5; ++i)
117 // expected-error@+1{{do loop cannot appear in intervening code of a 'serial loop' with a 'tile' clause}}
118 do{}while(true);
122 void only_for_loops() {
123 // expected-note@+1{{'parallel loop' construct is here}}
124 #pragma acc parallel loop tile(1)
125 // expected-error@+1{{OpenACC 'parallel loop' construct can only be applied to a 'for' loop}}
126 while(true);
128 // expected-note@+1{{'serial loop' construct is here}}
129 #pragma acc serial loop tile(1)
130 // expected-error@+1{{OpenACC 'serial loop' construct can only be applied to a 'for' loop}}
131 do {} while(true);
133 // expected-error@+1{{'tile' clause specifies a loop count greater than the number of available loops}}
134 #pragma acc kernels loop tile(1, 2) // expected-note 2{{active 'tile' clause defined here}}
135 for(int i = 0; i < 5; ++i)
136 // expected-error@+1{{while loop cannot appear in intervening code of a 'kernels loop' with a 'tile' clause}}
137 while(true);
139 // expected-error@+1{{'tile' clause specifies a loop count greater than the number of available loops}}
140 #pragma acc parallel loop tile(1, 2) // expected-note 2{{active 'tile' clause defined here}}
141 for(int i = 0; i < 5; ++i)
142 // expected-error@+1{{do loop cannot appear in intervening code of a 'parallel loop' with a 'tile' clause}}
143 do{}while(true);
146 void only_one_on_loop() {
147 // expected-error@+2{{OpenACC 'tile' clause cannot appear more than once on a 'serial loop' directive}}
148 // expected-note@+1{{previous clause is here}}
149 #pragma acc serial loop tile(1) tile(1)
150 for(int i = 0; i < 5; ++i);
153 template<unsigned Val>
154 void depth_too_high_templ() {
155 // expected-error@+1{{'tile' clause specifies a loop count greater than the number of available loops}}
156 #pragma acc kernels loop tile (Val, *, Val) // expected-note{{active 'tile' clause defined here}}
157 for(int i = 0; i < 5; ++i)
158 for(int j = 0; j < 5; ++j);
160 // expected-error@+1{{'tile' clause specifies a loop count greater than the number of available loops}}
161 #pragma acc parallel loop tile (Val, *, Val) // expected-note 2{{active 'tile' clause defined here}}
162 for(int i = 0; i < 5; ++i)
163 for(int j = 0; j < 5; ++j)
164 // expected-error@+1{{while loop cannot appear in intervening code of a 'parallel loop' with a 'tile' clause}}
165 while(true);
167 // expected-error@+1{{'tile' clause specifies a loop count greater than the number of available loops}}
168 #pragma acc serial loop tile (Val, *, Val) // expected-note 2{{active 'tile' clause defined here}}
169 for(int i = 0; i < 5; ++i)
170 for(int j = 0; j < 5; ++j)
171 // expected-error@+1{{do loop cannot appear in intervening code of a 'serial loop' with a 'tile' clause}}
172 do{}while(true);
174 int Arr[Val+5];
176 // expected-error@+1{{'tile' clause specifies a loop count greater than the number of available loops}}
177 #pragma acc kernels loop tile (Val, *, Val) // expected-note 2{{active 'tile' clause defined here}}
178 for(int i = 0; i < 5; ++i)
179 for(auto x : Arr)
180 // expected-error@+1{{while loop cannot appear in intervening code of a 'kernels loop' with a 'tile' clause}}
181 while(true)
182 for(int j = 0; j < 5; ++j);
184 #pragma acc parallel loop tile (Val, *, Val)
185 for(int i = 0; i < 5; ++i)
186 for(auto x : Arr)
187 for(int j = 0; j < 5; ++j)
188 while(true);
191 void depth_too_high() {
192 depth_too_high_templ<3>();
194 int Arr[5];
196 // expected-error@+1{{'tile' clause specifies a loop count greater than the number of available loops}}
197 #pragma acc serial loop tile (1, *, 3) // expected-note{{active 'tile' clause defined here}}
198 for(int i = 0; i < 5; ++i)
199 for(int j = 0; j < 5; ++j);
201 // expected-error@+1{{'tile' clause specifies a loop count greater than the number of available loops}}
202 #pragma acc parallel loop tile (1, *, 3) // expected-note 2{{active 'tile' clause defined here}}
203 for(int i = 0; i < 5; ++i)
204 for(int j = 0; j < 5; ++j)
205 // expected-error@+1{{while loop cannot appear in intervening code of a 'parallel loop' with a 'tile' clause}}
206 while(true);
208 // expected-error@+1{{'tile' clause specifies a loop count greater than the number of available loops}}
209 #pragma acc parallel loop tile (1, *, 3) // expected-note 2{{active 'tile' clause defined here}}
210 for(int i = 0; i < 5; ++i)
211 for(int j = 0; j < 5; ++j)
212 // expected-error@+1{{do loop cannot appear in intervening code of a 'parallel loop' with a 'tile' clause}}
213 do{}while(true);
215 // expected-error@+1{{'tile' clause specifies a loop count greater than the number of available loops}}
216 #pragma acc parallel loop tile (1, *, 3) // expected-note 2{{active 'tile' clause defined here}}
217 for(int i = 0; i < 5; ++i)
218 for(int j = 0; j < 5; ++j)
219 // expected-error@+1{{while loop cannot appear in intervening code of a 'parallel loop' with a 'tile' clause}}
220 while(true)
221 for(int j = 0; j < 5; ++j);
223 #pragma acc parallel loop tile (1, *, 3)
224 for(int i = 0; i < 5; ++i)
225 for(auto x : Arr)
226 for(int j = 0; j < 5; ++j)
227 while(true);
230 template<unsigned Val>
231 void not_single_loop_templ() {
233 int Arr[Val];
235 #pragma acc parallel loop tile (Val, *, 3) // expected-note{{active 'tile' clause defined here}}
236 for(int i = 0; i < 5; ++i) {
237 for (auto x : Arr)
238 for(int k = 0; k < 5; ++k);
239 // expected-error@+1{{more than one for-loop in a loop associated with OpenACC 'parallel loop' construct with a 'tile' clause}}
240 for(int j = 0; j < 5; ++j)
241 for(int k = 0; k < 5; ++k);
245 void not_single_loop() {
246 not_single_loop_templ<3>(); // no diagnostic, was diagnosed in phase 1.
248 int Arr[5];
250 #pragma acc parallel loop tile (1, *, 3)// expected-note{{active 'tile' clause defined here}}
251 for(int i = 0; i < 5; ++i) {
252 for (auto x : Arr)
253 for(int k = 0; k < 5; ++k);
254 // expected-error@+1{{more than one for-loop in a loop associated with OpenACC 'parallel loop' construct with a 'tile' clause}}
255 for(int j = 0; j < 5; ++j)
256 for(int k = 0; k < 5; ++k);
260 template<unsigned Val>
261 void no_other_directives_templ() {
263 int Arr[Val];
265 #pragma acc parallel loop tile (Val, *, 3) // expected-note{{active 'tile' clause defined here}}
266 for(int i = 0; i < 5; ++i) {
267 for (auto x : Arr) {
268 // expected-error@+1{{OpenACC 'serial' construct cannot appear in intervening code of a 'parallel loop' with a 'tile' clause}}
269 #pragma acc serial
271 for(int j = 0; j < 5; ++j);
275 // OK, in innermost
276 #pragma acc parallel loop tile (Val, *, 3)
277 for(int i = 0; i < 5; ++i) {
278 for(int j = 0; j < 5; ++j) {
279 for (auto x : Arr) {
280 #pragma acc serial
287 void no_other_directives() {
288 no_other_directives_templ<3>();
289 int Arr[5];
291 #pragma acc parallel loop tile (1, *, 3) // expected-note{{active 'tile' clause defined here}}
292 for(int i = 0; i < 5; ++i) {
293 for (auto x : Arr) {
294 // expected-error@+1{{OpenACC 'serial' construct cannot appear in intervening code of a 'parallel loop' with a 'tile' clause}}
295 #pragma acc serial
297 for(int j = 0; j < 5; ++j);
301 // OK, in innermost
302 #pragma acc parallel loop tile (3, *, 3)
303 for(int i = 0; i < 5; ++i) {
304 for(int j = 0; j < 5; ++j) {
305 for (auto x : Arr) {
306 #pragma acc serial
313 void call();
314 template<unsigned Val>
315 void intervening_templ() {
316 #pragma acc parallel loop tile(1, Val, *) // expected-note{{active 'tile' clause defined here}}
317 for(int i = 0; i < 5; ++i) {
318 //expected-error@+1{{inner loops must be tightly nested inside a 'tile' clause on a 'parallel loop' construct}}
319 call();
320 for(int j = 0; j < 5; ++j)
321 for(int k = 0; k < 5; ++k);
324 #pragma acc parallel loop tile(1, Val, *) // expected-note{{active 'tile' clause defined here}}
325 for(int i = 0; i < 5; ++i) {
326 //expected-error@+1{{inner loops must be tightly nested inside a 'tile' clause on a 'parallel loop' construct}}
327 unsigned I;
328 for(int j = 0; j < 5; ++j)
329 for(int k = 0; k < 5; ++k);
332 #pragma acc parallel loop tile(1, Val, *)
333 // expected-error@+2{{OpenACC 'parallel loop' construct must have a terminating condition}}
334 // expected-note@-2{{'parallel loop' construct is here}}
335 for(int i = 0;;++i) {
336 // expected-error@+2{{OpenACC 'parallel loop' construct must have a terminating condition}}
337 // expected-note@-5{{'parallel loop' construct is here}}
338 for(int j = 0;;++j)
339 // expected-error@+2{{OpenACC 'parallel loop' construct must have a terminating condition}}
340 // expected-note@-8{{'parallel loop' construct is here}}
341 for(int k = 0;;++k)
342 call();
346 void intervening() {
347 intervening_templ<3>();
349 #pragma acc parallel loop tile(1, 2, *) // expected-note{{active 'tile' clause defined here}}
350 for(int i = 0; i < 5; ++i) {
351 //expected-error@+1{{inner loops must be tightly nested inside a 'tile' clause on a 'parallel loop' construct}}
352 call();
353 for(int j = 0; j < 5; ++j)
354 for(int k = 0; k < 5; ++k);
357 #pragma acc parallel loop tile(1, 2, *) // expected-note{{active 'tile' clause defined here}}
358 for(int i = 0; i < 5; ++i) {
359 //expected-error@+1{{inner loops must be tightly nested inside a 'tile' clause on a 'parallel loop' construct}}
360 unsigned I;
361 for(int j = 0; j < 5; ++j)
362 for(int k = 0; k < 5; ++k);
365 #pragma acc parallel loop tile(1, 2, *)
366 for(int i = 0; i < 5; ++i) {
367 for(int j = 0; j < 5; ++j)
368 for(int k = 0; k < 5; ++k)
369 call();
372 #pragma acc parallel loop tile(1, 2, *)
373 // expected-error@+2{{OpenACC 'parallel loop' construct must have a terminating condition}}
374 // expected-note@-2{{'parallel loop' construct is here}}
375 for(int i = 0;;++i) {
376 // expected-error@+2{{OpenACC 'parallel loop' construct must have a terminating condition}}
377 // expected-note@-5{{'parallel loop' construct is here}}
378 for(int j = 0;;++j)
379 // expected-error@+2{{OpenACC 'parallel loop' construct must have a terminating condition}}
380 // expected-note@-8{{'parallel loop' construct is here}}
381 for(int k = 0;;++k)
382 for(;;)
383 call();
387 void collapse_tile_depth() {
388 // expected-error@+4{{'collapse' clause specifies a loop count greater than the number of available loops}}
389 // expected-note@+3{{active 'collapse' clause defined here}}
390 // expected-error@+2{{'tile' clause specifies a loop count greater than the number of available loops}}
391 // expected-note@+1{{active 'tile' clause defined here}}
392 #pragma acc parallel loop tile(1, 2, 3) collapse (3)
393 for(int i = 0; i < 5;++i) {
394 for(int j = 0; j < 5; ++j);