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