Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / masked_taskloop_simd_loop_messages.cpp
blob8f1bc37ac65690848efaabc649082745b694c53e
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 int tid = 0;
32 register int reg; // expected-warning {{'register' storage class specifier is deprecated}}
33 #pragma omp parallel
34 #pragma omp masked taskloop simd filter(tid)
35 for (int i = 0; i < 10; i += 1) {
36 c[i] = a[i] + b[i];
38 #pragma omp parallel
39 #pragma omp masked taskloop simd
40 for (char i = 0; i < 10; i++) {
41 c[i] = a[i] + b[i];
43 #pragma omp parallel
44 #pragma omp masked taskloop simd
45 for (char i = 0; i < 10; i += '\1') {
46 c[i] = a[i] + b[i];
48 #pragma omp parallel
49 #pragma omp masked taskloop simd
50 for (long long i = 0; i < 10; i++) {
51 c[i] = a[i] + b[i];
53 #pragma omp parallel
54 // expected-error@+2 {{expression must have integral or unscoped enumeration type, not 'double'}}
55 #pragma omp masked taskloop simd
56 for (long long i = 0; i < 10; i += 1.5) {
57 c[i] = a[i] + b[i];
59 #pragma omp parallel
60 #pragma omp masked taskloop simd
61 for (long long i = 0; i < 'z'; i += 1u) {
62 c[i] = a[i] + b[i];
64 #pragma omp parallel
65 // expected-error@+2 {{variable must be of integer or random access iterator type}}
66 #pragma omp masked taskloop simd
67 for (float fi = 0; fi < 10.0; fi++) {
68 c[(int)fi] = a[(int)fi] + b[(int)fi];
70 #pragma omp parallel
71 // expected-error@+2 {{variable must be of integer or random access iterator type}}
72 #pragma omp masked taskloop simd
73 for (double fi = 0; fi < 10.0; fi++) {
74 c[(int)fi] = a[(int)fi] + b[(int)fi];
76 #pragma omp parallel
77 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
78 #pragma omp masked taskloop simd
79 for (int &ref = ii; ref < 10; ref++) {
81 #pragma omp parallel
82 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
83 #pragma omp masked taskloop simd
84 for (int i; i < 10; i++)
85 c[i] = a[i];
87 #pragma omp parallel
88 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
89 #pragma omp masked taskloop simd
90 for (int i = 0, j = 0; i < 10; ++i)
91 c[i] = a[i];
93 #pragma omp parallel
94 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
95 #pragma omp masked taskloop simd
96 for (; ii < 10; ++ii)
97 c[ii] = a[ii];
99 #pragma omp parallel
100 // expected-warning@+3 {{expression result unused}}
101 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
102 #pragma omp masked taskloop simd
103 for (ii + 1; ii < 10; ++ii)
104 c[ii] = a[ii];
106 #pragma omp parallel
107 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
108 #pragma omp masked taskloop simd
109 for (c[ii] = 0; ii < 10; ++ii)
110 c[ii] = a[ii];
112 #pragma omp parallel
113 // Ok to skip parenthesises.
114 #pragma omp masked taskloop simd
115 for (((ii)) = 0; ii < 10; ++ii)
116 c[ii] = a[ii];
118 #pragma omp parallel
119 // 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'}}
120 #pragma omp masked taskloop simd
121 for (int i = 0; i; i++)
122 c[i] = a[i];
124 #pragma omp parallel
125 // 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'}}
126 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'i'}}
127 #pragma omp masked taskloop simd
128 for (int i = 0; jj < kk; ii++)
129 c[i] = a[i];
131 #pragma omp parallel
132 // 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'}}
133 #pragma omp masked taskloop simd
134 for (int i = 0; !!i; i++)
135 c[i] = a[i];
137 #pragma omp parallel
138 // omp4-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}}
139 #pragma omp masked taskloop simd
140 for (int i = 0; i != 1; i++)
141 c[i] = a[i];
143 #pragma omp parallel
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 masked taskloop simd
146 for (int i = 0;; i++)
147 c[i] = a[i];
149 #pragma omp parallel
150 // Ok.
151 #pragma omp masked taskloop simd
152 for (int i = 11; i > 10; i--)
153 c[i] = a[i];
155 #pragma omp parallel
156 // Ok.
157 #pragma omp masked taskloop simd
158 for (int i = 0; i < 10; ++i)
159 c[i] = a[i];
161 #pragma omp parallel
162 // Ok.
163 #pragma omp masked taskloop simd
164 for (ii = 0; ii < 10; ++ii)
165 c[ii] = a[ii];
167 #pragma omp parallel
168 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
169 #pragma omp masked taskloop simd
170 for (ii = 0; ii < 10; ++jj)
171 c[ii] = a[jj];
173 #pragma omp parallel
174 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
175 #pragma omp masked taskloop simd
176 for (ii = 0; ii < 10; ++++ii)
177 c[ii] = a[ii];
179 #pragma omp parallel
180 // Ok but undefined behavior (in general, cannot check that incr
181 // is really loop-invariant).
182 #pragma omp masked taskloop simd
183 for (ii = 0; ii < 10; ii = ii + ii)
184 c[ii] = a[ii];
186 #pragma omp parallel
187 // expected-error@+2 {{expression must have integral or unscoped enumeration type, not 'float'}}
188 #pragma omp masked taskloop simd
189 for (ii = 0; ii < 10; ii = ii + 1.0f)
190 c[ii] = a[ii];
192 #pragma omp parallel
193 // Ok - step was converted to integer type.
194 #pragma omp masked taskloop simd
195 for (ii = 0; ii < 10; ii = ii + (int)1.1f)
196 c[ii] = a[ii];
198 #pragma omp parallel
199 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
200 #pragma omp masked taskloop simd
201 for (ii = 0; ii < 10; jj = ii + 2)
202 c[ii] = a[ii];
204 #pragma omp parallel
205 // expected-warning@+3 {{relational comparison result unused}}
206 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
207 #pragma omp masked taskloop simd
208 for (ii = 0; ii<10; jj> kk + 2)
209 c[ii] = a[ii];
211 #pragma omp parallel
212 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
213 #pragma omp masked taskloop simd
214 for (ii = 0; ii < 10;)
215 c[ii] = a[ii];
217 #pragma omp parallel
218 // expected-warning@+3 {{expression result unused}}
219 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
220 #pragma omp masked taskloop simd
221 for (ii = 0; ii < 10; !ii)
222 c[ii] = a[ii];
224 #pragma omp parallel
225 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
226 #pragma omp masked taskloop simd
227 for (ii = 0; ii < 10; ii ? ++ii : ++jj)
228 c[ii] = a[ii];
230 #pragma omp parallel
231 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
232 #pragma omp masked taskloop simd
233 for (ii = 0; ii < 10; ii = ii < 10)
234 c[ii] = a[ii];
236 #pragma omp parallel
237 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
238 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
239 #pragma omp masked taskloop simd
240 for (ii = 0; ii < 10; ii = ii + 0)
241 c[ii] = a[ii];
243 #pragma omp parallel
244 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
245 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
246 #pragma omp masked taskloop simd
247 for (ii = 0; ii < 10; ii = ii + (int)(0.8 - 0.45))
248 c[ii] = a[ii];
250 #pragma omp parallel
251 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
252 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
253 #pragma omp masked taskloop simd
254 for (ii = 0; (ii) < 10; ii -= 25)
255 c[ii] = a[ii];
257 #pragma omp parallel
258 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
259 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
260 #pragma omp masked taskloop simd
261 for (ii = 0; (ii < 10); ii -= 0)
262 c[ii] = a[ii];
264 #pragma omp parallel
265 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
266 // expected-error@+2 {{increment expression must cause 'ii' to decrease on each iteration of OpenMP for loop}}
267 #pragma omp masked taskloop simd
268 for (ii = 0; ii > 10; (ii += 0))
269 c[ii] = a[ii];
271 #pragma omp parallel
272 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
273 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
274 #pragma omp masked taskloop simd
275 for (ii = 0; ii < 10; (ii) = (1 - 1) + (ii))
276 c[ii] = a[ii];
278 #pragma omp parallel
279 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
280 // expected-error@+2 {{increment expression must cause 'ii' to decrease on each iteration of OpenMP for loop}}
281 #pragma omp masked taskloop simd
282 for ((ii = 0); ii > 10; (ii -= 0))
283 c[ii] = a[ii];
285 #pragma omp parallel
286 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
287 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
288 #pragma omp masked taskloop simd
289 for (ii = 0; (ii < 10); (ii -= 0))
290 c[ii] = a[ii];
292 #pragma omp parallel
293 // expected-note@+2 {{defined as firstprivate}}
294 // expected-error@+2 {{loop iteration variable in the associated loop of 'omp masked taskloop simd' directive may not be firstprivate, predetermined as linear}}
295 #pragma omp masked taskloop simd firstprivate(ii)
296 for (ii = 0; ii < 10; ii++)
297 c[ii] = a[ii];
299 #pragma omp parallel
300 #pragma omp masked taskloop simd linear(ii)
301 for (ii = 0; ii < 10; ii++)
302 c[ii] = a[ii];
304 // omp4-note@+3 {{defined as private}}
305 // omp4-error@+3 {{loop iteration variable in the associated loop of 'omp masked taskloop simd' directive may not be private, predetermined as linear}}
306 #pragma omp parallel
307 #pragma omp masked taskloop simd private(ii)
308 for (ii = 0; ii < 10; ii++)
309 c[ii] = a[ii];
311 // omp4-note@+3 {{defined as lastprivate}}
312 // omp4-error@+3 {{loop iteration variable in the associated loop of 'omp masked taskloop simd' directive may not be lastprivate, predetermined as linear}}
313 #pragma omp parallel
314 #pragma omp masked taskloop simd lastprivate(ii)
315 for (ii = 0; ii < 10; ii++)
316 c[ii] = a[ii];
318 #pragma omp parallel
320 // expected-error@+2 {{loop iteration variable in the associated loop of 'omp masked taskloop simd' directive may not be threadprivate or thread local, predetermined as linear}}
321 #pragma omp masked taskloop simd
322 for (sii = 0; sii < 10; sii += 1)
323 c[sii] = a[sii];
326 #pragma omp parallel
328 #pragma omp masked taskloop simd
329 for (reg0 = 0; reg0 < 10; reg0 += 1)
330 c[reg0] = a[reg0];
333 #pragma omp parallel
335 #pragma omp masked taskloop simd
336 for (reg = 0; reg < 10; reg += 1)
337 c[reg] = a[reg];
340 #pragma omp parallel
342 #pragma omp masked taskloop simd
343 for (globalii = 0; globalii < 10; globalii += 1)
344 c[globalii] = a[globalii];
347 #pragma omp parallel
349 #pragma omp masked taskloop simd collapse(2)
350 for (ii = 0; ii < 10; ii += 1)
351 for (globalii = 0; globalii < 10; globalii += 1)
352 c[globalii] += a[globalii] + ii;
355 #pragma omp parallel
356 // omp4-error@+2 {{statement after '#pragma omp masked taskloop simd' must be a for loop}}
357 #pragma omp masked taskloop simd
358 for (auto &item : a) {
359 item = item + 1;
362 #pragma omp parallel
363 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
364 // expected-error@+2 {{increment expression must cause 'i' to increase on each iteration of OpenMP for loop}}
365 #pragma omp masked taskloop simd
366 for (unsigned i = 9; i < 10; i--) {
367 c[i] = a[i] + b[i];
370 int(*lb)[4] = nullptr;
371 #pragma omp parallel
372 #pragma omp masked taskloop simd
373 for (int(*p)[4] = lb; p < lb + 8; ++p) {
376 #pragma omp parallel
377 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
378 #pragma omp masked taskloop simd
379 for (int a{0}; a < 10; ++a) {
382 return 0;
385 // Iterators allowed in openmp for-loops.
386 namespace std {
387 struct random_access_iterator_tag {};
388 template <class Iter>
389 struct iterator_traits {
390 typedef typename Iter::difference_type difference_type;
391 typedef typename Iter::iterator_category iterator_category;
393 template <class Iter>
394 typename iterator_traits<Iter>::difference_type
395 distance(Iter first, Iter last) { return first - last; }
397 class Iter0 {
398 public:
399 Iter0() {}
400 Iter0(const Iter0 &) {}
401 Iter0 operator++() { return *this; }
402 Iter0 operator--() { return *this; }
403 bool operator<(Iter0 a) { return true; }
405 // expected-note@+2 {{candidate function not viable: no known conversion from 'GoodIter' to 'Iter0' for 1st argument}}
406 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'Iter0' for 1st argument}}
407 int operator-(Iter0 a, Iter0 b) { return 0; }
408 class Iter1 {
409 public:
410 Iter1(float f = 0.0f, double d = 0.0) {}
411 Iter1(const Iter1 &) {}
412 Iter1 operator++() { return *this; }
413 Iter1 operator--() { return *this; }
414 bool operator<(Iter1 a) { return true; }
415 bool operator>=(Iter1 a) { return false; }
417 class GoodIter {
418 public:
419 GoodIter() {}
420 GoodIter(const GoodIter &) {}
421 GoodIter(int fst, int snd) {}
422 GoodIter &operator=(const GoodIter &that) { return *this; }
423 GoodIter &operator=(const Iter0 &that) { return *this; }
424 GoodIter &operator+=(int x) { return *this; }
425 GoodIter &operator-=(int x) { return *this; }
426 explicit GoodIter(void *) {}
427 GoodIter operator++() { return *this; }
428 GoodIter operator--() { return *this; }
429 bool operator!() { return true; }
430 bool operator<(GoodIter a) { return true; }
431 bool operator<=(GoodIter a) { return true; }
432 bool operator>=(GoodIter a) { return false; }
433 typedef int difference_type;
434 typedef std::random_access_iterator_tag iterator_category;
436 // expected-note@+2 {{candidate function not viable: no known conversion from 'const Iter0' to 'GoodIter' for 2nd argument}}
437 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}}
438 int operator-(GoodIter a, GoodIter b) { return 0; }
439 // expected-note@+1 3 {{candidate function not viable: requires single argument 'a', but 2 arguments were provided}}
440 GoodIter operator-(GoodIter a) { return a; }
441 // expected-note@+2 {{candidate function not viable: no known conversion from 'const Iter0' to 'int' for 2nd argument}}
442 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}}
443 GoodIter operator-(GoodIter a, int v) { return GoodIter(); }
444 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter0' to 'GoodIter' for 1st argument}}
445 GoodIter operator+(GoodIter a, int v) { return GoodIter(); }
446 // expected-note@+2 {{candidate function not viable: no known conversion from 'GoodIter' to 'int' for 1st argument}}
447 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'int' for 1st argument}}
448 GoodIter operator-(int v, GoodIter a) { return GoodIter(); }
449 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter0' to 'int' for 1st argument}}
450 GoodIter operator+(int v, GoodIter a) { return GoodIter(); }
452 int test_with_random_access_iterator() {
453 GoodIter begin, end;
454 Iter0 begin0, end0;
455 #pragma omp parallel
456 #pragma omp masked taskloop simd
457 for (GoodIter I = begin; I < end; ++I)
458 ++I;
459 #pragma omp parallel
460 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
461 #pragma omp masked taskloop simd
462 for (GoodIter &I = begin; I < end; ++I)
463 ++I;
464 #pragma omp parallel
465 #pragma omp masked taskloop simd
466 for (GoodIter I = begin; I >= end; --I)
467 ++I;
468 #pragma omp parallel
469 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
470 #pragma omp masked taskloop simd
471 for (GoodIter I(begin); I < end; ++I)
472 ++I;
473 #pragma omp parallel
474 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
475 #pragma omp masked taskloop simd
476 for (GoodIter I(nullptr); I < end; ++I)
477 ++I;
478 #pragma omp parallel
479 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
480 #pragma omp masked taskloop simd
481 for (GoodIter I(0); I < end; ++I)
482 ++I;
483 #pragma omp parallel
484 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
485 #pragma omp masked taskloop simd
486 for (GoodIter I(1, 2); I < end; ++I)
487 ++I;
488 #pragma omp parallel
489 #pragma omp masked taskloop simd
490 for (begin = GoodIter(0); begin < end; ++begin)
491 ++begin;
492 // expected-error@+4 {{invalid operands to binary expression ('GoodIter' and 'const Iter0')}}
493 // expected-error@+3 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}
494 #pragma omp parallel
495 #pragma omp masked taskloop simd
496 for (begin = begin0; begin < end; ++begin)
497 ++begin;
498 #pragma omp parallel
499 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
500 #pragma omp masked taskloop simd
501 for (++begin; begin < end; ++begin)
502 ++begin;
503 #pragma omp parallel
504 #pragma omp masked taskloop simd
505 for (begin = end; begin < end; ++begin)
506 ++begin;
507 #pragma omp parallel
508 // 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'}}
509 #pragma omp masked taskloop simd
510 for (GoodIter I = begin; I - I; ++I)
511 ++I;
512 #pragma omp parallel
513 // 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'}}
514 #pragma omp masked taskloop simd
515 for (GoodIter I = begin; begin < end; ++I)
516 ++I;
517 #pragma omp parallel
518 // 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'}}
519 #pragma omp masked taskloop simd
520 for (GoodIter I = begin; !I; ++I)
521 ++I;
522 #pragma omp parallel
523 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
524 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
525 #pragma omp masked taskloop simd
526 for (GoodIter I = begin; I >= end; I = I + 1)
527 ++I;
528 #pragma omp parallel
529 #pragma omp masked taskloop simd
530 for (GoodIter I = begin; I >= end; I = I - 1)
531 ++I;
532 #pragma omp parallel
533 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}}
534 #pragma omp masked taskloop simd
535 for (GoodIter I = begin; I >= end; I = -I)
536 ++I;
537 #pragma omp parallel
538 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
539 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
540 #pragma omp masked taskloop simd
541 for (GoodIter I = begin; I >= end; I = 2 + I)
542 ++I;
543 #pragma omp parallel
544 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}}
545 #pragma omp masked taskloop simd
546 for (GoodIter I = begin; I >= end; I = 2 - I)
547 ++I;
548 // In the following example, we cannot update the loop variable using '+='
549 // expected-error@+3 {{invalid operands to binary expression ('Iter0' and 'int')}}
550 #pragma omp parallel
551 #pragma omp masked taskloop simd
552 for (Iter0 I = begin0; I < end0; ++I)
553 ++I;
554 #pragma omp parallel
555 // Initializer is constructor without params.
556 // expected-error@+3 {{invalid operands to binary expression ('Iter0' and 'int')}}
557 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
558 #pragma omp masked taskloop simd
559 for (Iter0 I; I < end0; ++I)
560 ++I;
561 Iter1 begin1, end1;
562 // expected-error@+4 {{invalid operands to binary expression ('Iter1' and 'Iter1')}}
563 // expected-error@+3 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}
564 #pragma omp parallel
565 #pragma omp masked taskloop simd
566 for (Iter1 I = begin1; I < end1; ++I)
567 ++I;
568 #pragma omp parallel
569 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
570 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
571 #pragma omp masked taskloop simd
572 for (Iter1 I = begin1; I >= end1; ++I)
573 ++I;
574 #pragma omp parallel
575 // expected-error@+5 {{invalid operands to binary expression ('Iter1' and 'float')}}
576 // expected-error@+4 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}
577 // Initializer is constructor with all default params.
578 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
579 #pragma omp masked taskloop simd
580 for (Iter1 I; I < end1; ++I) {
582 return 0;
585 template <typename IT, int ST>
586 class TC {
587 public:
588 int dotest_lt(IT begin, IT end) {
589 #pragma omp parallel
590 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
591 // expected-error@+2 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}}
592 #pragma omp masked taskloop simd
593 for (IT I = begin; I < end; I = I + ST) {
594 ++I;
596 #pragma omp parallel
597 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
598 // expected-error@+2 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}}
599 #pragma omp masked taskloop simd
600 for (IT I = begin; I <= end; I += ST) {
601 ++I;
603 #pragma omp parallel
604 #pragma omp masked taskloop simd
605 for (IT I = begin; I < end; ++I) {
606 ++I;
610 static IT step() {
611 return IT(ST);
614 template <typename IT, int ST = 0>
615 int dotest_gt(IT begin, IT end) {
616 #pragma omp parallel
617 // expected-note@+3 2 {{loop step is expected to be negative due to this condition}}
618 // expected-error@+2 2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
619 #pragma omp masked taskloop simd
620 for (IT I = begin; I >= end; I = I + ST) {
621 ++I;
623 #pragma omp parallel
624 // expected-note@+3 2 {{loop step is expected to be negative due to this condition}}
625 // expected-error@+2 2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
626 #pragma omp masked taskloop simd
627 for (IT I = begin; I >= end; I += ST) {
628 ++I;
631 #pragma omp parallel
632 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
633 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
634 #pragma omp masked taskloop simd
635 for (IT I = begin; I >= end; ++I) {
636 ++I;
639 #pragma omp parallel
640 #pragma omp masked taskloop simd
641 for (IT I = begin; I < end; I += TC<int, ST>::step()) {
642 ++I;
646 void test_with_template() {
647 GoodIter begin, end;
648 TC<GoodIter, 100> t1;
649 TC<GoodIter, -100> t2;
650 t1.dotest_lt(begin, end);
651 t2.dotest_lt(begin, end); // expected-note {{in instantiation of member function 'TC<GoodIter, -100>::dotest_lt' requested here}}
652 dotest_gt(begin, end); // expected-note {{in instantiation of function template specialization 'dotest_gt<GoodIter, 0>' requested here}}
653 dotest_gt<unsigned, 10>(0, 100); // expected-note {{in instantiation of function template specialization 'dotest_gt<unsigned int, 10>' requested here}}
656 void test_loop_break() {
657 const int N = 100;
658 float a[N], b[N], c[N];
659 #pragma omp parallel
660 #pragma omp masked taskloop simd
661 for (int i = 0; i < 10; i++) {
662 c[i] = a[i] + b[i];
663 for (int j = 0; j < 10; ++j) {
664 if (a[i] > b[j])
665 break; // OK in nested loop
667 switch (i) {
668 case 1:
669 b[i]++;
670 break;
671 default:
672 break;
674 if (c[i] > 10)
675 break; // expected-error {{'break' statement cannot be used in OpenMP for loop}}
677 if (c[i] > 11)
678 break; // expected-error {{'break' statement cannot be used in OpenMP for loop}}
681 #pragma omp parallel
682 #pragma omp masked taskloop simd
683 for (int i = 0; i < 10; i++) {
684 for (int j = 0; j < 10; j++) {
685 c[i] = a[i] + b[i];
686 if (c[i] > 10) {
687 if (c[i] < 20) {
688 break; // OK
695 void test_loop_eh() {
696 const int N = 100;
697 float a[N], b[N], c[N];
698 #pragma omp parallel
699 #pragma omp masked taskloop simd
700 for (int i = 0; i < 10; i++) {
701 c[i] = a[i] + b[i];
702 try { // expected-error {{'try' statement cannot be used in OpenMP simd region}}
703 for (int j = 0; j < 10; ++j) {
704 if (a[i] > b[j])
705 throw a[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
707 throw a[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
708 } catch (float f) {
709 if (f > 0.1)
710 throw a[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
711 return; // expected-error {{cannot return from OpenMP region}}
713 switch (i) {
714 case 1:
715 b[i]++;
716 break;
717 default:
718 break;
720 for (int j = 0; j < 10; j++) {
721 if (c[i] > 10)
722 throw c[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
725 if (c[9] > 10)
726 throw c[9]; // OK
728 #pragma omp parallel
729 #pragma omp masked taskloop simd
730 for (int i = 0; i < 10; ++i) {
731 struct S {
732 void g() { throw 0; }
737 void test_loop_firstprivate_lastprivate() {
738 S s(4);
739 #pragma omp parallel
740 #pragma omp masked taskloop simd lastprivate(s) firstprivate(s)
741 for (int i = 0; i < 16; ++i)