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