[libc][test] Adjust header paths in tests (#119623)
[llvm-project.git] / clang / test / OpenMP / parallel_masked_taskloop_simd_loop_messages.cpp
blobc92b1ab8210354cf25cc348cf474ba0e3ef492b3
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 parallel masked 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 parallel masked taskloop simd
39 for (char i = 0; i < 10; i++) {
40 c[i] = a[i] + b[i];
42 #pragma omp parallel
43 #pragma omp parallel masked 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 parallel masked 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 parallel masked 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 parallel masked 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 parallel masked 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 parallel masked 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 parallel masked 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 parallel masked 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 parallel masked 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 parallel masked 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 parallel masked 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 parallel masked 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 parallel masked 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 parallel masked 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 parallel masked 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 parallel masked taskloop simd
133 for (int i = 0; !!i; i++)
134 c[i] = a[i];
136 // Ok
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 parallel 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 parallel masked taskloop simd
146 for (int i = 0;; i++)
147 c[i] = a[i];
149 #pragma omp parallel
150 // Ok.
151 #pragma omp parallel 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 parallel 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 parallel 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 parallel 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 parallel 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 parallel 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 parallel 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 parallel 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 parallel 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 parallel 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 parallel 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 parallel 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 parallel 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 parallel 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 parallel 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 parallel 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 parallel 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 parallel 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 parallel 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 parallel 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 parallel 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 parallel 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 parallel masked taskloop simd' directive may not be firstprivate, predetermined as linear}}
295 #pragma omp parallel masked taskloop simd firstprivate(ii)
296 for (ii = 0; ii < 10; ii++)
297 c[ii] = a[ii];
299 #pragma omp parallel
300 // expected-error@+1 {{unexpected OpenMP clause 'in_reduction' in directive '#pragma omp parallel masked taskloop simd'}}
301 #pragma omp parallel masked taskloop simd in_reduction(+:ii)
302 for (ii = 0; ii < 10; ii++)
303 c[ii] = a[ii];
305 #pragma omp parallel
306 #pragma omp parallel masked taskloop simd linear(ii)
307 for (ii = 0; ii < 10; ii++)
308 c[ii] = a[ii];
310 #pragma omp parallel
312 // expected-error@+2 {{loop iteration variable in the associated loop of 'omp parallel masked taskloop simd' directive may not be threadprivate or thread local, predetermined as linear}}
313 #pragma omp parallel masked taskloop simd
314 for (sii = 0; sii < 10; sii += 1)
315 c[sii] = a[sii];
318 #pragma omp parallel
320 #pragma omp parallel masked taskloop simd
321 for (reg0 = 0; reg0 < 10; reg0 += 1)
322 c[reg0] = a[reg0];
325 #pragma omp parallel
327 #pragma omp parallel masked taskloop simd
328 for (reg = 0; reg < 10; reg += 1)
329 c[reg] = a[reg];
332 #pragma omp parallel
334 #pragma omp parallel masked taskloop simd
335 for (globalii = 0; globalii < 10; globalii += 1)
336 c[globalii] = a[globalii];
339 #pragma omp parallel
341 #pragma omp parallel masked taskloop simd collapse(2)
342 for (ii = 0; ii < 10; ii += 1)
343 for (globalii = 0; globalii < 10; globalii += 1)
344 c[globalii] += a[globalii] + ii;
347 #pragma omp parallel
348 // omp4-error@+2 {{statement after '#pragma omp parallel masked taskloop simd' must be a for loop}}
349 #pragma omp parallel masked taskloop simd
350 for (auto &item : a) {
351 item = item + 1;
354 #pragma omp parallel
355 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
356 // expected-error@+2 {{increment expression must cause 'i' to increase on each iteration of OpenMP for loop}}
357 #pragma omp parallel masked taskloop simd
358 for (unsigned i = 9; i < 10; i--) {
359 c[i] = a[i] + b[i];
362 int(*lb)[4] = nullptr;
363 #pragma omp parallel
364 #pragma omp parallel masked taskloop simd
365 for (int(*p)[4] = lb; p < lb + 8; ++p) {
368 #pragma omp parallel
369 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
370 #pragma omp parallel masked taskloop simd
371 for (int a{0}; a < 10; ++a) {
374 return 0;
377 // Iterators allowed in openmp for-loops.
378 namespace std {
379 struct random_access_iterator_tag {};
380 template <class Iter>
381 struct iterator_traits {
382 typedef typename Iter::difference_type difference_type;
383 typedef typename Iter::iterator_category iterator_category;
385 template <class Iter>
386 typename iterator_traits<Iter>::difference_type
387 distance(Iter first, Iter last) { return first - last; }
389 class Iter0 {
390 public:
391 Iter0() {}
392 Iter0(const Iter0 &) {}
393 Iter0 operator++() { return *this; }
394 Iter0 operator--() { return *this; }
395 bool operator<(Iter0 a) { return true; }
397 // expected-note@+2 {{candidate function not viable: no known conversion from 'GoodIter' to 'Iter0' for 1st argument}}
398 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'Iter0' for 1st argument}}
399 int operator-(Iter0 a, Iter0 b) { return 0; }
400 class Iter1 {
401 public:
402 Iter1(float f = 0.0f, double d = 0.0) {}
403 Iter1(const Iter1 &) {}
404 Iter1 operator++() { return *this; }
405 Iter1 operator--() { return *this; }
406 bool operator<(Iter1 a) { return true; }
407 bool operator>=(Iter1 a) { return false; }
409 class GoodIter {
410 public:
411 GoodIter() {}
412 GoodIter(const GoodIter &) {}
413 GoodIter(int fst, int snd) {}
414 GoodIter &operator=(const GoodIter &that) { return *this; }
415 GoodIter &operator=(const Iter0 &that) { return *this; }
416 GoodIter &operator+=(int x) { return *this; }
417 GoodIter &operator-=(int x) { return *this; }
418 explicit GoodIter(void *) {}
419 GoodIter operator++() { return *this; }
420 GoodIter operator--() { return *this; }
421 bool operator!() { return true; }
422 bool operator<(GoodIter a) { return true; }
423 bool operator<=(GoodIter a) { return true; }
424 bool operator>=(GoodIter a) { return false; }
425 typedef int difference_type;
426 typedef std::random_access_iterator_tag iterator_category;
428 // expected-note@+2 {{candidate function not viable: no known conversion from 'const Iter0' to 'GoodIter' for 2nd argument}}
429 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}}
430 int operator-(GoodIter a, GoodIter b) { return 0; }
431 // expected-note@+1 3 {{candidate function not viable: requires single argument 'a', but 2 arguments were provided}}
432 GoodIter operator-(GoodIter a) { return a; }
433 // expected-note@+2 {{candidate function not viable: no known conversion from 'const Iter0' to 'int' for 2nd argument}}
434 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}}
435 GoodIter operator-(GoodIter a, int v) { return GoodIter(); }
436 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter0' to 'GoodIter' for 1st argument}}
437 GoodIter operator+(GoodIter a, int v) { return GoodIter(); }
438 // expected-note@+2 {{candidate function not viable: no known conversion from 'GoodIter' to 'int' for 1st argument}}
439 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'int' for 1st argument}}
440 GoodIter operator-(int v, GoodIter a) { return GoodIter(); }
441 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter0' to 'int' for 1st argument}}
442 GoodIter operator+(int v, GoodIter a) { return GoodIter(); }
444 int test_with_random_access_iterator() {
445 GoodIter begin, end;
446 Iter0 begin0, end0;
447 #pragma omp parallel
448 #pragma omp parallel masked taskloop simd
449 for (GoodIter I = begin; I < end; ++I)
450 ++I;
451 #pragma omp parallel
452 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
453 #pragma omp parallel masked taskloop simd
454 for (GoodIter &I = begin; I < end; ++I)
455 ++I;
456 #pragma omp parallel
457 #pragma omp parallel masked taskloop simd
458 for (GoodIter I = begin; I >= end; --I)
459 ++I;
460 #pragma omp parallel
461 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
462 #pragma omp parallel masked taskloop simd
463 for (GoodIter I(begin); I < end; ++I)
464 ++I;
465 #pragma omp parallel
466 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
467 #pragma omp parallel masked taskloop simd
468 for (GoodIter I(nullptr); I < end; ++I)
469 ++I;
470 #pragma omp parallel
471 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
472 #pragma omp parallel masked taskloop simd
473 for (GoodIter I(0); I < end; ++I)
474 ++I;
475 #pragma omp parallel
476 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
477 #pragma omp parallel masked taskloop simd
478 for (GoodIter I(1, 2); I < end; ++I)
479 ++I;
480 #pragma omp parallel
481 #pragma omp parallel masked taskloop simd
482 for (begin = GoodIter(0); begin < end; ++begin)
483 ++begin;
484 // expected-error@+4 {{invalid operands to binary expression ('GoodIter' and 'const Iter0')}}
485 // expected-error@+3 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}
486 #pragma omp parallel
487 #pragma omp parallel masked taskloop simd
488 for (begin = begin0; begin < end; ++begin)
489 ++begin;
490 #pragma omp parallel
491 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
492 #pragma omp parallel masked taskloop simd
493 for (++begin; begin < end; ++begin)
494 ++begin;
495 #pragma omp parallel
496 #pragma omp parallel masked taskloop simd
497 for (begin = end; begin < end; ++begin)
498 ++begin;
499 #pragma omp parallel
500 // 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'}}
501 #pragma omp parallel masked taskloop simd
502 for (GoodIter I = begin; I - I; ++I)
503 ++I;
504 #pragma omp parallel
505 // 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'}}
506 #pragma omp parallel masked taskloop simd
507 for (GoodIter I = begin; begin < end; ++I)
508 ++I;
509 #pragma omp parallel
510 // 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'}}
511 #pragma omp parallel masked taskloop simd
512 for (GoodIter I = begin; !I; ++I)
513 ++I;
514 #pragma omp parallel
515 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
516 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
517 #pragma omp parallel masked taskloop simd
518 for (GoodIter I = begin; I >= end; I = I + 1)
519 ++I;
520 #pragma omp parallel
521 #pragma omp parallel masked taskloop simd
522 for (GoodIter I = begin; I >= end; I = I - 1)
523 ++I;
524 #pragma omp parallel
525 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}}
526 #pragma omp parallel masked taskloop simd
527 for (GoodIter I = begin; I >= end; I = -I)
528 ++I;
529 #pragma omp parallel
530 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
531 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
532 #pragma omp parallel masked taskloop simd
533 for (GoodIter I = begin; I >= end; I = 2 + I)
534 ++I;
535 #pragma omp parallel
536 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}}
537 #pragma omp parallel masked taskloop simd
538 for (GoodIter I = begin; I >= end; I = 2 - I)
539 ++I;
540 // In the following example, we cannot update the loop variable using '+='
541 // expected-error@+3 {{invalid operands to binary expression ('Iter0' and 'int')}}
542 #pragma omp parallel
543 #pragma omp parallel masked taskloop simd
544 for (Iter0 I = begin0; I < end0; ++I)
545 ++I;
546 #pragma omp parallel
547 // Initializer is constructor without params.
548 // expected-error@+3 {{invalid operands to binary expression ('Iter0' and 'int')}}
549 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
550 #pragma omp parallel masked taskloop simd
551 for (Iter0 I; I < end0; ++I)
552 ++I;
553 Iter1 begin1, end1;
554 // expected-error@+4 {{invalid operands to binary expression ('Iter1' and 'Iter1')}}
555 // expected-error@+3 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}
556 #pragma omp parallel
557 #pragma omp parallel masked taskloop simd
558 for (Iter1 I = begin1; I < end1; ++I)
559 ++I;
560 #pragma omp parallel
561 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
562 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
563 #pragma omp parallel masked taskloop simd
564 for (Iter1 I = begin1; I >= end1; ++I)
565 ++I;
566 #pragma omp parallel
567 // expected-error@+5 {{invalid operands to binary expression ('Iter1' and 'float')}}
568 // expected-error@+4 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}
569 // Initializer is constructor with all default params.
570 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
571 #pragma omp parallel masked taskloop simd
572 for (Iter1 I; I < end1; ++I) {
574 return 0;
577 template <typename IT, int ST>
578 class TC {
579 public:
580 int dotest_lt(IT begin, IT end) {
581 #pragma omp parallel
582 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
583 // expected-error@+2 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}}
584 #pragma omp parallel masked taskloop simd
585 for (IT I = begin; I < end; I = I + ST) {
586 ++I;
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 parallel masked taskloop simd
592 for (IT I = begin; I <= end; I += ST) {
593 ++I;
595 #pragma omp parallel
596 #pragma omp parallel masked taskloop simd
597 for (IT I = begin; I < end; ++I) {
598 ++I;
602 static IT step() {
603 return IT(ST);
606 template <typename IT, int ST = 0>
607 int dotest_gt(IT begin, IT end) {
608 #pragma omp parallel
609 // expected-note@+3 2 {{loop step is expected to be negative due to this condition}}
610 // expected-error@+2 2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
611 #pragma omp parallel masked taskloop simd
612 for (IT I = begin; I >= end; I = I + ST) {
613 ++I;
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 parallel masked taskloop simd
619 for (IT I = begin; I >= end; I += ST) {
620 ++I;
623 #pragma omp parallel
624 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
625 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
626 #pragma omp parallel masked taskloop simd
627 for (IT I = begin; I >= end; ++I) {
628 ++I;
631 #pragma omp parallel
632 #pragma omp parallel masked taskloop simd
633 for (IT I = begin; I < end; I += TC<int, ST>::step()) {
634 ++I;
638 void test_with_template() {
639 GoodIter begin, end;
640 TC<GoodIter, 100> t1;
641 TC<GoodIter, -100> t2;
642 t1.dotest_lt(begin, end);
643 t2.dotest_lt(begin, end); // expected-note {{in instantiation of member function 'TC<GoodIter, -100>::dotest_lt' requested here}}
644 dotest_gt(begin, end); // expected-note {{in instantiation of function template specialization 'dotest_gt<GoodIter, 0>' requested here}}
645 dotest_gt<unsigned, 10>(0, 100); // expected-note {{in instantiation of function template specialization 'dotest_gt<unsigned int, 10>' requested here}}
648 void test_loop_break() {
649 const int N = 100;
650 float a[N], b[N], c[N];
651 #pragma omp parallel
652 #pragma omp parallel masked taskloop simd
653 for (int i = 0; i < 10; i++) {
654 c[i] = a[i] + b[i];
655 for (int j = 0; j < 10; ++j) {
656 if (a[i] > b[j])
657 break; // OK in nested loop
659 switch (i) {
660 case 1:
661 b[i]++;
662 break;
663 default:
664 break;
666 if (c[i] > 10)
667 break; // expected-error {{'break' statement cannot be used in OpenMP for loop}}
669 if (c[i] > 11)
670 break; // expected-error {{'break' statement cannot be used in OpenMP for loop}}
673 #pragma omp parallel
674 #pragma omp parallel masked taskloop simd
675 for (int i = 0; i < 10; i++) {
676 for (int j = 0; j < 10; j++) {
677 c[i] = a[i] + b[i];
678 if (c[i] > 10) {
679 if (c[i] < 20) {
680 break; // OK
687 void test_loop_eh() {
688 const int N = 100;
689 float a[N], b[N], c[N];
690 #pragma omp parallel
691 #pragma omp parallel masked taskloop simd
692 for (int i = 0; i < 10; i++) {
693 c[i] = a[i] + b[i];
694 try { // expected-error {{'try' statement cannot be used in OpenMP simd region}}
695 for (int j = 0; j < 10; ++j) {
696 if (a[i] > b[j])
697 throw a[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
699 throw a[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
700 } catch (float f) {
701 if (f > 0.1)
702 throw a[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
703 return; // expected-error {{cannot return from OpenMP region}}
705 switch (i) {
706 case 1:
707 b[i]++;
708 break;
709 default:
710 break;
712 for (int j = 0; j < 10; j++) {
713 if (c[i] > 10)
714 throw c[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
717 if (c[9] > 10)
718 throw c[9]; // OK
720 #pragma omp parallel
721 #pragma omp parallel masked taskloop simd
722 for (int i = 0; i < 10; ++i) {
723 struct S {
724 void g() { throw 0; }
729 void test_loop_firstprivate_lastprivate() {
730 S s(4);
731 int c;
732 #pragma omp parallel
733 #pragma omp parallel masked taskloop simd lastprivate(s) firstprivate(s)
734 for (int i = 0; i < 16; ++i)
736 #pragma omp parallel masked taskloop simd if(c) default(none) // expected-error {{variable 'c' must have explicitly specified data sharing attributes}} expected-note {{explicit data sharing attribute requested here}}
737 for (int i = 0; i < 16; ++i)
739 #pragma omp parallel masked taskloop simd if(taskloop:c) default(none) // expected-error {{variable 'c' must have explicitly specified data sharing attributes}} expected-note {{explicit data sharing attribute requested here}}
740 for (int i = 0; i < 16; ++i)
742 #pragma omp parallel masked taskloop simd if(parallel:c) default(none)
743 for (int i = 0; i < 16; ++i)