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