Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / for_loop_messages.cpp
blobe62ec07acc04936915481f2d8e7d4dbd3cd546ba
1 // RUN: %clang_cc1 -fsyntax-only -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify=expected,omp4 %s -Wuninitialized
2 // RUN: %clang_cc1 -fsyntax-only -fopenmp -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify=expected,omp5 %s -Wuninitialized
4 // RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -fopenmp-version=45 -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify=expected,omp4 %s -Wuninitialized
5 // RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify=expected,omp5 %s -Wuninitialized
7 class S {
8 int a;
9 S() : a(0) {}
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 // Currently, we cannot use "0" for global register variables.
22 // register int reg0 __asm__("0");
23 int reg0;
25 int test_iteration_spaces() {
26 const int N = 100;
27 float a[N], b[N], c[N];
28 int ii, jj, kk;
29 float fii;
30 double dii;
31 register int reg; // expected-warning {{'register' storage class specifier is deprecated}}
32 #pragma omp parallel
33 #pragma omp for
34 for (int i = 0; i < 10; i += 1) {
35 c[i] = a[i] + b[i];
37 #pragma omp parallel
38 #pragma omp for
39 for (char i = 0; i < 10; i++) {
40 c[i] = a[i] + b[i];
42 #pragma omp parallel
43 #pragma omp for
44 for (char i = 0; i < 10; i += '\1') {
45 c[i] = a[i] + b[i];
47 #pragma omp parallel
48 #pragma omp for
49 for (long long i = 0; i < 10; i++) {
50 c[i] = a[i] + b[i];
52 #pragma omp parallel
53 // expected-error@+2 {{expression must have integral or unscoped enumeration type, not 'double'}}
54 #pragma omp for
55 for (long long i = 0; i < 10; i += 1.5) {
56 c[i] = a[i] + b[i];
58 #pragma omp parallel
59 #pragma omp for
60 for (long long i = 0; i < 'z'; i += 1u) {
61 c[i] = a[i] + b[i];
63 #pragma omp parallel
64 // expected-error@+2 {{variable must be of integer or random access iterator type}}
65 #pragma omp for
66 for (float fi = 0; fi < 10.0; fi++) {
67 c[(int)fi] = a[(int)fi] + b[(int)fi];
69 #pragma omp parallel
70 // expected-error@+2 {{variable must be of integer or random access iterator type}}
71 #pragma omp for
72 for (double fi = 0; fi < 10.0; fi++) {
73 c[(int)fi] = a[(int)fi] + b[(int)fi];
75 #pragma omp parallel
76 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
77 #pragma omp for
78 for (int &ref = ii; ref < 10; ref++) {
80 #pragma omp parallel
81 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
82 #pragma omp for
83 for (int i; i < 10; i++)
84 c[i] = a[i];
86 #pragma omp parallel
87 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
88 #pragma omp for
89 for (int i = 0, j = 0; i < 10; ++i)
90 c[i] = a[i];
92 #pragma omp parallel
93 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
94 #pragma omp for
95 for (; ii < 10; ++ii)
96 c[ii] = a[ii];
98 #pragma omp parallel
99 // expected-warning@+3 {{expression result unused}}
100 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
101 #pragma omp for
102 for (ii + 1; ii < 10; ++ii)
103 c[ii] = a[ii];
105 #pragma omp parallel
106 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
107 #pragma omp for
108 for (c[ii] = 0; ii < 10; ++ii)
109 c[ii] = a[ii];
111 #pragma omp parallel
112 // Ok to skip parenthesises.
113 #pragma omp for
114 for (((ii)) = 0; ii < 10; ++ii)
115 c[ii] = a[ii];
117 #pragma omp parallel
118 // 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'}}
119 #pragma omp for
120 for (int i = 0; i; i++)
121 c[i] = a[i];
123 #pragma omp parallel
124 // 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'}}
125 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'i'}}
126 #pragma omp for
127 for (int i = 0; jj < kk; ii++)
128 c[i] = a[i];
130 #pragma omp parallel
131 // 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'}}
132 #pragma omp for
133 for (int i = 0; !!i; i++)
134 c[i] = a[i];
136 #pragma omp parallel
137 // omp4-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}}
138 #pragma omp for
139 for (int i = 0; i != 1; i++)
140 c[i] = a[i];
142 #pragma omp parallel
143 // 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'}}
144 #pragma omp for
145 for (int i = 0;; i++)
146 c[i] = a[i];
148 #pragma omp parallel
149 // Ok.
150 #pragma omp for
151 for (int i = 11; i > 10; i--)
152 c[i] = a[i];
154 #pragma omp parallel
155 // Ok.
156 #pragma omp for
157 for (int i = 0; i < 10; ++i)
158 c[i] = a[i];
160 #pragma omp parallel
161 // Ok.
162 #pragma omp for
163 for (ii = 0; ii < 10; ++ii)
164 c[ii] = a[ii];
166 #pragma omp parallel
167 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
168 #pragma omp for
169 for (ii = 0; ii < 10; ++jj)
170 c[ii] = a[jj];
172 #pragma omp parallel
173 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
174 #pragma omp for
175 for (ii = 0; ii < 10; ++++ii)
176 c[ii] = a[ii];
178 #pragma omp parallel
179 // Ok but undefined behavior (in general, cannot check that incr
180 // is really loop-invariant).
181 #pragma omp for
182 for (ii = 0; ii < 10; ii = ii + ii)
183 c[ii] = a[ii];
185 #pragma omp parallel
186 // expected-error@+2 {{expression must have integral or unscoped enumeration type, not 'float'}}
187 #pragma omp for
188 for (ii = 0; ii < 10; ii = ii + 1.0f)
189 c[ii] = a[ii];
191 #pragma omp parallel
192 // Ok - step was converted to integer type.
193 #pragma omp for
194 for (ii = 0; ii < 10; ii = ii + (int)1.1f)
195 c[ii] = a[ii];
197 #pragma omp parallel
198 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
199 #pragma omp for
200 for (ii = 0; ii < 10; jj = ii + 2)
201 c[ii] = a[ii];
203 #pragma omp parallel
204 // expected-warning@+3 {{relational comparison result unused}}
205 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
206 #pragma omp for
207 for (ii = 0; ii<10; jj> kk + 2)
208 c[ii] = a[ii];
210 #pragma omp parallel
211 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
212 #pragma omp for
213 for (ii = 0; ii < 10;)
214 c[ii] = a[ii];
216 #pragma omp parallel
217 // expected-warning@+3 {{expression result unused}}
218 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
219 #pragma omp for
220 for (ii = 0; ii < 10; !ii)
221 c[ii] = a[ii];
223 #pragma omp parallel
224 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
225 #pragma omp for
226 for (ii = 0; ii < 10; ii ? ++ii : ++jj)
227 c[ii] = a[ii];
229 #pragma omp parallel
230 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
231 #pragma omp for
232 for (ii = 0; ii < 10; ii = ii < 10)
233 c[ii] = a[ii];
235 #pragma omp parallel
236 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
237 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
238 #pragma omp for
239 for (ii = 0; ii < 10; ii = ii + 0)
240 c[ii] = a[ii];
242 #pragma omp parallel
243 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
244 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
245 #pragma omp for
246 for (ii = 0; ii < 10; ii = ii + (int)(0.8 - 0.45))
247 c[ii] = a[ii];
249 #pragma omp parallel
250 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
251 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
252 #pragma omp for
253 for (ii = 0; (ii) < 10; ii -= 25)
254 c[ii] = a[ii];
256 #pragma omp parallel
257 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
258 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
259 #pragma omp for
260 for (ii = 0; (ii < 10); ii -= 0)
261 c[ii] = a[ii];
263 #pragma omp parallel
264 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
265 // expected-error@+2 {{increment expression must cause 'ii' to decrease on each iteration of OpenMP for loop}}
266 #pragma omp for
267 for (ii = 0; ii > 10; (ii += 0))
268 c[ii] = a[ii];
270 #pragma omp parallel
271 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
272 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
273 #pragma omp for
274 for (ii = 0; ii < 10; (ii) = (1 - 1) + (ii))
275 c[ii] = a[ii];
277 #pragma omp parallel
278 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
279 // expected-error@+2 {{increment expression must cause 'ii' to decrease on each iteration of OpenMP for loop}}
280 #pragma omp for
281 for ((ii = 0); ii > 10; (ii -= 0))
282 c[ii] = a[ii];
284 #pragma omp parallel
285 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
286 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
287 #pragma omp for
288 for (ii = 0; (ii < 10); (ii -= 0))
289 c[ii] = a[ii];
291 #pragma omp parallel
292 // expected-error@+3 {{the loop initializer expression depends on the current loop control variable}}
293 // expected-error@+2 2 {{the loop condition expression depends on the current loop control variable}}
294 #pragma omp for
295 for (ii = ii * 10 + 25; ii < ii / ii - 23; ii += 1)
296 c[ii] = a[ii];
298 // expected-error@+3 {{expected loop invariant expression or '<invariant1> * ii + <invariant2>' kind of expression}}
299 #pragma omp for collapse(2)
300 for (ii = 10 + 25; ii < 1000; ii += 1)
301 for (kk = ii * 10 + 25; kk < ii / ii - 23; kk += 1)
304 // expected-error@+4 {{expected loop invariant expression or '<invariant1> * ii + <invariant2>' kind of expression}}
305 #pragma omp for collapse(3)
306 for (ii = 10 + 25; ii < 1000; ii += 1)
307 for (jj = 10 + 25; jj < 1000; jj += 1)
308 for (kk = ii * 10 + 25; kk < jj - 23; kk += 1)
311 #pragma omp parallel
312 // expected-note@+2 {{defined as firstprivate}}
313 // expected-error@+2 {{loop iteration variable in the associated loop of 'omp for' directive may not be firstprivate, predetermined as private}}
314 #pragma omp for firstprivate(ii)
315 for (ii = 0; ii < 10; ii++)
316 c[ii] = a[ii];
318 #pragma omp parallel
319 // expected-note@+2 {{defined as linear}}
320 // expected-error@+2 {{loop iteration variable in the associated loop of 'omp for' directive may not be linear, predetermined as private}}
321 #pragma omp for linear(ii)
322 for (ii = 0; ii < 10; ii++)
323 c[ii] = a[ii];
325 #pragma omp parallel
326 #pragma omp for private(ii)
327 for (ii = 0; ii < 10; ii++)
328 c[ii] = a[ii];
330 #pragma omp parallel
331 #pragma omp for lastprivate(ii)
332 for (ii = 0; ii < 10; ii++)
333 c[ii] = a[ii];
335 #pragma omp parallel
337 // expected-error@+2 {{loop iteration variable in the associated loop of 'omp for' directive may not be threadprivate or thread local, predetermined as private}}
338 #pragma omp for
339 for (sii = 0; sii < 10; sii += 1)
340 c[sii] = a[sii];
343 #pragma omp parallel
345 #pragma omp for
346 for (reg0 = 0; reg0 < 10; reg0 += 1)
347 c[reg0] = a[reg0];
350 #pragma omp parallel
352 #pragma omp for
353 for (reg = 0; reg < 10; reg += 1)
354 c[reg] = a[reg];
357 #pragma omp parallel
359 #pragma omp for
360 for (globalii = 0; globalii < 10; globalii += 1)
361 c[globalii] = a[globalii];
364 #pragma omp parallel
366 #pragma omp for collapse(2)
367 for (ii = 0; ii < 10; ii += 1)
368 for (globalii = 0; globalii < 10; globalii += 1)
369 c[globalii] += a[globalii] + ii;
372 #pragma omp parallel
373 // omp4-error@+2 {{statement after '#pragma omp for' must be a for loop}}
374 #pragma omp for
375 for (auto &item : a) {
376 item = item + 1;
379 #pragma omp parallel
380 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
381 // expected-error@+2 {{increment expression must cause 'i' to increase on each iteration of OpenMP for loop}}
382 #pragma omp for
383 for (unsigned i = 9; i < 10; i--) {
384 c[i] = a[i] + b[i];
387 int(*lb)[4] = nullptr;
388 #pragma omp parallel
389 #pragma omp for
390 for (int(*p)[4] = lb; p < lb + 8; ++p) {
393 #pragma omp parallel
394 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
395 #pragma omp for
396 for (int a{0}; a < 10; ++a) {
399 return 0;
402 // Iterators allowed in openmp for-loops.
403 namespace std {
404 struct random_access_iterator_tag {};
405 template <class Iter>
406 struct iterator_traits {
407 typedef typename Iter::difference_type difference_type;
408 typedef typename Iter::iterator_category iterator_category;
410 template <class Iter>
411 typename iterator_traits<Iter>::difference_type
412 distance(Iter first, Iter last) { return first - last; }
414 class Iter0 {
415 public:
416 Iter0() {}
417 Iter0(const Iter0 &) {}
418 Iter0 operator++() { return *this; }
419 Iter0 operator--() { return *this; }
420 bool operator<(Iter0 a) { return true; }
422 // expected-note@+2 {{candidate function not viable: no known conversion from 'GoodIter' to 'Iter0' for 1st argument}}
423 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'Iter0' for 1st argument}}
424 int operator-(Iter0 a, Iter0 b) { return 0; }
425 class Iter1 {
426 public:
427 Iter1(float f = 0.0f, double d = 0.0) {}
428 Iter1(const Iter1 &) {}
429 Iter1 operator++() { return *this; }
430 Iter1 operator--() { return *this; }
431 bool operator<(Iter1 a) { return true; }
432 bool operator>=(Iter1 a) { return false; }
434 class GoodIter {
435 public:
436 GoodIter() {}
437 GoodIter(const GoodIter &) {}
438 GoodIter(int fst, int snd) {}
439 GoodIter &operator=(const GoodIter &that) { return *this; }
440 GoodIter &operator=(const Iter0 &that) { return *this; }
441 GoodIter &operator+=(int x) { return *this; }
442 GoodIter &operator-=(int x) { return *this; }
443 explicit GoodIter(void *) {}
444 GoodIter operator++() { return *this; }
445 GoodIter operator--() { return *this; }
446 bool operator!() { return true; }
447 bool operator<(GoodIter a) { return true; }
448 bool operator<=(GoodIter a) { return true; }
449 bool operator>=(GoodIter a) { return false; }
450 typedef int difference_type;
451 typedef std::random_access_iterator_tag iterator_category;
453 class GoodIter1 {
454 public:
455 GoodIter1() {}
456 GoodIter1(const GoodIter1 &) {}
457 GoodIter1 &operator++(int) { return *this; }
458 GoodIter1 &operator=(const GoodIter1 &that) { return *this; }
459 GoodIter1 &operator+=(int x) { return *this; }
460 friend long operator-(const GoodIter1 &, const GoodIter1 &);
461 GoodIter1 &operator-(int) { return *this; }
462 bool operator<(GoodIter1 a) { return true; }
463 typedef int difference_type;
464 typedef std::random_access_iterator_tag iterator_category;
466 // expected-note@+2 {{candidate function not viable: no known conversion from 'const Iter0' to 'GoodIter' for 2nd argument}}
467 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}}
468 int operator-(GoodIter a, GoodIter b) { return 0; }
469 // expected-note@+1 3 {{candidate function not viable: requires single argument 'a', but 2 arguments were provided}}
470 GoodIter operator-(GoodIter a) { return a; }
471 // expected-note@+2 {{candidate function not viable: no known conversion from 'const Iter0' to 'int' for 2nd argument}}
472 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}}
473 GoodIter operator-(GoodIter a, int v) { return GoodIter(); }
474 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter0' to 'GoodIter' for 1st argument}}
475 GoodIter operator+(GoodIter a, int v) { return GoodIter(); }
476 // expected-note@+2 {{candidate function not viable: no known conversion from 'GoodIter' to 'int' for 1st argument}}
477 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'int' for 1st argument}}
478 GoodIter operator-(int v, GoodIter a) { return GoodIter(); }
479 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter0' to 'int' for 1st argument}}
480 GoodIter operator+(int v, GoodIter a) { return GoodIter(); }
482 int test_with_random_access_iterator() {
483 GoodIter begin, end;
484 Iter0 begin0, end0;
485 #pragma omp parallel
486 #pragma omp for
487 for (GoodIter I = begin; I < end; ++I)
488 ++I;
489 #pragma omp parallel
490 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
491 #pragma omp for
492 for (GoodIter &I = begin; I < end; ++I)
493 ++I;
494 #pragma omp parallel
495 #pragma omp for
496 for (GoodIter I = begin; I >= end; --I)
497 ++I;
498 #pragma omp parallel
499 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
500 #pragma omp for
501 for (GoodIter I(begin); I < end; ++I)
502 ++I;
503 #pragma omp parallel
504 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
505 #pragma omp for
506 for (GoodIter I(nullptr); I < end; ++I)
507 ++I;
508 #pragma omp parallel
509 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
510 #pragma omp for
511 for (GoodIter I(0); I < end; ++I)
512 ++I;
513 #pragma omp parallel
514 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
515 #pragma omp for
516 for (GoodIter I(1, 2); I < end; ++I)
517 ++I;
518 #pragma omp parallel
519 #pragma omp for
520 for (begin = GoodIter(0); begin < end; ++begin)
521 ++begin;
522 // expected-error@+4 {{invalid operands to binary expression ('GoodIter' and 'const Iter0')}}
523 // expected-error@+3 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}
524 #pragma omp parallel
525 #pragma omp for
526 for (begin = begin0; begin < end; ++begin)
527 ++begin;
528 #pragma omp parallel
529 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
530 #pragma omp for
531 for (++begin; begin < end; ++begin)
532 ++begin;
533 #pragma omp parallel
534 #pragma omp for
535 for (begin = end; begin < end; ++begin)
536 ++begin;
537 #pragma omp parallel
538 // 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'}}
539 #pragma omp for
540 for (GoodIter I = begin; I - I; ++I)
541 ++I;
542 #pragma omp parallel
543 // 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'}}
544 #pragma omp for
545 for (GoodIter I = begin; begin < end; ++I)
546 ++I;
547 #pragma omp parallel
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 for
550 for (GoodIter I = begin; !I; ++I)
551 ++I;
552 #pragma omp parallel
553 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
554 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
555 #pragma omp for
556 for (GoodIter I = begin; I >= end; I = I + 1)
557 ++I;
558 #pragma omp parallel
559 #pragma omp for
560 for (GoodIter I = begin; I >= end; I = I - 1)
561 ++I;
562 #pragma omp parallel
563 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}}
564 #pragma omp for
565 for (GoodIter I = begin; I >= end; I = -I)
566 ++I;
567 #pragma omp parallel
568 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
569 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
570 #pragma omp for
571 for (GoodIter I = begin; I >= end; I = 2 + I)
572 ++I;
573 #pragma omp parallel
574 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}}
575 #pragma omp for
576 for (GoodIter I = begin; I >= end; I = 2 - I)
577 ++I;
578 // In the following example, we cannot update the loop variable using '+='
579 // expected-error@+3 {{invalid operands to binary expression ('Iter0' and 'int')}}
580 #pragma omp parallel
581 #pragma omp for
582 for (Iter0 I = begin0; I < end0; ++I)
583 ++I;
584 #pragma omp parallel
585 // Initializer is constructor without params.
586 // expected-error@+3 {{invalid operands to binary expression ('Iter0' and 'int')}}
587 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
588 #pragma omp for
589 for (Iter0 I; I < end0; ++I)
590 ++I;
591 Iter1 begin1, end1;
592 // expected-error@+4 {{invalid operands to binary expression ('Iter1' and 'Iter1')}}
593 // expected-error@+3 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}
594 #pragma omp parallel
595 #pragma omp for
596 for (Iter1 I = begin1; I < end1; ++I)
597 ++I;
598 #pragma omp parallel
599 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
600 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
601 #pragma omp for
602 for (Iter1 I = begin1; I >= end1; ++I)
603 ++I;
604 #pragma omp parallel
605 // expected-error@+5 {{invalid operands to binary expression ('Iter1' and 'float')}}
606 // expected-error@+4 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}
607 // Initializer is constructor with all default params.
608 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
609 #pragma omp for
610 for (Iter1 I; I < end1; ++I) {
612 GoodIter1 I1, E1;
613 // expected-error@+4 {{expected an integer or a pointer type of the outer loop counter 'I' for non-rectangular nests}}
614 // expected-error@+4 {{expected an integer or a pointer type of the outer loop counter 'I' for non-rectangular nests}}
615 #pragma omp for collapse(3)
616 for (GoodIter1 I = I1; I < E1; I++) // expected-note 2 {{'I' declared here}}
617 for (int i = (I - I1) * 10 + 25; i < 23; i += 1)
618 for (int j = 10 + 25; j < 23 + (I - E1); j += 1)
621 #pragma omp for
622 for (GoodIter1 I = I1; I < E1; I++)
624 return 0;
627 template <typename IT, int ST>
628 class TC {
629 int ii, iii, kk;
630 public:
631 enum { myconstant = 42 };
632 int ub();
633 int dotest_lt(IT begin, IT end) {
634 #pragma omp parallel
635 // expected-error@+3 3 {{the loop initializer expression depends on the current loop control variable}}
636 // expected-error@+2 6 {{the loop condition expression depends on the current loop control variable}}
637 #pragma omp for
638 for (ii = ii * 10 + 25; ii < ii / ii - 23; ii += 1)
641 // Check that member function calls and enum constants in the condition is
642 // handled.
643 #pragma omp for
644 for (ii = 0; ii < ub() + this->myconstant; ii += 1) // expected-no-error
647 #pragma omp parallel
648 // expected-error@+4 2 {{expected loop invariant expression or '<invariant1> * ii + <invariant2>' kind of expression}}
649 // expected-error@+3 {{expected loop invariant expression or '<invariant1> * TC::ii + <invariant2>' kind of expression}}
650 #pragma omp for collapse(2)
651 for (ii = 10 + 25; ii < 1000; ii += 1)
652 for (iii = ii * 10 + 25; iii < ii / ii - 23; iii += 1)
655 #pragma omp parallel
656 // expected-error@+6 {{expected loop invariant expression or '<invariant1> * TC::ii + <invariant2>' kind of expression}}
657 // expected-error@+6 {{expected loop invariant expression or '<invariant1> * TC::ii + <invariant2>' kind of expression}}
658 // expected-error@+4 2 {{expected loop invariant expression or '<invariant1> * ii + <invariant2>' kind of expression}}
659 // expected-error@+4 2 {{expected loop invariant expression or '<invariant1> * ii + <invariant2>' kind of expression}}
660 #pragma omp for collapse(3)
661 for (ii = 10 + 25; ii < 1000; ii += 1)
662 for (iii = ii * 10 + 25; iii < ii / ii - 23; iii += 1)
663 for (kk = ii * 10 + 25; kk < iii - 23; kk += 1)
666 #pragma omp parallel
667 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
668 // expected-error@+2 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}}
669 #pragma omp for
670 for (IT I = begin; I < end; I = I + ST) {
671 ++I;
673 #pragma omp parallel
674 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
675 // expected-error@+2 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}}
676 #pragma omp for
677 for (IT I = begin; I <= end; I += ST) {
678 ++I;
680 #pragma omp parallel
681 #pragma omp for
682 for (IT I = begin; I < end; ++I) {
683 ++I;
687 static IT step() {
688 return IT(ST);
691 template <typename IT, int ST = 0>
692 int dotest_gt(IT begin, IT end) {
693 #pragma omp parallel
694 // expected-note@+3 2 {{loop step is expected to be negative due to this condition}}
695 // expected-error@+2 2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
696 #pragma omp for
697 for (IT I = begin; I >= end; I = I + ST) {
698 ++I;
700 #pragma omp parallel
701 // expected-note@+3 2 {{loop step is expected to be negative due to this condition}}
702 // expected-error@+2 2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
703 #pragma omp for
704 for (IT I = begin; I >= end; I += ST) {
705 ++I;
708 #pragma omp parallel
709 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
710 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
711 #pragma omp for
712 for (IT I = begin; I >= end; ++I) {
713 ++I;
716 #pragma omp parallel
717 #pragma omp for
718 for (IT I = begin; I < end; I += TC<int, ST>::step()) {
719 ++I;
723 void test_with_template() {
724 GoodIter begin, end;
725 TC<GoodIter, 100> t1;
726 TC<GoodIter, -100> t2;
727 t1.dotest_lt(begin, end); // expected-note {{in instantiation of member function 'TC<GoodIter, 100>::dotest_lt' requested here}}
728 t2.dotest_lt(begin, end); // expected-note {{in instantiation of member function 'TC<GoodIter, -100>::dotest_lt' requested here}}
729 dotest_gt(begin, end); // expected-note {{in instantiation of function template specialization 'dotest_gt<GoodIter, 0>' requested here}}
730 dotest_gt<unsigned, 10>(0, 100); // expected-note {{in instantiation of function template specialization 'dotest_gt<unsigned int, 10>' requested here}}
733 void test_loop_break() {
734 const int N = 100;
735 float a[N], b[N], c[N];
736 #pragma omp parallel
737 #pragma omp for
738 for (int i = 0; i < 10; i++) {
739 c[i] = a[i] + b[i];
740 for (int j = 0; j < 10; ++j) {
741 if (a[i] > b[j])
742 break; // OK in nested loop
744 switch (i) {
745 case 1:
746 b[i]++;
747 break;
748 default:
749 break;
751 if (c[i] > 10)
752 break; // expected-error {{'break' statement cannot be used in OpenMP for loop}}
754 if (c[i] > 11)
755 break; // expected-error {{'break' statement cannot be used in OpenMP for loop}}
758 #pragma omp parallel
759 #pragma omp for
760 for (int i = 0; i < 10; i++) {
761 for (int j = 0; j < 10; j++) {
762 c[i] = a[i] + b[i];
763 if (c[i] > 10) {
764 if (c[i] < 20) {
765 break; // OK
772 void test_loop_eh() {
773 const int N = 100;
774 float a[N], b[N], c[N];
775 #pragma omp parallel
776 #pragma omp for
777 for (int i = 0; i < 10; i++) {
778 c[i] = a[i] + b[i];
779 try {
780 for (int j = 0; j < 10; ++j) {
781 if (a[i] > b[j])
782 throw a[i];
784 throw a[i];
785 } catch (float f) {
786 if (f > 0.1)
787 throw a[i];
788 return; // expected-error {{cannot return from OpenMP region}}
790 switch (i) {
791 case 1:
792 b[i]++;
793 break;
794 default:
795 break;
797 for (int j = 0; j < 10; j++) {
798 if (c[i] > 10)
799 throw c[i];
802 if (c[9] > 10)
803 throw c[9]; // OK
805 #pragma omp parallel
806 #pragma omp for
807 for (int i = 0; i < 10; ++i) {
808 struct S {
809 void g() { throw 0; }
814 void test_loop_firstprivate_lastprivate() {
815 S s(4);
816 #pragma omp parallel
817 #pragma omp for lastprivate(s) firstprivate(s)
818 for (int i = 0; i < 16; ++i)
822 void test_ordered() {
823 #pragma omp parallel
824 #pragma omp for ordered ordered // expected-error {{directive '#pragma omp for' cannot contain more than one 'ordered' clause}}
825 for (int i = 0; i < 16; ++i)
829 void test_nowait() {
830 #pragma omp parallel
831 #pragma omp for nowait nowait // expected-error {{directive '#pragma omp for' cannot contain more than one 'nowait' clause}}
832 for (int i = 0; i < 16; ++i)
836 void test_static_data_member() {
837 #pragma omp parallel
838 #pragma omp for
839 for (int i = 0; i < 16; ++i) {
840 class X {
841 static int x; // expected-error {{static data member 'x' not allowed in local class 'X'}}