[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / OpenMP / distribute_parallel_for_simd_loop_messages.cpp
blob8195ed655f858b33a0d0c0a5d65b705e31a51585
1 // RUN: %clang_cc1 -fsyntax-only -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify=expected,omp4 %s -Wno-openmp-mapping -Wuninitialized
2 // RUN: %clang_cc1 -fsyntax-only -fopenmp -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify=expected,omp5 %s -Wno-openmp-mapping -Wuninitialized
4 // RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -fopenmp-version=45 -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify=expected,omp4 %s -Wno-openmp-mapping -Wuninitialized
5 // RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify=expected,omp5 %s -Wno-openmp-mapping -Wuninitialized
7 class S {
8 int a;
9 S() : a(0) {} // expected-note {{implicitly declared private here}}
11 public:
12 S(int v) : a(v) {}
13 S(const S &s) : a(s.a) {}
16 static int sii;
17 // expected-note@+1 {{defined as threadprivate or thread local}}
18 #pragma omp threadprivate(sii)
19 static int globalii;
21 int test_iteration_spaces() {
22 const int N = 100;
23 float a[N], b[N], c[N];
24 int ii, jj, kk;
25 float fii;
26 double dii;
27 #pragma omp target
28 #pragma omp teams
29 #pragma omp distribute parallel for simd
30 for (int i = 0; i < 10; i += 1) {
31 c[i] = a[i] + b[i];
33 #pragma omp target
34 #pragma omp teams
35 #pragma omp distribute parallel for simd
36 for (char i = 0; i < 10; i++) {
37 c[i] = a[i] + b[i];
39 #pragma omp target
40 #pragma omp teams
41 #pragma omp distribute parallel for simd
42 for (char i = 0; i < 10; i += '\1') {
43 c[i] = a[i] + b[i];
45 #pragma omp target
46 #pragma omp teams
47 #pragma omp distribute parallel for simd
48 for (long long i = 0; i < 10; i++) {
49 c[i] = a[i] + b[i];
51 #pragma omp target
52 #pragma omp teams
53 // expected-error@+2 {{expression must have integral or unscoped enumeration type, not 'double'}}
54 #pragma omp distribute parallel for simd
55 for (long long i = 0; i < 10; i += 1.5) {
56 c[i] = a[i] + b[i];
58 #pragma omp target
59 #pragma omp teams
60 #pragma omp distribute parallel for simd
61 for (long long i = 0; i < 'z'; i += 1u) {
62 c[i] = a[i] + b[i];
64 #pragma omp target
65 #pragma omp teams
66 // expected-error@+2 {{variable must be of integer or random access iterator type}}
67 #pragma omp distribute parallel for simd
68 for (float fi = 0; fi < 10.0; fi++) {
69 c[(int)fi] = a[(int)fi] + b[(int)fi];
71 #pragma omp target
72 #pragma omp teams
73 // expected-error@+2 {{variable must be of integer or random access iterator type}}
74 #pragma omp distribute parallel for simd
75 for (double fi = 0; fi < 10.0; fi++) {
76 c[(int)fi] = a[(int)fi] + b[(int)fi];
78 #pragma omp target
79 #pragma omp teams
80 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
81 #pragma omp distribute parallel for simd
82 for (int &ref = ii; ref < 10; ref++) {
84 #pragma omp target
85 #pragma omp teams
86 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
87 #pragma omp distribute parallel for simd
88 for (int i; i < 10; i++)
89 c[i] = a[i];
91 #pragma omp target
92 #pragma omp teams
93 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
94 #pragma omp distribute parallel for simd
95 for (int i = 0, j = 0; i < 10; ++i)
96 c[i] = a[i];
98 #pragma omp target
99 #pragma omp teams
100 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
101 #pragma omp distribute parallel for simd
102 for (; ii < 10; ++ii)
103 c[ii] = a[ii];
105 #pragma omp target
106 #pragma omp teams
107 // expected-warning@+3 {{expression result unused}}
108 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
109 #pragma omp distribute parallel for simd
110 for (ii + 1; ii < 10; ++ii)
111 c[ii] = a[ii];
113 #pragma omp target
114 #pragma omp teams
115 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
116 #pragma omp distribute parallel for simd
117 for (c[ii] = 0; ii < 10; ++ii)
118 c[ii] = a[ii];
120 #pragma omp target
121 #pragma omp teams
122 // Ok to skip parenthesises.
123 #pragma omp distribute parallel for simd
124 for (((ii)) = 0; ii < 10; ++ii)
125 c[ii] = a[ii];
127 #pragma omp target
128 #pragma omp teams
129 // omp4-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}} omp5-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'i'}}
130 #pragma omp distribute parallel for simd
131 for (int i = 0; i; i++)
132 c[i] = a[i];
134 #pragma omp target
135 #pragma omp teams
136 // omp4-error@+3 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}} omp5-error@+3 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'i'}}
137 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'i'}}
138 #pragma omp distribute parallel for simd
139 for (int i = 0; jj < kk; ii++)
140 c[i] = a[i];
142 #pragma omp target
143 #pragma omp teams
144 // omp4-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}} omp5-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'i'}}
145 #pragma omp distribute parallel for simd
146 for (int i = 0; !!i; i++)
147 c[i] = a[i];
149 #pragma omp target
150 #pragma omp teams
151 // omp4-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}}
152 #pragma omp distribute parallel for simd
153 for (int i = 0; i != 1; i++)
154 c[i] = a[i];
156 #pragma omp target
157 #pragma omp teams
158 // omp4-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}} omp5-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'i'}}
159 #pragma omp distribute parallel for simd
160 for (int i = 0;; i++)
161 c[i] = a[i];
163 // Ok.
164 #pragma omp target
165 #pragma omp teams
166 #pragma omp distribute parallel for simd
167 for (int i = 11; i > 10; i--)
168 c[i] = a[i];
170 // Ok.
171 #pragma omp target
172 #pragma omp teams
173 #pragma omp distribute parallel for simd
174 for (int i = 0; i < 10; ++i)
175 c[i] = a[i];
177 // Ok.
178 #pragma omp target
179 #pragma omp teams
180 #pragma omp distribute parallel for simd
181 for (ii = 0; ii < 10; ++ii)
182 c[ii] = a[ii];
184 #pragma omp target
185 #pragma omp teams
186 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
187 #pragma omp distribute parallel for simd
188 for (ii = 0; ii < 10; ++jj)
189 c[ii] = a[jj];
191 #pragma omp target
192 #pragma omp teams
193 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
194 #pragma omp distribute parallel for simd
195 for (ii = 0; ii < 10; ++++ii)
196 c[ii] = a[ii];
198 // Ok but undefined behavior (in general, cannot check that incr
199 // is really loop-invariant).
200 #pragma omp target
201 #pragma omp teams
202 #pragma omp distribute parallel for simd
203 for (ii = 0; ii < 10; ii = ii + ii)
204 c[ii] = a[ii];
206 #pragma omp target
207 #pragma omp teams
208 // expected-error@+2 {{expression must have integral or unscoped enumeration type, not 'float'}}
209 #pragma omp distribute parallel for simd
210 for (ii = 0; ii < 10; ii = ii + 1.0f)
211 c[ii] = a[ii];
213 // Ok - step was converted to integer type.
214 #pragma omp target
215 #pragma omp teams
216 #pragma omp distribute parallel for simd
217 for (ii = 0; ii < 10; ii = ii + (int)1.1f)
218 c[ii] = a[ii];
220 #pragma omp target
221 #pragma omp teams
222 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
223 #pragma omp distribute parallel for simd
224 for (ii = 0; ii < 10; jj = ii + 2)
225 c[ii] = a[ii];
227 #pragma omp target
228 #pragma omp teams
229 // expected-warning@+3 {{relational comparison result unused}}
230 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
231 #pragma omp distribute parallel for simd
232 for (ii = 0; ii<10; jj> kk + 2)
233 c[ii] = a[ii];
235 #pragma omp target
236 #pragma omp teams
237 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
238 #pragma omp distribute parallel for simd
239 for (ii = 0; ii < 10;)
240 c[ii] = a[ii];
242 #pragma omp target
243 #pragma omp teams
244 // expected-warning@+3 {{expression result unused}}
245 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
246 #pragma omp distribute parallel for simd
247 for (ii = 0; ii < 10; !ii)
248 c[ii] = a[ii];
250 #pragma omp target
251 #pragma omp teams
252 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
253 #pragma omp distribute parallel for simd
254 for (ii = 0; ii < 10; ii ? ++ii : ++jj)
255 c[ii] = a[ii];
257 #pragma omp target
258 #pragma omp teams
259 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
260 #pragma omp distribute parallel for simd
261 for (ii = 0; ii < 10; ii = ii < 10)
262 c[ii] = a[ii];
264 #pragma omp target
265 #pragma omp teams
266 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
267 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
268 #pragma omp distribute parallel for simd
269 for (ii = 0; ii < 10; ii = ii + 0)
270 c[ii] = a[ii];
272 #pragma omp target
273 #pragma omp teams
274 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
275 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
276 #pragma omp distribute parallel for simd
277 for (ii = 0; ii < 10; ii = ii + (int)(0.8 - 0.45))
278 c[ii] = a[ii];
280 #pragma omp target
281 #pragma omp teams
282 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
283 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
284 #pragma omp distribute parallel for simd
285 for (ii = 0; (ii) < 10; ii -= 25)
286 c[ii] = a[ii];
288 #pragma omp target
289 #pragma omp teams
290 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
291 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
292 #pragma omp distribute parallel for simd
293 for (ii = 0; (ii < 10); ii -= 0)
294 c[ii] = a[ii];
296 #pragma omp target
297 #pragma omp teams
298 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
299 // expected-error@+2 {{increment expression must cause 'ii' to decrease on each iteration of OpenMP for loop}}
300 #pragma omp distribute parallel for simd
301 for (ii = 0; ii > 10; (ii += 0))
302 c[ii] = a[ii];
304 #pragma omp target
305 #pragma omp teams
306 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
307 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
308 #pragma omp distribute parallel for simd
309 for (ii = 0; ii < 10; (ii) = (1 - 1) + (ii))
310 c[ii] = a[ii];
312 #pragma omp target
313 #pragma omp teams
314 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
315 // expected-error@+2 {{increment expression must cause 'ii' to decrease on each iteration of OpenMP for loop}}
316 #pragma omp distribute parallel for simd
317 for ((ii = 0); ii > 10; (ii -= 0))
318 c[ii] = a[ii];
320 #pragma omp target
321 #pragma omp teams
322 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
323 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
324 #pragma omp distribute parallel for simd
325 for (ii = 0; (ii < 10); (ii -= 0))
326 c[ii] = a[ii];
328 #pragma omp target
329 #pragma omp teams
330 // expected-note@+2 {{defined as firstprivate}}
331 // expected-error@+2 {{loop iteration variable in the associated loop of 'omp distribute parallel for simd' directive may not be firstprivate, predetermined as linear}}
332 #pragma omp distribute parallel for simd firstprivate(ii)
333 for (ii = 0; ii < 10; ii++)
334 c[ii] = a[ii];
336 #pragma omp target
337 #pragma omp teams
338 #pragma omp distribute parallel for simd linear(ii)
339 for (ii = 0; ii < 10; ii++)
340 c[ii] = a[ii];
342 #pragma omp target
343 #pragma omp teams
344 // omp4-note@+2 {{defined as private}}
345 // omp4-error@+2 {{loop iteration variable in the associated loop of 'omp distribute parallel for simd' directive may not be private, predetermined as linear}}
346 #pragma omp distribute parallel for simd private(ii)
347 for (ii = 0; ii < 10; ii++)
348 c[ii] = a[ii];
350 #pragma omp target
351 #pragma omp teams
352 // omp4-note@+2 {{defined as lastprivate}}
353 // omp4-error@+2 {{loop iteration variable in the associated loop of 'omp distribute parallel for simd' directive may not be lastprivate, predetermined as linear}}
354 #pragma omp distribute parallel for simd lastprivate(ii)
355 for (ii = 0; ii < 10; ii++)
356 c[ii] = a[ii];
359 // expected-error@+2 {{loop iteration variable in the associated loop of 'omp distribute parallel for simd' directive may not be threadprivate or thread local, predetermined as linear}}
360 #pragma omp distribute parallel for simd
361 for (sii = 0; sii < 10; sii += 1)
362 c[sii] = a[sii];
366 #pragma omp distribute parallel for simd
367 for (globalii = 0; globalii < 10; globalii += 1)
368 c[globalii] = a[globalii];
372 #pragma omp target
373 #pragma omp teams
374 #pragma omp distribute parallel for simd collapse(2)
375 for (ii = 0; ii < 10; ii += 1)
376 for (globalii = 0; globalii < 10; globalii += 1)
377 c[globalii] += a[globalii] + ii;
380 #pragma omp target
381 #pragma omp teams
382 // omp4-error@+2 {{statement after '#pragma omp distribute parallel for simd' must be a for loop}}
383 #pragma omp distribute parallel for simd
384 for (auto &item : a) {
385 item = item + 1;
388 #pragma omp target
389 #pragma omp teams
390 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
391 // expected-error@+2 {{increment expression must cause 'i' to increase on each iteration of OpenMP for loop}}
392 #pragma omp distribute parallel for simd
393 for (unsigned i = 9; i < 10; i--) {
394 c[i] = a[i] + b[i];
397 int(*lb)[4] = nullptr;
398 #pragma omp target
399 #pragma omp teams
400 #pragma omp distribute parallel for simd
401 for (int(*p)[4] = lb; p < lb + 8; ++p) {
404 #pragma omp target
405 #pragma omp teams
406 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
407 #pragma omp distribute parallel for simd
408 for (int a{0}; a < 10; ++a) {
411 return 0;
414 // Iterators allowed in openmp for-loops.
415 namespace std {
416 struct random_access_iterator_tag {};
417 template <class Iter>
418 struct iterator_traits {
419 typedef typename Iter::difference_type difference_type;
420 typedef typename Iter::iterator_category iterator_category;
422 template <class Iter>
423 typename iterator_traits<Iter>::difference_type
424 distance(Iter first, Iter last) { return first - last; }
426 class Iter0 {
427 public:
428 Iter0() {}
429 Iter0(const Iter0 &) {}
430 Iter0 operator++() { return *this; }
431 Iter0 operator--() { return *this; }
432 bool operator<(Iter0 a) { return true; }
434 // expected-note@+2 {{candidate function not viable: no known conversion from 'GoodIter' to 'Iter0' for 1st argument}}
435 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'Iter0' for 1st argument}}
436 int operator-(Iter0 a, Iter0 b) { return 0; }
437 class Iter1 {
438 public:
439 Iter1(float f = 0.0f, double d = 0.0) {}
440 Iter1(const Iter1 &) {}
441 Iter1 operator++() { return *this; }
442 Iter1 operator--() { return *this; }
443 bool operator<(Iter1 a) { return true; }
444 bool operator>=(Iter1 a) { return false; }
446 class GoodIter {
447 public:
448 GoodIter() {}
449 GoodIter(const GoodIter &) {}
450 GoodIter(int fst, int snd) {}
451 GoodIter &operator=(const GoodIter &that) { return *this; }
452 GoodIter &operator=(const Iter0 &that) { return *this; }
453 GoodIter &operator+=(int x) { return *this; }
454 explicit GoodIter(void *) {}
455 GoodIter operator++() { return *this; }
456 GoodIter operator--() { return *this; }
457 bool operator!() { return true; }
458 bool operator<(GoodIter a) { return true; }
459 bool operator<=(GoodIter a) { return true; }
460 bool operator>=(GoodIter a) { return false; }
461 typedef int difference_type;
462 typedef std::random_access_iterator_tag iterator_category;
464 // expected-note@+2 {{candidate function not viable: no known conversion from 'const Iter0' to 'GoodIter' for 2nd argument}}
465 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}}
466 int operator-(GoodIter a, GoodIter b) { return 0; }
467 // expected-note@+1 3 {{candidate function not viable: requires single argument 'a', but 2 arguments were provided}}
468 GoodIter operator-(GoodIter a) { return a; }
469 // expected-note@+2 {{candidate function not viable: no known conversion from 'const Iter0' to 'int' for 2nd argument}}
470 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}}
471 GoodIter operator-(GoodIter a, int v) { return GoodIter(); }
472 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter0' to 'GoodIter' for 1st argument}}
473 GoodIter operator+(GoodIter a, int v) { return GoodIter(); }
474 // expected-note@+2 {{candidate function not viable: no known conversion from 'GoodIter' to 'int' for 1st argument}}
475 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'int' for 1st argument}}
476 GoodIter operator-(int v, GoodIter a) { return GoodIter(); }
477 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter0' to 'int' for 1st argument}}
478 GoodIter operator+(int v, GoodIter a) { return GoodIter(); }
480 int test_with_random_access_iterator() {
481 GoodIter begin, end;
482 Iter0 begin0, end0;
483 #pragma omp target
484 #pragma omp teams
485 #pragma omp distribute parallel for simd
486 for (GoodIter I = begin; I < end; ++I)
487 ++I;
488 #pragma omp target
489 #pragma omp teams
490 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
491 #pragma omp distribute parallel for simd
492 for (GoodIter &I = begin; I < end; ++I)
493 ++I;
494 #pragma omp target
495 #pragma omp teams
496 #pragma omp distribute parallel for simd
497 for (GoodIter I = begin; I >= end; --I)
498 ++I;
499 #pragma omp target
500 #pragma omp teams
501 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
502 #pragma omp distribute parallel for simd
503 for (GoodIter I(begin); I < end; ++I)
504 ++I;
505 #pragma omp target
506 #pragma omp teams
507 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
508 #pragma omp distribute parallel for simd
509 for (GoodIter I(nullptr); I < end; ++I)
510 ++I;
511 #pragma omp target
512 #pragma omp teams
513 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
514 #pragma omp distribute parallel for simd
515 for (GoodIter I(0); I < end; ++I)
516 ++I;
517 #pragma omp target
518 #pragma omp teams
519 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
520 #pragma omp distribute parallel for simd
521 for (GoodIter I(1, 2); I < end; ++I)
522 ++I;
523 #pragma omp target
524 #pragma omp teams
525 #pragma omp distribute parallel for simd
526 for (begin = GoodIter(0); begin < end; ++begin)
527 ++begin;
528 #pragma omp target
529 #pragma omp teams
530 // expected-error@+3 {{invalid operands to binary expression ('GoodIter' and 'const Iter0')}}
531 // expected-error@+2 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}
532 #pragma omp distribute parallel for simd
533 for (begin = begin0; begin < end; ++begin)
534 ++begin;
535 #pragma omp target
536 #pragma omp teams
537 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
538 #pragma omp distribute parallel for simd
539 for (++begin; begin < end; ++begin)
540 ++begin;
541 #pragma omp target
542 #pragma omp teams
543 #pragma omp distribute parallel for simd
544 for (begin = end; begin < end; ++begin)
545 ++begin;
546 #pragma omp target
547 #pragma omp teams
548 // omp4-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'I'}} omp5-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'I'}}
549 #pragma omp distribute parallel for simd
550 for (GoodIter I = begin; I - I; ++I)
551 ++I;
552 #pragma omp target
553 #pragma omp teams
554 // omp4-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'I'}} omp5-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'I'}}
555 #pragma omp distribute parallel for simd
556 for (GoodIter I = begin; begin < end; ++I)
557 ++I;
558 #pragma omp target
559 #pragma omp teams
560 // omp4-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'I'}} omp5-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'I'}}
561 #pragma omp distribute parallel for simd
562 for (GoodIter I = begin; !I; ++I)
563 ++I;
564 #pragma omp target
565 #pragma omp teams
566 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
567 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
568 #pragma omp distribute parallel for simd
569 for (GoodIter I = begin; I >= end; I = I + 1)
570 ++I;
571 #pragma omp target
572 #pragma omp teams
573 #pragma omp distribute parallel for simd
574 for (GoodIter I = begin; I >= end; I = I - 1)
575 ++I;
576 #pragma omp target
577 #pragma omp teams
578 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}}
579 #pragma omp distribute parallel for simd
580 for (GoodIter I = begin; I >= end; I = -I)
581 ++I;
582 #pragma omp target
583 #pragma omp teams
584 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
585 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
586 #pragma omp distribute parallel for simd
587 for (GoodIter I = begin; I >= end; I = 2 + I)
588 ++I;
589 #pragma omp target
590 #pragma omp teams
591 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}}
592 #pragma omp distribute parallel for simd
593 for (GoodIter I = begin; I >= end; I = 2 - I)
594 ++I;
595 #pragma omp target
596 #pragma omp teams
597 // expected-error@+2 {{invalid operands to binary expression ('Iter0' and 'int')}}
598 #pragma omp distribute parallel for simd
599 for (Iter0 I = begin0; I < end0; ++I)
600 ++I;
601 #pragma omp target
602 #pragma omp teams
603 // Initializer is constructor without params.
604 // expected-error@+3 {{invalid operands to binary expression ('Iter0' and 'int')}}
605 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
606 #pragma omp distribute parallel for simd
607 for (Iter0 I; I < end0; ++I)
608 ++I;
609 Iter1 begin1, end1;
610 #pragma omp target
611 #pragma omp teams
612 // expected-error@+3 {{invalid operands to binary expression ('Iter1' and 'Iter1')}}
613 // expected-error@+2 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}
614 #pragma omp distribute parallel for simd
615 for (Iter1 I = begin1; I < end1; ++I)
616 ++I;
617 #pragma omp target
618 #pragma omp teams
619 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
620 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
621 #pragma omp distribute parallel for simd
622 for (Iter1 I = begin1; I >= end1; ++I)
623 ++I;
624 #pragma omp target
625 #pragma omp teams
626 // expected-error@+5 {{invalid operands to binary expression ('Iter1' and 'float')}}
627 // expected-error@+4 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}
628 // Initializer is constructor with all default params.
629 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
630 #pragma omp distribute parallel for simd
631 for (Iter1 I; I < end1; ++I) {
633 return 0;
636 template <typename IT, int ST>
637 class TC {
638 public:
639 int dotest_lt(IT begin, IT end) {
640 #pragma omp target
641 #pragma omp teams
642 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
643 // expected-error@+2 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}}
644 #pragma omp distribute parallel for simd
645 for (IT I = begin; I < end; I = I + ST) {
646 ++I;
648 #pragma omp target
649 #pragma omp teams
650 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
651 // expected-error@+2 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}}
652 #pragma omp distribute parallel for simd
653 for (IT I = begin; I <= end; I += ST) {
654 ++I;
656 #pragma omp target
657 #pragma omp teams
658 #pragma omp distribute parallel for simd
659 for (IT I = begin; I < end; ++I) {
660 ++I;
664 static IT step() {
665 return IT(ST);
668 template <typename IT, int ST = 0>
669 int dotest_gt(IT begin, IT end) {
670 #pragma omp target
671 #pragma omp teams
672 // expected-note@+3 2 {{loop step is expected to be negative due to this condition}}
673 // expected-error@+2 2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
674 #pragma omp distribute parallel for simd
675 for (IT I = begin; I >= end; I = I + ST) {
676 ++I;
678 #pragma omp target
679 #pragma omp teams
680 // expected-note@+3 2 {{loop step is expected to be negative due to this condition}}
681 // expected-error@+2 2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
682 #pragma omp distribute parallel for simd
683 for (IT I = begin; I >= end; I += ST) {
684 ++I;
687 #pragma omp target
688 #pragma omp teams
689 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
690 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
691 #pragma omp distribute parallel for simd
692 for (IT I = begin; I >= end; ++I) {
693 ++I;
696 #pragma omp distribute parallel for simd
697 for (IT I = begin; I < end; I += TC<int, ST>::step()) {
698 ++I;
702 void test_with_template() {
703 GoodIter begin, end;
704 TC<GoodIter, 100> t1;
705 TC<GoodIter, -100> t2;
706 t1.dotest_lt(begin, end);
707 t2.dotest_lt(begin, end); // expected-note {{in instantiation of member function 'TC<GoodIter, -100>::dotest_lt' requested here}}
708 dotest_gt(begin, end); // expected-note {{in instantiation of function template specialization 'dotest_gt<GoodIter, 0>' requested here}}
709 dotest_gt<unsigned, 10>(0, 100); // expected-note {{in instantiation of function template specialization 'dotest_gt<unsigned int, 10>' requested here}}
712 void test_loop_break() {
713 const int N = 100;
714 float a[N], b[N], c[N];
715 #pragma omp target
716 #pragma omp teams
717 #pragma omp distribute parallel for simd
718 for (int i = 0; i < 10; i++) {
719 c[i] = a[i] + b[i];
720 for (int j = 0; j < 10; ++j) {
721 if (a[i] > b[j])
722 break; // OK in nested loop
724 switch (i) {
725 case 1:
726 b[i]++;
727 break;
728 default:
729 break;
731 if (c[i] > 10)
732 break; // expected-error {{'break' statement cannot be used in OpenMP for loop}}
734 if (c[i] > 11)
735 break; // expected-error {{'break' statement cannot be used in OpenMP for loop}}
738 #pragma omp target
739 #pragma omp teams
740 #pragma omp distribute parallel for simd
741 for (int i = 0; i < 10; i++) {
742 for (int j = 0; j < 10; j++) {
743 c[i] = a[i] + b[i];
744 if (c[i] > 10) {
745 if (c[i] < 20) {
746 break; // OK
753 void test_loop_eh() {
754 const int N = 100;
755 float a[N], b[N], c[N];
756 #pragma omp target
757 #pragma omp teams
758 #pragma omp distribute parallel for simd
759 for (int i = 0; i < 10; i++) {
760 c[i] = a[i] + b[i];
761 try { // expected-error {{'try' statement cannot be used in OpenMP simd region}}
762 for (int j = 0; j < 10; ++j) {
763 if (a[i] > b[j])
764 throw a[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
766 throw a[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
767 } catch (float f) {
768 if (f > 0.1)
769 throw a[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
770 return; // expected-error {{cannot return from OpenMP region}}
772 switch (i) {
773 case 1:
774 b[i]++;
775 break;
776 default:
777 break;
779 for (int j = 0; j < 10; j++) {
780 if (c[i] > 10)
781 throw c[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
784 if (c[9] > 10)
785 throw c[9]; // OK
787 #pragma omp distribute parallel for simd
788 for (int i = 0; i < 10; ++i) {
789 struct S {
790 void g() { throw 0; }
795 void test_loop_firstprivate_lastprivate() {
796 S s(4);
797 // expected-error@+3 {{lastprivate variable cannot be firstprivate}} expected-note@+3 {{defined as lastprivate}}
798 #pragma omp target
799 #pragma omp teams
800 #pragma omp distribute parallel for simd lastprivate(s) firstprivate(s) // expected-error {{calling a private constructor of class 'S'}}
801 for (int i = 0; i < 16; ++i)
805 void test_ordered() {
806 #pragma omp target
807 #pragma omp teams
808 #pragma omp distribute parallel for simd ordered // expected-error {{unexpected OpenMP clause 'ordered' in directive '#pragma omp distribute parallel for simd'}}
809 for (int i = 0; i < 16; ++i)
813 void test_nowait() {
814 #pragma omp target
815 #pragma omp teams
816 // expected-error@+1 2 {{unexpected OpenMP clause 'nowait' in directive '#pragma omp distribute parallel for simd'}}
817 #pragma omp distribute parallel for simd nowait nowait // expected-error {{directive '#pragma omp distribute parallel for simd' cannot contain more than one 'nowait' clause}}
818 for (int i = 0; i < 16; ++i)