1 // RUN: %clang_cc1 -fsyntax-only -fopenmp -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify %s
2
3 class S {
4 int a;
S()5 S() : a(0) {}
6
7 public:
S(int v)8 S(int v) : a(v) {}
S(const S & s)9 S(const S &s) : a(s.a) {}
10 };
11
12 static int sii;
13 #pragma omp threadprivate(sii)
14 static int globalii;
15
16 // Currently, we cannot use "0" for global register variables.
17 // register int reg0 __asm__("0");
18 int reg0;
19
test_iteration_spaces()20 int test_iteration_spaces() {
21 const int N = 100;
22 float a[N], b[N], c[N];
23 int ii, jj, kk;
24 float fii;
25 double dii;
26 register int reg; // expected-warning {{'register' storage class specifier is deprecated}}
27 #pragma omp parallel
28 #pragma omp taskloop
29 for (int i = 0; i < 10; i += 1) {
30 c[i] = a[i] + b[i];
31 }
32 #pragma omp parallel
33 #pragma omp taskloop
34 for (char i = 0; i < 10; i++) {
35 c[i] = a[i] + b[i];
36 }
37 #pragma omp parallel
38 #pragma omp taskloop
39 for (char i = 0; i < 10; i += '\1') {
40 c[i] = a[i] + b[i];
41 }
42 #pragma omp parallel
43 #pragma omp taskloop
44 for (long long i = 0; i < 10; i++) {
45 c[i] = a[i] + b[i];
46 }
47 #pragma omp parallel
48 // expected-error@+2 {{expression must have integral or unscoped enumeration type, not 'double'}}
49 #pragma omp taskloop
50 for (long long i = 0; i < 10; i += 1.5) {
51 c[i] = a[i] + b[i];
52 }
53 #pragma omp parallel
54 #pragma omp taskloop
55 for (long long i = 0; i < 'z'; i += 1u) {
56 c[i] = a[i] + b[i];
57 }
58 #pragma omp parallel
59 // expected-error@+2 {{variable must be of integer or random access iterator type}}
60 #pragma omp taskloop
61 for (float fi = 0; fi < 10.0; fi++) {
62 c[(int)fi] = a[(int)fi] + b[(int)fi];
63 }
64 #pragma omp parallel
65 // expected-error@+2 {{variable must be of integer or random access iterator type}}
66 #pragma omp taskloop
67 for (double fi = 0; fi < 10.0; fi++) {
68 c[(int)fi] = a[(int)fi] + b[(int)fi];
69 }
70 #pragma omp parallel
71 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
72 #pragma omp taskloop
73 for (int &ref = ii; ref < 10; ref++) {
74 }
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 taskloop
78 for (int i; i < 10; i++)
79 c[i] = a[i];
80
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 taskloop
84 for (int i = 0, j = 0; i < 10; ++i)
85 c[i] = a[i];
86
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 taskloop
90 for (; ii < 10; ++ii)
91 c[ii] = a[ii];
92
93 #pragma omp parallel
94 // expected-warning@+3 {{expression result unused}}
95 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
96 #pragma omp taskloop
97 for (ii + 1; ii < 10; ++ii)
98 c[ii] = a[ii];
99
100 #pragma omp parallel
101 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
102 #pragma omp taskloop
103 for (c[ii] = 0; ii < 10; ++ii)
104 c[ii] = a[ii];
105
106 #pragma omp parallel
107 // Ok to skip parenthesises.
108 #pragma omp taskloop
109 for (((ii)) = 0; ii < 10; ++ii)
110 c[ii] = a[ii];
111
112 #pragma omp parallel
113 // expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}}
114 #pragma omp taskloop
115 for (int i = 0; i; i++)
116 c[i] = a[i];
117
118 #pragma omp parallel
119 // expected-error@+3 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}}
120 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'i'}}
121 #pragma omp taskloop
122 for (int i = 0; jj < kk; ii++)
123 c[i] = a[i];
124
125 #pragma omp parallel
126 // expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}}
127 #pragma omp taskloop
128 for (int i = 0; !!i; i++)
129 c[i] = a[i];
130
131 #pragma omp parallel
132 // expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}}
133 #pragma omp taskloop
134 for (int i = 0; i != 1; i++)
135 c[i] = a[i];
136
137 #pragma omp parallel
138 // expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}}
139 #pragma omp taskloop
140 for (int i = 0;; i++)
141 c[i] = a[i];
142
143 #pragma omp parallel
144 // Ok.
145 #pragma omp taskloop
146 for (int i = 11; i > 10; i--)
147 c[i] = a[i];
148
149 #pragma omp parallel
150 // Ok.
151 #pragma omp taskloop
152 for (int i = 0; i < 10; ++i)
153 c[i] = a[i];
154
155 #pragma omp parallel
156 // Ok.
157 #pragma omp taskloop
158 for (ii = 0; ii < 10; ++ii)
159 c[ii] = a[ii];
160
161 #pragma omp parallel
162 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
163 #pragma omp taskloop
164 for (ii = 0; ii < 10; ++jj)
165 c[ii] = a[jj];
166
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 taskloop
170 for (ii = 0; ii < 10; ++++ii)
171 c[ii] = a[ii];
172
173 #pragma omp parallel
174 // Ok but undefined behavior (in general, cannot check that incr
175 // is really loop-invariant).
176 #pragma omp taskloop
177 for (ii = 0; ii < 10; ii = ii + ii)
178 c[ii] = a[ii];
179
180 #pragma omp parallel
181 // expected-error@+2 {{expression must have integral or unscoped enumeration type, not 'float'}}
182 #pragma omp taskloop
183 for (ii = 0; ii < 10; ii = ii + 1.0f)
184 c[ii] = a[ii];
185
186 #pragma omp parallel
187 // Ok - step was converted to integer type.
188 #pragma omp taskloop
189 for (ii = 0; ii < 10; ii = ii + (int)1.1f)
190 c[ii] = a[ii];
191
192 #pragma omp parallel
193 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
194 #pragma omp taskloop
195 for (ii = 0; ii < 10; jj = ii + 2)
196 c[ii] = a[ii];
197
198 #pragma omp parallel
199 // expected-warning@+3 {{relational comparison result unused}}
200 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
201 #pragma omp taskloop
202 for (ii = 0; ii<10; jj> kk + 2)
203 c[ii] = a[ii];
204
205 #pragma omp parallel
206 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
207 #pragma omp taskloop
208 for (ii = 0; ii < 10;)
209 c[ii] = a[ii];
210
211 #pragma omp parallel
212 // expected-warning@+3 {{expression result unused}}
213 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
214 #pragma omp taskloop
215 for (ii = 0; ii < 10; !ii)
216 c[ii] = a[ii];
217
218 #pragma omp parallel
219 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
220 #pragma omp taskloop
221 for (ii = 0; ii < 10; ii ? ++ii : ++jj)
222 c[ii] = a[ii];
223
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 taskloop
227 for (ii = 0; ii < 10; ii = ii < 10)
228 c[ii] = a[ii];
229
230 #pragma omp parallel
231 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
232 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
233 #pragma omp taskloop
234 for (ii = 0; ii < 10; ii = ii + 0)
235 c[ii] = a[ii];
236
237 #pragma omp parallel
238 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
239 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
240 #pragma omp taskloop
241 for (ii = 0; ii < 10; ii = ii + (int)(0.8 - 0.45))
242 c[ii] = a[ii];
243
244 #pragma omp parallel
245 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
246 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
247 #pragma omp taskloop
248 for (ii = 0; (ii) < 10; ii -= 25)
249 c[ii] = a[ii];
250
251 #pragma omp parallel
252 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
253 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
254 #pragma omp taskloop
255 for (ii = 0; (ii < 10); ii -= 0)
256 c[ii] = a[ii];
257
258 #pragma omp parallel
259 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
260 // expected-error@+2 {{increment expression must cause 'ii' to decrease on each iteration of OpenMP for loop}}
261 #pragma omp taskloop
262 for (ii = 0; ii > 10; (ii += 0))
263 c[ii] = a[ii];
264
265 #pragma omp parallel
266 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
267 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
268 #pragma omp taskloop
269 for (ii = 0; ii < 10; (ii) = (1 - 1) + (ii))
270 c[ii] = a[ii];
271
272 #pragma omp parallel
273 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
274 // expected-error@+2 {{increment expression must cause 'ii' to decrease on each iteration of OpenMP for loop}}
275 #pragma omp taskloop
276 for ((ii = 0); ii > 10; (ii -= 0))
277 c[ii] = a[ii];
278
279 #pragma omp parallel
280 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
281 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
282 #pragma omp taskloop
283 for (ii = 0; (ii < 10); (ii -= 0))
284 c[ii] = a[ii];
285
286 #pragma omp parallel
287 // expected-note@+2 {{defined as firstprivate}}
288 // expected-error@+2 {{loop iteration variable in the associated loop of 'omp taskloop' directive may not be firstprivate, predetermined as private}}
289 #pragma omp taskloop firstprivate(ii)
290 for (ii = 0; ii < 10; ii++)
291 c[ii] = a[ii];
292
293 #pragma omp parallel
294 // expected-error@+2 {{unexpected OpenMP clause 'linear' in directive '#pragma omp taskloop'}}
295 // expected-note@+1 {{defined as linear}}
296 #pragma omp taskloop linear(ii)
297 // expected-error@+1 {{loop iteration variable in the associated loop of 'omp taskloop' directive may not be linear, predetermined as private}}
298 for (ii = 0; ii < 10; ii++)
299 c[ii] = a[ii];
300
301 #pragma omp parallel
302 #pragma omp taskloop private(ii)
303 for (ii = 0; ii < 10; ii++)
304 c[ii] = a[ii];
305
306 #pragma omp parallel
307 #pragma omp taskloop lastprivate(ii)
308 for (ii = 0; ii < 10; ii++)
309 c[ii] = a[ii];
310
311 #pragma omp parallel
312 {
313 #pragma omp taskloop
314 for (sii = 0; sii < 10; sii += 1)
315 c[sii] = a[sii];
316 }
317
318 #pragma omp parallel
319 {
320 #pragma omp taskloop
321 for (reg0 = 0; reg0 < 10; reg0 += 1)
322 c[reg0] = a[reg0];
323 }
324
325 #pragma omp parallel
326 {
327 #pragma omp taskloop
328 for (reg = 0; reg < 10; reg += 1)
329 c[reg] = a[reg];
330 }
331
332 #pragma omp parallel
333 {
334 #pragma omp taskloop
335 for (globalii = 0; globalii < 10; globalii += 1)
336 c[globalii] = a[globalii];
337 }
338
339 #pragma omp parallel
340 {
341 #pragma omp taskloop collapse(2)
342 for (ii = 0; ii < 10; ii += 1)
343 for (globalii = 0; globalii < 10; globalii += 1)
344 c[globalii] += a[globalii] + ii;
345 }
346
347 #pragma omp parallel
348 // expected-error@+2 {{statement after '#pragma omp taskloop' must be a for loop}}
349 #pragma omp taskloop
350 for (auto &item : a) {
351 item = item + 1;
352 }
353
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 taskloop
358 for (unsigned i = 9; i < 10; i--) {
359 c[i] = a[i] + b[i];
360 }
361
362 int(*lb)[4] = nullptr;
363 #pragma omp parallel
364 #pragma omp taskloop
365 for (int(*p)[4] = lb; p < lb + 8; ++p) {
366 }
367
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 taskloop
371 for (int a{0}; a < 10; ++a) {
372 }
373
374 return 0;
375 }
376
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;
384 };
385 template <class Iter>
386 typename iterator_traits<Iter>::difference_type
distance(Iter first,Iter last)387 distance(Iter first, Iter last) { return first - last; }
388 }
389 class Iter0 {
390 public:
Iter0()391 Iter0() {}
Iter0(const Iter0 &)392 Iter0(const Iter0 &) {}
operator ++()393 Iter0 operator++() { return *this; }
operator --()394 Iter0 operator--() { return *this; }
operator <(Iter0 a)395 bool operator<(Iter0 a) { return true; }
396 };
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}}
operator -(Iter0 a,Iter0 b)399 int operator-(Iter0 a, Iter0 b) { return 0; }
400 class Iter1 {
401 public:
Iter1(float f=0.0f,double d=0.0)402 Iter1(float f = 0.0f, double d = 0.0) {}
Iter1(const Iter1 &)403 Iter1(const Iter1 &) {}
operator ++()404 Iter1 operator++() { return *this; }
operator --()405 Iter1 operator--() { return *this; }
operator <(Iter1 a)406 bool operator<(Iter1 a) { return true; }
operator >=(Iter1 a)407 bool operator>=(Iter1 a) { return false; }
408 };
409 class GoodIter {
410 public:
GoodIter()411 GoodIter() {}
GoodIter(const GoodIter &)412 GoodIter(const GoodIter &) {}
GoodIter(int fst,int snd)413 GoodIter(int fst, int snd) {}
operator =(const GoodIter & that)414 GoodIter &operator=(const GoodIter &that) { return *this; }
operator =(const Iter0 & that)415 GoodIter &operator=(const Iter0 &that) { return *this; }
operator +=(int x)416 GoodIter &operator+=(int x) { return *this; }
operator -=(int x)417 GoodIter &operator-=(int x) { return *this; }
GoodIter(void *)418 explicit GoodIter(void *) {}
operator ++()419 GoodIter operator++() { return *this; }
operator --()420 GoodIter operator--() { return *this; }
operator !()421 bool operator!() { return true; }
operator <(GoodIter a)422 bool operator<(GoodIter a) { return true; }
operator <=(GoodIter a)423 bool operator<=(GoodIter a) { return true; }
operator >=(GoodIter a)424 bool operator>=(GoodIter a) { return false; }
425 typedef int difference_type;
426 typedef std::random_access_iterator_tag iterator_category;
427 };
428 // expected-note@+2 {{candidate function not viable: no known conversion from '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}}
operator -(GoodIter a,GoodIter b)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}}
operator -(GoodIter a)432 GoodIter operator-(GoodIter a) { return a; }
433 // expected-note@+2 {{candidate function not viable: no known conversion from '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}}
operator -(GoodIter a,int v)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}}
operator +(GoodIter a,int v)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}}
operator -(int v,GoodIter a)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}}
operator +(int v,GoodIter a)442 GoodIter operator+(int v, GoodIter a) { return GoodIter(); }
443
test_with_random_access_iterator()444 int test_with_random_access_iterator() {
445 GoodIter begin, end;
446 Iter0 begin0, end0;
447 #pragma omp parallel
448 #pragma omp taskloop
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 taskloop
454 for (GoodIter &I = begin; I < end; ++I)
455 ++I;
456 #pragma omp parallel
457 #pragma omp taskloop
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 taskloop
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 taskloop
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 taskloop
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 taskloop
478 for (GoodIter I(1, 2); I < end; ++I)
479 ++I;
480 #pragma omp parallel
481 #pragma omp taskloop
482 for (begin = GoodIter(0); begin < end; ++begin)
483 ++begin;
484 // expected-error@+4 {{invalid operands to binary expression ('GoodIter' and '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 taskloop
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 taskloop
493 for (++begin; begin < end; ++begin)
494 ++begin;
495 #pragma omp parallel
496 #pragma omp taskloop
497 for (begin = end; begin < end; ++begin)
498 ++begin;
499 #pragma omp parallel
500 // expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'I'}}
501 #pragma omp taskloop
502 for (GoodIter I = begin; I - I; ++I)
503 ++I;
504 #pragma omp parallel
505 // expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'I'}}
506 #pragma omp taskloop
507 for (GoodIter I = begin; begin < end; ++I)
508 ++I;
509 #pragma omp parallel
510 // expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'I'}}
511 #pragma omp taskloop
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 taskloop
518 for (GoodIter I = begin; I >= end; I = I + 1)
519 ++I;
520 #pragma omp parallel
521 #pragma omp taskloop
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 taskloop
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 taskloop
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 taskloop
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 taskloop
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 taskloop
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 taskloop
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 taskloop
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 taskloop
572 for (Iter1 I; I < end1; ++I) {
573 }
574 return 0;
575 }
576
577 template <typename IT, int ST>
578 class TC {
579 public:
dotest_lt(IT begin,IT end)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 taskloop
585 for (IT I = begin; I < end; I = I + ST) {
586 ++I;
587 }
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 taskloop
592 for (IT I = begin; I <= end; I += ST) {
593 ++I;
594 }
595 #pragma omp parallel
596 #pragma omp taskloop
597 for (IT I = begin; I < end; ++I) {
598 ++I;
599 }
600 }
601
step()602 static IT step() {
603 return IT(ST);
604 }
605 };
606 template <typename IT, int ST = 0>
dotest_gt(IT begin,IT end)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 taskloop
612 for (IT I = begin; I >= end; I = I + ST) {
613 ++I;
614 }
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 taskloop
619 for (IT I = begin; I >= end; I += ST) {
620 ++I;
621 }
622
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 taskloop
627 for (IT I = begin; I >= end; ++I) {
628 ++I;
629 }
630
631 #pragma omp parallel
632 #pragma omp taskloop
633 for (IT I = begin; I < end; I += TC<int, ST>::step()) {
634 ++I;
635 }
636 }
637
test_with_template()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}}
646 }
647
test_loop_break()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 taskloop
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
658 }
659 switch (i) {
660 case 1:
661 b[i]++;
662 break;
663 default:
664 break;
665 }
666 if (c[i] > 10)
667 break; // expected-error {{'break' statement cannot be used in OpenMP for loop}}
668
669 if (c[i] > 11)
670 break; // expected-error {{'break' statement cannot be used in OpenMP for loop}}
671 }
672
673 #pragma omp parallel
674 #pragma omp taskloop
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
681 }
682 }
683 }
684 }
685 }
686
test_loop_eh()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 taskloop
692 for (int i = 0; i < 10; i++) {
693 c[i] = a[i] + b[i];
694 try {
695 for (int j = 0; j < 10; ++j) {
696 if (a[i] > b[j])
697 throw a[i];
698 }
699 throw a[i];
700 } catch (float f) {
701 if (f > 0.1)
702 throw a[i];
703 return; // expected-error {{cannot return from OpenMP region}}
704 }
705 switch (i) {
706 case 1:
707 b[i]++;
708 break;
709 default:
710 break;
711 }
712 for (int j = 0; j < 10; j++) {
713 if (c[i] > 10)
714 throw c[i];
715 }
716 }
717 if (c[9] > 10)
718 throw c[9]; // OK
719
720 #pragma omp parallel
721 #pragma omp taskloop
722 for (int i = 0; i < 10; ++i) {
723 struct S {
724 void g() { throw 0; }
725 };
726 }
727 }
728
test_loop_firstprivate_lastprivate()729 void test_loop_firstprivate_lastprivate() {
730 S s(4);
731 #pragma omp parallel
732 #pragma omp taskloop lastprivate(s) firstprivate(s)
733 for (int i = 0; i < 16; ++i)
734 ;
735 }
736
737