[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / OpenMP / master_taskloop_simd_loop_messages.cpp
blob0f4f424c87af2640e4b32cf4fe8aed815d313f61
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 master taskloop simd
34 for (int i = 0; i < 10; i += 1) {
35 c[i] = a[i] + b[i];
37 #pragma omp parallel
38 #pragma omp master taskloop simd
39 for (char i = 0; i < 10; i++) {
40 c[i] = a[i] + b[i];
42 #pragma omp parallel
43 #pragma omp master taskloop simd
44 for (char i = 0; i < 10; i += '\1') {
45 c[i] = a[i] + b[i];
47 #pragma omp parallel
48 #pragma omp master taskloop simd
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 master taskloop simd
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 master taskloop simd
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 master taskloop simd
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 master taskloop simd
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 master taskloop simd
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 master taskloop simd
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 master taskloop simd
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 master taskloop simd
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 master taskloop simd
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 master taskloop simd
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 master taskloop simd
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 master taskloop simd
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 master taskloop simd
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 master taskloop simd
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 master taskloop simd
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 master taskloop simd
145 for (int i = 0;; i++)
146 c[i] = a[i];
148 #pragma omp parallel
149 // Ok.
150 #pragma omp master taskloop simd
151 for (int i = 11; i > 10; i--)
152 c[i] = a[i];
154 #pragma omp parallel
155 // Ok.
156 #pragma omp master taskloop simd
157 for (int i = 0; i < 10; ++i)
158 c[i] = a[i];
160 #pragma omp parallel
161 // Ok.
162 #pragma omp master taskloop simd
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 master taskloop simd
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 master taskloop simd
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 master taskloop simd
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 master taskloop simd
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 master taskloop simd
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 master taskloop simd
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 master taskloop simd
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 master taskloop simd
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 master taskloop simd
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 master taskloop simd
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 master taskloop simd
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 master taskloop simd
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 master taskloop simd
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 master taskloop simd
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 master taskloop simd
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 master taskloop simd
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 master taskloop simd
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 master taskloop simd
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 master taskloop simd
288 for (ii = 0; (ii < 10); (ii -= 0))
289 c[ii] = a[ii];
291 #pragma omp parallel
292 // expected-note@+2 {{defined as firstprivate}}
293 // expected-error@+2 {{loop iteration variable in the associated loop of 'omp master taskloop simd' directive may not be firstprivate, predetermined as linear}}
294 #pragma omp master taskloop simd firstprivate(ii)
295 for (ii = 0; ii < 10; ii++)
296 c[ii] = a[ii];
298 #pragma omp parallel
299 #pragma omp master taskloop simd linear(ii)
300 for (ii = 0; ii < 10; ii++)
301 c[ii] = a[ii];
303 // omp4-note@+3 {{defined as private}}
304 // omp4-error@+3 {{loop iteration variable in the associated loop of 'omp master taskloop simd' directive may not be private, predetermined as linear}}
305 #pragma omp parallel
306 #pragma omp master taskloop simd private(ii)
307 for (ii = 0; ii < 10; ii++)
308 c[ii] = a[ii];
310 // omp4-note@+3 {{defined as lastprivate}}
311 // omp4-error@+3 {{loop iteration variable in the associated loop of 'omp master taskloop simd' directive may not be lastprivate, predetermined as linear}}
312 #pragma omp parallel
313 #pragma omp master taskloop simd lastprivate(ii)
314 for (ii = 0; ii < 10; ii++)
315 c[ii] = a[ii];
317 #pragma omp parallel
319 // expected-error@+2 {{loop iteration variable in the associated loop of 'omp master taskloop simd' directive may not be threadprivate or thread local, predetermined as linear}}
320 #pragma omp master taskloop simd
321 for (sii = 0; sii < 10; sii += 1)
322 c[sii] = a[sii];
325 #pragma omp parallel
327 #pragma omp master taskloop simd
328 for (reg0 = 0; reg0 < 10; reg0 += 1)
329 c[reg0] = a[reg0];
332 #pragma omp parallel
334 #pragma omp master taskloop simd
335 for (reg = 0; reg < 10; reg += 1)
336 c[reg] = a[reg];
339 #pragma omp parallel
341 #pragma omp master taskloop simd
342 for (globalii = 0; globalii < 10; globalii += 1)
343 c[globalii] = a[globalii];
346 #pragma omp parallel
348 #pragma omp master taskloop simd collapse(2)
349 for (ii = 0; ii < 10; ii += 1)
350 for (globalii = 0; globalii < 10; globalii += 1)
351 c[globalii] += a[globalii] + ii;
354 #pragma omp parallel
355 // omp4-error@+2 {{statement after '#pragma omp master taskloop simd' must be a for loop}}
356 #pragma omp master taskloop simd
357 for (auto &item : a) {
358 item = item + 1;
361 #pragma omp parallel
362 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
363 // expected-error@+2 {{increment expression must cause 'i' to increase on each iteration of OpenMP for loop}}
364 #pragma omp master taskloop simd
365 for (unsigned i = 9; i < 10; i--) {
366 c[i] = a[i] + b[i];
369 int(*lb)[4] = nullptr;
370 #pragma omp parallel
371 #pragma omp master taskloop simd
372 for (int(*p)[4] = lb; p < lb + 8; ++p) {
375 #pragma omp parallel
376 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
377 #pragma omp master taskloop simd
378 for (int a{0}; a < 10; ++a) {
381 return 0;
384 // Iterators allowed in openmp for-loops.
385 namespace std {
386 struct random_access_iterator_tag {};
387 template <class Iter>
388 struct iterator_traits {
389 typedef typename Iter::difference_type difference_type;
390 typedef typename Iter::iterator_category iterator_category;
392 template <class Iter>
393 typename iterator_traits<Iter>::difference_type
394 distance(Iter first, Iter last) { return first - last; }
396 class Iter0 {
397 public:
398 Iter0() {}
399 Iter0(const Iter0 &) {}
400 Iter0 operator++() { return *this; }
401 Iter0 operator--() { return *this; }
402 bool operator<(Iter0 a) { return true; }
404 // expected-note@+2 {{candidate function not viable: no known conversion from 'GoodIter' to 'Iter0' for 1st argument}}
405 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'Iter0' for 1st argument}}
406 int operator-(Iter0 a, Iter0 b) { return 0; }
407 class Iter1 {
408 public:
409 Iter1(float f = 0.0f, double d = 0.0) {}
410 Iter1(const Iter1 &) {}
411 Iter1 operator++() { return *this; }
412 Iter1 operator--() { return *this; }
413 bool operator<(Iter1 a) { return true; }
414 bool operator>=(Iter1 a) { return false; }
416 class GoodIter {
417 public:
418 GoodIter() {}
419 GoodIter(const GoodIter &) {}
420 GoodIter(int fst, int snd) {}
421 GoodIter &operator=(const GoodIter &that) { return *this; }
422 GoodIter &operator=(const Iter0 &that) { return *this; }
423 GoodIter &operator+=(int x) { return *this; }
424 GoodIter &operator-=(int x) { return *this; }
425 explicit GoodIter(void *) {}
426 GoodIter operator++() { return *this; }
427 GoodIter operator--() { return *this; }
428 bool operator!() { return true; }
429 bool operator<(GoodIter a) { return true; }
430 bool operator<=(GoodIter a) { return true; }
431 bool operator>=(GoodIter a) { return false; }
432 typedef int difference_type;
433 typedef std::random_access_iterator_tag iterator_category;
435 // expected-note@+2 {{candidate function not viable: no known conversion from 'const Iter0' to 'GoodIter' for 2nd argument}}
436 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}}
437 int operator-(GoodIter a, GoodIter b) { return 0; }
438 // expected-note@+1 3 {{candidate function not viable: requires single argument 'a', but 2 arguments were provided}}
439 GoodIter operator-(GoodIter a) { return a; }
440 // expected-note@+2 {{candidate function not viable: no known conversion from 'const Iter0' to 'int' for 2nd argument}}
441 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}}
442 GoodIter operator-(GoodIter a, int v) { return GoodIter(); }
443 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter0' to 'GoodIter' for 1st argument}}
444 GoodIter operator+(GoodIter a, int v) { return GoodIter(); }
445 // expected-note@+2 {{candidate function not viable: no known conversion from 'GoodIter' to 'int' for 1st argument}}
446 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'int' for 1st argument}}
447 GoodIter operator-(int v, GoodIter a) { return GoodIter(); }
448 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter0' to 'int' for 1st argument}}
449 GoodIter operator+(int v, GoodIter a) { return GoodIter(); }
451 int test_with_random_access_iterator() {
452 GoodIter begin, end;
453 Iter0 begin0, end0;
454 #pragma omp parallel
455 #pragma omp master taskloop simd
456 for (GoodIter I = begin; I < end; ++I)
457 ++I;
458 #pragma omp parallel
459 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
460 #pragma omp master taskloop simd
461 for (GoodIter &I = begin; I < end; ++I)
462 ++I;
463 #pragma omp parallel
464 #pragma omp master taskloop simd
465 for (GoodIter I = begin; I >= end; --I)
466 ++I;
467 #pragma omp parallel
468 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
469 #pragma omp master taskloop simd
470 for (GoodIter I(begin); I < end; ++I)
471 ++I;
472 #pragma omp parallel
473 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
474 #pragma omp master taskloop simd
475 for (GoodIter I(nullptr); I < end; ++I)
476 ++I;
477 #pragma omp parallel
478 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
479 #pragma omp master taskloop simd
480 for (GoodIter I(0); I < end; ++I)
481 ++I;
482 #pragma omp parallel
483 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
484 #pragma omp master taskloop simd
485 for (GoodIter I(1, 2); I < end; ++I)
486 ++I;
487 #pragma omp parallel
488 #pragma omp master taskloop simd
489 for (begin = GoodIter(0); begin < end; ++begin)
490 ++begin;
491 // expected-error@+4 {{invalid operands to binary expression ('GoodIter' and 'const Iter0')}}
492 // expected-error@+3 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}
493 #pragma omp parallel
494 #pragma omp master taskloop simd
495 for (begin = begin0; begin < end; ++begin)
496 ++begin;
497 #pragma omp parallel
498 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
499 #pragma omp master taskloop simd
500 for (++begin; begin < end; ++begin)
501 ++begin;
502 #pragma omp parallel
503 #pragma omp master taskloop simd
504 for (begin = end; begin < end; ++begin)
505 ++begin;
506 #pragma omp parallel
507 // 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'}}
508 #pragma omp master taskloop simd
509 for (GoodIter I = begin; I - I; ++I)
510 ++I;
511 #pragma omp parallel
512 // 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'}}
513 #pragma omp master taskloop simd
514 for (GoodIter I = begin; begin < end; ++I)
515 ++I;
516 #pragma omp parallel
517 // 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'}}
518 #pragma omp master taskloop simd
519 for (GoodIter I = begin; !I; ++I)
520 ++I;
521 #pragma omp parallel
522 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
523 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
524 #pragma omp master taskloop simd
525 for (GoodIter I = begin; I >= end; I = I + 1)
526 ++I;
527 #pragma omp parallel
528 #pragma omp master taskloop simd
529 for (GoodIter I = begin; I >= end; I = I - 1)
530 ++I;
531 #pragma omp parallel
532 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}}
533 #pragma omp master taskloop simd
534 for (GoodIter I = begin; I >= end; I = -I)
535 ++I;
536 #pragma omp parallel
537 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
538 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
539 #pragma omp master taskloop simd
540 for (GoodIter I = begin; I >= end; I = 2 + I)
541 ++I;
542 #pragma omp parallel
543 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}}
544 #pragma omp master taskloop simd
545 for (GoodIter I = begin; I >= end; I = 2 - I)
546 ++I;
547 // In the following example, we cannot update the loop variable using '+='
548 // expected-error@+3 {{invalid operands to binary expression ('Iter0' and 'int')}}
549 #pragma omp parallel
550 #pragma omp master taskloop simd
551 for (Iter0 I = begin0; I < end0; ++I)
552 ++I;
553 #pragma omp parallel
554 // Initializer is constructor without params.
555 // expected-error@+3 {{invalid operands to binary expression ('Iter0' and 'int')}}
556 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
557 #pragma omp master taskloop simd
558 for (Iter0 I; I < end0; ++I)
559 ++I;
560 Iter1 begin1, end1;
561 // expected-error@+4 {{invalid operands to binary expression ('Iter1' and 'Iter1')}}
562 // expected-error@+3 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}
563 #pragma omp parallel
564 #pragma omp master taskloop simd
565 for (Iter1 I = begin1; I < end1; ++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 master taskloop simd
571 for (Iter1 I = begin1; I >= end1; ++I)
572 ++I;
573 #pragma omp parallel
574 // expected-error@+5 {{invalid operands to binary expression ('Iter1' and 'float')}}
575 // expected-error@+4 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}
576 // Initializer is constructor with all default params.
577 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
578 #pragma omp master taskloop simd
579 for (Iter1 I; I < end1; ++I) {
581 return 0;
584 template <typename IT, int ST>
585 class TC {
586 public:
587 int dotest_lt(IT begin, IT end) {
588 #pragma omp parallel
589 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
590 // expected-error@+2 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}}
591 #pragma omp master taskloop simd
592 for (IT I = begin; I < end; I = I + ST) {
593 ++I;
595 #pragma omp parallel
596 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
597 // expected-error@+2 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}}
598 #pragma omp master taskloop simd
599 for (IT I = begin; I <= end; I += ST) {
600 ++I;
602 #pragma omp parallel
603 #pragma omp master taskloop simd
604 for (IT I = begin; I < end; ++I) {
605 ++I;
609 static IT step() {
610 return IT(ST);
613 template <typename IT, int ST = 0>
614 int dotest_gt(IT begin, IT end) {
615 #pragma omp parallel
616 // expected-note@+3 2 {{loop step is expected to be negative due to this condition}}
617 // expected-error@+2 2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
618 #pragma omp master taskloop simd
619 for (IT I = begin; I >= end; I = I + ST) {
620 ++I;
622 #pragma omp parallel
623 // expected-note@+3 2 {{loop step is expected to be negative due to this condition}}
624 // expected-error@+2 2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
625 #pragma omp master taskloop simd
626 for (IT I = begin; I >= end; I += ST) {
627 ++I;
630 #pragma omp parallel
631 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
632 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
633 #pragma omp master taskloop simd
634 for (IT I = begin; I >= end; ++I) {
635 ++I;
638 #pragma omp parallel
639 #pragma omp master taskloop simd
640 for (IT I = begin; I < end; I += TC<int, ST>::step()) {
641 ++I;
645 void test_with_template() {
646 GoodIter begin, end;
647 TC<GoodIter, 100> t1;
648 TC<GoodIter, -100> t2;
649 t1.dotest_lt(begin, end);
650 t2.dotest_lt(begin, end); // expected-note {{in instantiation of member function 'TC<GoodIter, -100>::dotest_lt' requested here}}
651 dotest_gt(begin, end); // expected-note {{in instantiation of function template specialization 'dotest_gt<GoodIter, 0>' requested here}}
652 dotest_gt<unsigned, 10>(0, 100); // expected-note {{in instantiation of function template specialization 'dotest_gt<unsigned int, 10>' requested here}}
655 void test_loop_break() {
656 const int N = 100;
657 float a[N], b[N], c[N];
658 #pragma omp parallel
659 #pragma omp master taskloop simd
660 for (int i = 0; i < 10; i++) {
661 c[i] = a[i] + b[i];
662 for (int j = 0; j < 10; ++j) {
663 if (a[i] > b[j])
664 break; // OK in nested loop
666 switch (i) {
667 case 1:
668 b[i]++;
669 break;
670 default:
671 break;
673 if (c[i] > 10)
674 break; // expected-error {{'break' statement cannot be used in OpenMP for loop}}
676 if (c[i] > 11)
677 break; // expected-error {{'break' statement cannot be used in OpenMP for loop}}
680 #pragma omp parallel
681 #pragma omp master taskloop simd
682 for (int i = 0; i < 10; i++) {
683 for (int j = 0; j < 10; j++) {
684 c[i] = a[i] + b[i];
685 if (c[i] > 10) {
686 if (c[i] < 20) {
687 break; // OK
694 void test_loop_eh() {
695 const int N = 100;
696 float a[N], b[N], c[N];
697 #pragma omp parallel
698 #pragma omp master taskloop simd
699 for (int i = 0; i < 10; i++) {
700 c[i] = a[i] + b[i];
701 try { // expected-error {{'try' statement cannot be used in OpenMP simd region}}
702 for (int j = 0; j < 10; ++j) {
703 if (a[i] > b[j])
704 throw a[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
706 throw a[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
707 } catch (float f) {
708 if (f > 0.1)
709 throw a[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
710 return; // expected-error {{cannot return from OpenMP region}}
712 switch (i) {
713 case 1:
714 b[i]++;
715 break;
716 default:
717 break;
719 for (int j = 0; j < 10; j++) {
720 if (c[i] > 10)
721 throw c[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
724 if (c[9] > 10)
725 throw c[9]; // OK
727 #pragma omp parallel
728 #pragma omp master taskloop simd
729 for (int i = 0; i < 10; ++i) {
730 struct S {
731 void g() { throw 0; }
736 void test_loop_firstprivate_lastprivate() {
737 S s(4);
738 #pragma omp parallel
739 #pragma omp master taskloop simd lastprivate(s) firstprivate(s)
740 for (int i = 0; i < 16; ++i)