Debian Codegraph @

clang/test/SemaOpenACC/loop-construct.cpp

raw
1 // RUN: %clang_cc1 %s -fopenacc -verify -Wno-empty-body -Wno-unused-value
2 namespace std {
3 struct random_access_iterator_tag{};
4 }
5
6 struct SomeStruct{
7 void operator++();
8 void operator++(int);
9 };
10
11 struct SomeIterator {
12 bool operator!=(SomeIterator&);
13 void operator++();
14 void operator++(int);
15 int operator*();
16 };
17
18 struct SomeRAIterator {
19 using iterator_category = std::random_access_iterator_tag;
20 SomeRAIterator();
21 SomeRAIterator(int i);
22
23 void operator=(int i);
24 SomeRAIterator &operator=(SomeRAIterator&);
25
26 void operator++(int);
27 void operator++();
28 int operator*();
29 void operator+=(int);
30 bool operator!=(SomeRAIterator&);
31 };
32
33 SomeRAIterator &operator+(const SomeRAIterator&, int);
34 SomeRAIterator &operator+(int,const SomeRAIterator&);
35 SomeRAIterator &operator-(const SomeRAIterator&, int);
36 SomeRAIterator &operator-(int,const SomeRAIterator&);
37
38 struct HasIteratorCollection {
39 SomeIterator &begin();
40 SomeIterator &end();
41 };
42
43 struct HasRAIteratorCollection {
44 SomeRAIterator &begin();
45 SomeRAIterator &end();
46 };
47
48 void func_call();
49
50 template<typename Int, typename IntPtr, typename Float, typename Struct, typename Iterator, typename RandAccessIterator>
51 void SeqLoopRules() {
52
53 // No rules in this section!
54 #pragma acc loop seq
55 for(;;);
56
57 #pragma acc loop seq
58 for(float f;;);
59
60 #pragma acc loop seq
61 for(int f;;);
62
63 #pragma acc loop seq
64 for(int f,g;;);
65
66 #pragma acc loop seq
67 for(Int f;;);
68
69 #pragma acc loop seq
70 for(Int *f;;);
71
72 #pragma acc loop seq
73 for(IntPtr f;;);
74
75 #pragma acc loop seq
76 for(Float *f;;);
77
78 #pragma acc loop seq
79 for(SomeStruct f;;);
80
81 #pragma acc loop seq
82 for(Struct f;;);
83
84 #pragma acc loop seq
85 for(SomeIterator f;;);
86
87 #pragma acc loop seq
88 for(Iterator f;;);
89
90 #pragma acc loop seq
91 for(SomeRAIterator f;;);
92
93 #pragma acc loop seq
94 for(RandAccessIterator f;;);
95
96 #pragma acc loop seq
97 for(Int f;;);
98
99 #pragma acc loop seq
100 for(Int f;;++f);
101
102 #pragma acc loop seq
103 for(Int f;;f+=1);
104
105 int i;
106 #pragma acc loop seq
107 for(Int f;;i+=1);
108
109 #pragma acc loop seq
110 for(Int f;;i++);
111
112 #pragma acc loop seq
113 for(RandAccessIterator f;;i++);
114
115 #pragma acc loop seq
116 for(RandAccessIterator f;;func_call());
117
118 Int Array[5];
119 #pragma acc loop seq
120 for(auto X : Array);
121
122 #pragma acc loop seq
123 for(auto X : HasIteratorCollection{});
124
125 #pragma acc loop seq
126 for(auto X : HasRAIteratorCollection{});
127
128 RandAccessIterator f;
129 #pragma acc loop seq
130 for(f;;f++);
131
132 #pragma acc loop seq
133 for(f = 0;;++f);
134
135 #pragma acc loop seq
136 for(f = 0;;f++);
137
138 #pragma acc loop seq
139 for(f = 0;;f+=1);
140 }
141
142
143 template<typename Int, typename IntPtr, typename Float, typename Struct, typename Iterator, typename RandAccessIterator>
144 void LoopRules() {
145
146 // Loop variable must be integer, pointer, or random_access_iterator
147 #pragma acc loop
148 // expected-error@+6{{OpenACC 'loop' construct must have initialization clause in canonical form ('var = init' or 'T var = init'}}
149 // expected-note@-2{{'loop' construct is here}}
150 // expected-error@+4{{OpenACC 'loop' construct must have a terminating condition}}
151 // expected-note@-4{{'loop' construct is here}}
152 // expected-error@+2{{OpenACC 'loop' variable must monotonically increase or decrease ('++', '--', or compound assignment)}}
153 // expected-note@-6{{'loop' construct is here}}
154 for(;;);
155
156 #pragma acc loop
157 // expected-error@+6{{loop variable of loop associated with an OpenACC 'loop' construct must be of integer, pointer, or random-access-iterator type (is 'float')}}
158 // expected-note@-2{{'loop' construct is here}}
159 // expected-error@+4{{OpenACC 'loop' construct must have a terminating condition}}
160 // expected-note@-4{{'loop' construct is here}}
161 // expected-error@+2{{OpenACC 'loop' variable must monotonically increase or decrease ('++', '--', or compound assignment)}}
162 // expected-note@-6{{'loop' construct is here}}
163 for(float f = 0;;);
164
165 #pragma acc loop
166 // expected-error@+6{{OpenACC 'loop' construct must have initialization clause in canonical form ('var = init' or 'T var = init'}}
167 // expected-note@-2{{'loop' construct is here}}
168 // expected-error@+4{{OpenACC 'loop' construct must have a terminating condition}}
169 // expected-note@-4{{'loop' construct is here}}
170 // expected-error@+2{{OpenACC 'loop' variable must monotonically increase or decrease ('++', '--', or compound assignment)}}
171 // expected-note@-6{{'loop' construct is here}}
172 for(int f;;);
173
174 #pragma acc loop
175 // expected-error@+6{{OpenACC 'loop' construct must have initialization clause in canonical form ('var = init' or 'T var = init'}}
176 // expected-note@-2{{'loop' construct is here}}
177 // expected-error@+4{{OpenACC 'loop' construct must have a terminating condition}}
178 // expected-note@-4{{'loop' construct is here}}
179 // expected-error@+2{{OpenACC 'loop' variable must monotonically increase or decrease ('++', '--', or compound assignment)}}
180 // expected-note@-6{{'loop' construct is here}}
181 for(int f,g;;);
182
183 #pragma acc loop
184 // expected-error@+4{{OpenACC 'loop' construct must have initialization clause in canonical form ('var = init' or 'T var = init'}}
185 // expected-note@-2{{'loop' construct is here}}
186 // expected-error@+2{{OpenACC 'loop' construct must have a terminating condition}}
187 // expected-note@-4{{'loop' construct is here}}
188 for(Int f;;++f);
189
190 #pragma acc loop
191 // expected-error@+2{{OpenACC 'loop' construct must have a terminating condition}}
192 // expected-note@-2{{'loop' construct is here}}
193 for(Int *f = nullptr;;++f);
194
195 #pragma acc loop
196 // expected-error@+2{{OpenACC 'loop' construct must have a terminating condition}}
197 // expected-note@-2{{'loop' construct is here}}
198 for(IntPtr f = nullptr;;++f);
199
200 #pragma acc loop
201 // expected-error@+2{{OpenACC 'loop' construct must have a terminating condition}}
202 // expected-note@-2{{'loop' construct is here}}
203 for(Float *f = nullptr;;++f);
204
205 #pragma acc loop
206 // expected-error@+6{{loop variable of loop associated with an OpenACC 'loop' construct must be of integer, pointer, or random-access-iterator type (is 'SomeStruct')}}
207 // expected-note@-2{{'loop' construct is here}}
208 // expected-error@+4{{OpenACC 'loop' construct must have a terminating condition}}
209 // expected-note@-4{{'loop' construct is here}}
210 // expected-error@+2{{OpenACC 'loop' variable must monotonically increase or decrease ('++', '--', or compound assignment)}}
211 // expected-note@-6{{'loop' construct is here}}
212 for(SomeStruct f;;);
213
214 #pragma acc loop
215 // expected-error@+4{{loop variable of loop associated with an OpenACC 'loop' construct must be of integer, pointer, or random-access-iterator type (is 'SomeStruct')}}
216 // expected-note@-2{{'loop' construct is here}}
217 // expected-error@+2{{OpenACC 'loop' construct must have a terminating condition}}
218 // expected-note@-4{{'loop' construct is here}}
219 for(Struct f;;++f);
220
221 #pragma acc loop
222 // expected-error@+4{{loop variable of loop associated with an OpenACC 'loop' construct must be of integer, pointer, or random-access-iterator type (is 'SomeIterator')}}
223 // expected-note@-2{{'loop' construct is here}}
224 // expected-error@+2{{OpenACC 'loop' construct must have a terminating condition}}
225 // expected-note@-4{{'loop' construct is here}}
226 for(SomeIterator f;;++f);
227
228 #pragma acc loop
229 // expected-error@+4{{loop variable of loop associated with an OpenACC 'loop' construct must be of integer, pointer, or random-access-iterator type (is 'SomeIterator')}}
230 // expected-note@-2{{'loop' construct is here}}
231 // expected-error@+2{{OpenACC 'loop' construct must have a terminating condition}}
232 // expected-note@-4{{'loop' construct is here}}
233 for(Iterator f;;++f);
234
235 #pragma acc loop
236 // expected-error@+2{{OpenACC 'loop' construct must have a terminating condition}}
237 // expected-note@-2{{'loop' construct is here}}
238 for(SomeRAIterator f;;++f);
239
240 #pragma acc loop
241 // expected-error@+2{{OpenACC 'loop' construct must have a terminating condition}}
242 // expected-note@-2{{'loop' construct is here}}
243 for(RandAccessIterator f;;++f);
244
245 Int i;
246 #pragma acc loop
247 // expected-error@+4{{OpenACC 'loop' construct must have a terminating condition}}
248 // expected-note@-2{{'loop' construct is here}}
249 // expected-error@+2{{OpenACC 'loop' variable must monotonically increase or decrease ('++', '--', or compound assignment)}}
250 // expected-note@-4{{'loop' construct is here}}
251 for( i = 0;;);
252
253 #pragma acc loop
254 // expected-error@+6{{OpenACC 'loop' construct must have initialization clause in canonical form ('var = init' or 'T var = init'}}
255 // expected-note@-2{{'loop' construct is here}}
256 // expected-error@+4{{OpenACC 'loop' construct must have a terminating condition}}
257 // expected-note@-4{{'loop' construct is here}}
258 // expected-error@+2{{OpenACC 'loop' variable must monotonically increase or decrease ('++', '--', or compound assignment)}}
259 // expected-note@-6{{'loop' construct is here}}
260 for( i;;);
261
262 #pragma acc loop
263 // expected-error@+6{{OpenACC 'loop' construct must have initialization clause in canonical form ('var = init' or 'T var = init'}}
264 // expected-note@-2{{'loop' construct is here}}
265 // expected-error@+4{{OpenACC 'loop' construct must have a terminating condition}}
266 // expected-note@-4{{'loop' construct is here}}
267 // expected-error@+2{{OpenACC 'loop' variable must monotonically increase or decrease ('++', '--', or compound assignment)}}
268 // expected-note@-6{{'loop' construct is here}}
269 for( int j ;;);
270
271 #pragma acc loop
272 // expected-error@+6{{OpenACC 'loop' construct must have initialization clause in canonical form ('var = init' or 'T var = init'}}
273 // expected-note@-2{{'loop' construct is here}}
274 // expected-error@+4{{OpenACC 'loop' construct must have a terminating condition}}
275 // expected-note@-4{{'loop' construct is here}}
276 // expected-error@+2{{OpenACC 'loop' variable must monotonically increase or decrease ('++', '--', or compound assignment)}}
277 // expected-note@-6{{'loop' construct is here}}
278 for( int j, k = 0;;);
279
280 #pragma acc loop
281 // expected-error@+6{{OpenACC 'loop' construct must have initialization clause in canonical form ('var = init' or 'T var = init'}}
282 // expected-note@-2{{'loop' construct is here}}
283 // expected-error@+4{{OpenACC 'loop' construct must have a terminating condition}}
284 // expected-note@-4{{'loop' construct is here}}
285 // expected-error@+2{{OpenACC 'loop' variable must monotonically increase or decrease ('++', '--', or compound assignment)}}
286 // expected-note@-6{{'loop' construct is here}}
287 for(Int f;;);
288
289 #pragma acc loop
290 // expected-error@+4{{OpenACC 'loop' construct must have initialization clause in canonical form ('var = init' or 'T var = init'}}
291 // expected-note@-2{{'loop' construct is here}}
292 // expected-error@+2{{OpenACC 'loop' construct must have a terminating condition}}
293 // expected-note@-4{{'loop' construct is here}}
294 for(Int f;;++f);
295
296 #pragma acc loop
297 // expected-error@+4{{OpenACC 'loop' construct must have initialization clause in canonical form ('var = init' or 'T var = init'}}
298 // expected-note@-2{{'loop' construct is here}}
299 // expected-error@+2{{OpenACC 'loop' construct must have a terminating condition}}
300 // expected-note@-4{{'loop' construct is here}}
301 for(Int f;;f+=1);
302
303 #pragma acc loop
304 // expected-error@+6{{OpenACC 'loop' construct must have initialization clause in canonical form ('var = init' or 'T var = init'}}
305 // expected-note@-2{{'loop' construct is here}}
306 // expected-error@+4{{OpenACC 'loop' construct must have a terminating condition}}
307 // expected-note@-4{{'loop' construct is here}}
308 // expected-error@+2{{OpenACC 'loop' variable must monotonically increase or decrease ('++', '--', or compound assignment)}}
309 // expected-note@-6{{'loop' construct is here}}
310 for(Int f;;i+=1);
311
312 #pragma acc loop
313 // expected-error@+6{{OpenACC 'loop' construct must have initialization clause in canonical form ('var = init' or 'T var = init'}}
314 // expected-note@-2{{'loop' construct is here}}
315 // expected-error@+4{{OpenACC 'loop' construct must have a terminating condition}}
316 // expected-note@-4{{'loop' construct is here}}
317 // expected-error@+2{{OpenACC 'loop' variable must monotonically increase or decrease ('++', '--', or compound assignment)}}
318 // expected-note@-6{{'loop' construct is here}}
319 for(Int f;;i++);
320
321 #pragma acc loop
322 // expected-error@+4{{OpenACC 'loop' construct must have a terminating condition}}
323 // expected-note@-2{{'loop' construct is here}}
324 // expected-error@+2{{OpenACC 'loop' variable must monotonically increase or decrease ('++', '--', or compound assignment)}}
325 // expected-note@-4{{'loop' construct is here}}
326 for(RandAccessIterator f;;i++);
327
328 #pragma acc loop
329 // expected-error@+4{{OpenACC 'loop' construct must have a terminating condition}}
330 // expected-note@-2{{'loop' construct is here}}
331 // expected-error@+2{{OpenACC 'loop' variable must monotonically increase or decrease ('++', '--', or compound assignment)}}
332 // expected-note@-4{{'loop' construct is here}}
333 for(RandAccessIterator f;;func_call());
334
335 // Not much we can do here other than check for random access iterator.
336 Int Array[5];
337 #pragma acc loop
338 for(auto X : Array);
339
340 #pragma acc loop
341 // expected-error@+2{{loop variable of loop associated with an OpenACC 'loop' construct must be of integer, pointer, or random-access-iterator type (is 'SomeIterator')}}
342 // expected-note@-2{{'loop' construct is here}}
343 for(auto X : HasIteratorCollection{});
344
345 #pragma acc loop
346 for(auto X : HasRAIteratorCollection{});
347
348 RandAccessIterator end;
349 #pragma acc loop
350 for(RandAccessIterator f = 0; f != end; ++f);
351
352 RandAccessIterator f;
353 #pragma acc loop
354 // expected-error@+2{{OpenACC 'loop' construct must have initialization clause in canonical form ('var = init' or 'T var = init'}}
355 // expected-note@-2{{'loop' construct is here}}
356 for(f;f != end;f++);
357
358 #pragma acc loop
359 // expected-error@+2{{OpenACC 'loop' construct must have a terminating condition}}
360 // expected-note@-2{{'loop' construct is here}}
361 for(f = 0;;++f);
362
363 #pragma acc loop
364 // expected-error@+2{{OpenACC 'loop' construct must have a terminating condition}}
365 // expected-note@-2{{'loop' construct is here}}
366 for(f = 0;;f++);
367
368 #pragma acc loop
369 // expected-error@+2{{OpenACC 'loop' construct must have a terminating condition}}
370 // expected-note@-2{{'loop' construct is here}}
371 for(f = 0;;f+=1);
372
373 #pragma acc loop
374 for(f = 0;f != end;++f);
375
376 #pragma acc loop
377 for(f = 0;f != end;f++);
378
379 #pragma acc loop
380 for(f = 0;f != end;f+=1);
381
382 #pragma acc loop
383 for (int i = 0; 5 >= i; ++i);
384
385 int otherI;
386 // expected-error@+3{{OpenACC 'loop' construct must have a terminating condition}}
387 // expected-note@+1{{'loop' construct is here}}
388 #pragma acc loop
389 for (int i = 0; otherI != 5; ++i);
390
391 // expected-error@+3{{OpenACC 'loop' construct must have a terminating condition}}
392 // expected-note@+1{{'loop' construct is here}}
393 #pragma acc loop
394 for (int i = 0; i != 5 && i < 3; ++i);
395
396 // expected-error@+3{{OpenACC 'loop' variable must monotonically increase or decrease}}
397 // expected-note@+1{{'loop' construct is here}}
398 #pragma acc loop
399 for (int i = 0; i != 5; ++f);
400 }
401
402 void inst() {
403 SeqLoopRules<int, int*, float, SomeStruct, SomeIterator, SomeRAIterator>();
404 // expected-note@+1{{in instantiation of function template specialization}}
405 LoopRules<int, int*, float, SomeStruct, SomeIterator, SomeRAIterator>();
406 }
407
408 void allowTrivialAssignStep(int N) {
409 #pragma acc loop
410 for(int i = 0; i !=5; i = i + N);
411 #pragma acc loop
412 for(int i = 0; i !=5; i = i - N);
413 #pragma acc loop
414 for(int i = 0; i !=5; i = N + i);
415
416 // expected-error@+3{{OpenACC 'loop' variable must monotonically increase or decrease}}
417 // expected-note@+1{{'loop' construct is here}}
418 #pragma acc loop
419 for(int i = 0; i !=5; i = N - i);
420 // expected-error@+3{{OpenACC 'loop' variable must monotonically increase or decrease}}
421 // expected-note@+1{{'loop' construct is here}}
422 #pragma acc loop
423 for(int i = 0; i !=5; i = N + N);
424
425 HasRAIteratorCollection Col;
426
427 #pragma acc loop
428 for (auto Itr = Col.begin(); Itr != Col.end(); Itr = Itr + N);
429
430 #pragma acc loop
431 for (auto Itr = Col.begin(); Itr != Col.end(); Itr = Itr - N);
432
433 #pragma acc loop
434 for (auto Itr = Col.begin(); Itr != Col.end(); Itr = N + Itr);
435
436 // expected-error@+3{{OpenACC 'loop' variable must monotonically increase or decrease}}
437 // expected-note@+1{{'loop' construct is here}}
438 #pragma acc loop
439 for (auto Itr = Col.begin(); Itr != Col.end(); Itr = N - Itr);
440 }
441