Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / for_simd_loop_messages.cpp
blob1cc5988ea8092f4d8d5dee27a96b2f5c83efbffc
1 // RUN: %clang_cc1 -fsyntax-only -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify=expected,omp4 %s -Wuninitialized
2 // RUN: %clang_cc1 -fsyntax-only -fopenmp -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify=expected,omp5 %s -Wuninitialized
4 // RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -fopenmp-version=45 -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify=expected,omp4 %s -Wuninitialized
5 // RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify=expected,omp5 %s -Wuninitialized
7 class S {
8 int a;
9 S() : a(0) {}
11 public:
12 S(int v) : a(v) {}
13 S(const S &s) : a(s.a) {}
16 static int sii;
17 // expected-note@+1 {{defined as threadprivate or thread local}}
18 #pragma omp threadprivate(sii)
19 static int globalii;
21 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 #pragma omp parallel
28 #pragma omp for simd
29 for (int i = 0; i < 10; i += 1) {
30 c[i] = a[i] + b[i];
32 #pragma omp parallel
33 #pragma omp for simd
34 for (char i = 0; i < 10; i++) {
35 c[i] = a[i] + b[i];
37 #pragma omp parallel
38 #pragma omp for simd
39 for (char i = 0; i < 10; i += '\1') {
40 c[i] = a[i] + b[i];
42 #pragma omp parallel
43 #pragma omp for simd
44 for (long long i = 0; i < 10; i++) {
45 c[i] = a[i] + b[i];
47 #pragma omp parallel
48 // expected-error@+2 {{expression must have integral or unscoped enumeration type, not 'double'}}
49 #pragma omp for simd
50 for (long long i = 0; i < 10; i += 1.5) {
51 c[i] = a[i] + b[i];
53 #pragma omp parallel
54 #pragma omp for simd
55 for (long long i = 0; i < 'z'; i += 1u) {
56 c[i] = a[i] + b[i];
58 #pragma omp parallel
59 // expected-error@+2 {{variable must be of integer or random access iterator type}}
60 #pragma omp for simd
61 for (float fi = 0; fi < 10.0; fi++) {
62 c[(int)fi] = a[(int)fi] + b[(int)fi];
64 #pragma omp parallel
65 // expected-error@+2 {{variable must be of integer or random access iterator type}}
66 #pragma omp for simd
67 for (double fi = 0; fi < 10.0; fi++) {
68 c[(int)fi] = a[(int)fi] + b[(int)fi];
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 for simd
73 for (int &ref = ii; ref < 10; ref++) {
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 for simd
78 for (int i; i < 10; i++)
79 c[i] = a[i];
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 for simd
84 for (int i = 0, j = 0; i < 10; ++i)
85 c[i] = a[i];
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 for simd
90 for (; ii < 10; ++ii)
91 c[ii] = a[ii];
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 for simd
97 for (ii + 1; ii < 10; ++ii)
98 c[ii] = a[ii];
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 for simd
103 for (c[ii] = 0; ii < 10; ++ii)
104 c[ii] = a[ii];
106 #pragma omp parallel
107 // Ok to skip parenthesises.
108 #pragma omp for simd
109 for (((ii)) = 0; ii < 10; ++ii)
110 c[ii] = a[ii];
112 #pragma omp parallel
113 // 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'}}
114 #pragma omp for simd
115 for (int i = 0; i; i++)
116 c[i] = a[i];
118 #pragma omp parallel
119 // 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'}}
120 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'i'}}
121 #pragma omp for simd
122 for (int i = 0; jj < kk; ii++)
123 c[i] = a[i];
125 #pragma omp parallel
126 // 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'}}
127 #pragma omp for simd
128 for (int i = 0; !!i; i++)
129 c[i] = a[i];
131 #pragma omp parallel
132 // omp4-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}}
133 #pragma omp for simd
134 for (int i = 0; i != 1; i++)
135 c[i] = a[i];
137 #pragma omp parallel
138 // 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'}}
139 #pragma omp for simd
140 for (int i = 0;; i++)
141 c[i] = a[i];
143 #pragma omp parallel
144 // Ok.
145 #pragma omp for simd
146 for (int i = 11; i > 10; i--)
147 c[i] = a[i];
149 #pragma omp parallel
150 // Ok.
151 #pragma omp for simd
152 for (int i = 0; i < 10; ++i)
153 c[i] = a[i];
155 #pragma omp parallel
156 // Ok.
157 #pragma omp for simd
158 for (ii = 0; ii < 10; ++ii)
159 c[ii] = a[ii];
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 for simd
164 for (ii = 0; ii < 10; ++jj)
165 c[ii] = a[jj];
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 for simd
170 for (ii = 0; ii < 10; ++++ii)
171 c[ii] = a[ii];
173 #pragma omp parallel
174 // Ok but undefined behavior (in general, cannot check that incr
175 // is really loop-invariant).
176 #pragma omp for simd
177 for (ii = 0; ii < 10; ii = ii + ii)
178 c[ii] = a[ii];
180 #pragma omp parallel
181 // expected-error@+2 {{expression must have integral or unscoped enumeration type, not 'float'}}
182 #pragma omp for simd
183 for (ii = 0; ii < 10; ii = ii + 1.0f)
184 c[ii] = a[ii];
186 #pragma omp parallel
187 // Ok - step was converted to integer type.
188 #pragma omp for simd
189 for (ii = 0; ii < 10; ii = ii + (int)1.1f)
190 c[ii] = a[ii];
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 for simd
195 for (ii = 0; ii < 10; jj = ii + 2)
196 c[ii] = a[ii];
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 for simd
202 for (ii = 0; ii<10; jj> kk + 2)
203 c[ii] = a[ii];
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 for simd
208 for (ii = 0; ii < 10;)
209 c[ii] = a[ii];
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 for simd
215 for (ii = 0; ii < 10; !ii)
216 c[ii] = a[ii];
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 for simd
221 for (ii = 0; ii < 10; ii ? ++ii : ++jj)
222 c[ii] = a[ii];
224 #pragma omp parallel
225 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
226 #pragma omp for simd
227 for (ii = 0; ii < 10; ii = ii < 10)
228 c[ii] = a[ii];
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 for simd
234 for (ii = 0; ii < 10; ii = ii + 0)
235 c[ii] = a[ii];
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 for simd
241 for (ii = 0; ii < 10; ii = ii + (int)(0.8 - 0.45))
242 c[ii] = a[ii];
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 for simd
248 for (ii = 0; (ii) < 10; ii -= 25)
249 c[ii] = a[ii];
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 for simd
255 for (ii = 0; (ii < 10); ii -= 0)
256 c[ii] = a[ii];
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 for simd
262 for (ii = 0; ii > 10; (ii += 0))
263 c[ii] = a[ii];
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 for simd
269 for (ii = 0; ii < 10; (ii) = (1 - 1) + (ii))
270 c[ii] = a[ii];
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 for simd
276 for ((ii = 0); ii > 10; (ii -= 0))
277 c[ii] = a[ii];
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 for simd
283 for (ii = 0; (ii < 10); (ii -= 0))
284 c[ii] = a[ii];
286 #pragma omp parallel
287 // expected-note@+2 {{defined as firstprivate}}
288 // expected-error@+2 {{loop iteration variable in the associated loop of 'omp for simd' directive may not be firstprivate, predetermined as linear}}
289 #pragma omp for simd firstprivate(ii)
290 for (ii = 0; ii < 10; ii++)
291 c[ii] = a[ii];
293 #pragma omp parallel
294 #pragma omp for simd linear(ii)
295 for (ii = 0; ii < 10; ii++)
296 c[ii] = a[ii];
298 #pragma omp parallel
299 // omp4-note@+2 {{defined as private}}
300 // omp4-error@+2 {{loop iteration variable in the associated loop of 'omp for simd' directive may not be private, predetermined as linear}}
301 #pragma omp for simd private(ii)
302 for (ii = 0; ii < 10; ii++)
303 c[ii] = a[ii];
305 #pragma omp parallel
306 // omp4-note@+2 {{defined as lastprivate}}
307 // omp4-error@+2 {{loop iteration variable in the associated loop of 'omp for simd' directive may not be lastprivate, predetermined as linear}}
308 #pragma omp for simd lastprivate(ii)
309 for (ii = 0; ii < 10; ii++)
310 c[ii] = a[ii];
312 #pragma omp parallel
314 // expected-error@+2 {{loop iteration variable in the associated loop of 'omp for simd' directive may not be threadprivate or thread local, predetermined as linear}}
315 #pragma omp for simd
316 for (sii = 0; sii < 10; sii += 1)
317 c[sii] = a[sii];
320 #pragma omp parallel
322 #pragma omp for simd
323 for (globalii = 0; globalii < 10; globalii += 1)
324 c[globalii] = a[globalii];
327 #pragma omp parallel
329 #pragma omp for simd collapse(2)
330 for (ii = 0; ii < 10; ii += 1)
331 for (globalii = 0; globalii < 10; globalii += 1)
332 c[globalii] += a[globalii] + ii;
335 #pragma omp parallel
336 // omp4-error@+2 {{statement after '#pragma omp for simd' must be a for loop}}
337 #pragma omp for simd
338 for (auto &item : a) {
339 item = item + 1;
342 #pragma omp parallel
343 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
344 // expected-error@+2 {{increment expression must cause 'i' to increase on each iteration of OpenMP for loop}}
345 #pragma omp for simd
346 for (unsigned i = 9; i < 10; i--) {
347 c[i] = a[i] + b[i];
350 int(*lb)[4] = nullptr;
351 #pragma omp parallel
352 #pragma omp for simd
353 for (int(*p)[4] = lb; p < lb + 8; ++p) {
356 #pragma omp parallel
357 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
358 #pragma omp for simd
359 for (int a{0}; a < 10; ++a) {
362 return 0;
365 // Iterators allowed in openmp for-loops.
366 namespace std {
367 struct random_access_iterator_tag {};
368 template <class Iter>
369 struct iterator_traits {
370 typedef typename Iter::difference_type difference_type;
371 typedef typename Iter::iterator_category iterator_category;
373 template <class Iter>
374 typename iterator_traits<Iter>::difference_type
375 distance(Iter first, Iter last) { return first - last; }
377 class Iter0 {
378 public:
379 Iter0() {}
380 Iter0(const Iter0 &) {}
381 Iter0 operator++() { return *this; }
382 Iter0 operator--() { return *this; }
383 bool operator<(Iter0 a) { return true; }
385 // expected-note@+2 {{candidate function not viable: no known conversion from 'GoodIter' to 'Iter0' for 1st argument}}
386 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'Iter0' for 1st argument}}
387 int operator-(Iter0 a, Iter0 b) { return 0; }
388 class Iter1 {
389 public:
390 Iter1(float f = 0.0f, double d = 0.0) {}
391 Iter1(const Iter1 &) {}
392 Iter1 operator++() { return *this; }
393 Iter1 operator--() { return *this; }
394 bool operator<(Iter1 a) { return true; }
395 bool operator>=(Iter1 a) { return false; }
397 class GoodIter {
398 public:
399 GoodIter() {}
400 GoodIter(const GoodIter &) {}
401 GoodIter(int fst, int snd) {}
402 GoodIter &operator=(const GoodIter &that) { return *this; }
403 GoodIter &operator=(const Iter0 &that) { return *this; }
404 GoodIter &operator+=(int x) { return *this; }
405 explicit GoodIter(void *) {}
406 GoodIter operator++() { return *this; }
407 GoodIter operator--() { return *this; }
408 bool operator!() { return true; }
409 bool operator<(GoodIter a) { return true; }
410 bool operator<=(GoodIter a) { return true; }
411 bool operator>=(GoodIter a) { return false; }
412 typedef int difference_type;
413 typedef std::random_access_iterator_tag iterator_category;
415 // expected-note@+2 {{candidate function not viable: no known conversion from 'const Iter0' to 'GoodIter' for 2nd argument}}
416 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}}
417 int operator-(GoodIter a, GoodIter b) { return 0; }
418 // expected-note@+1 3 {{candidate function not viable: requires single argument 'a', but 2 arguments were provided}}
419 GoodIter operator-(GoodIter a) { return a; }
420 // expected-note@+2 {{candidate function not viable: no known conversion from 'const Iter0' to 'int' for 2nd argument}}
421 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}}
422 GoodIter operator-(GoodIter a, int v) { return GoodIter(); }
423 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter0' to 'GoodIter' for 1st argument}}
424 GoodIter operator+(GoodIter a, int v) { return GoodIter(); }
425 // expected-note@+2 {{candidate function not viable: no known conversion from 'GoodIter' to 'int' for 1st argument}}
426 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'int' for 1st argument}}
427 GoodIter operator-(int v, GoodIter a) { return GoodIter(); }
428 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter0' to 'int' for 1st argument}}
429 GoodIter operator+(int v, GoodIter a) { return GoodIter(); }
431 int test_with_random_access_iterator() {
432 GoodIter begin, end;
433 Iter0 begin0, end0;
434 #pragma omp parallel
435 #pragma omp for simd
436 for (GoodIter I = begin; I < end; ++I)
437 ++I;
438 #pragma omp parallel
439 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
440 #pragma omp for simd
441 for (GoodIter &I = begin; I < end; ++I)
442 ++I;
443 #pragma omp parallel
444 #pragma omp for simd
445 for (GoodIter I = begin; I >= end; --I)
446 ++I;
447 #pragma omp parallel
448 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
449 #pragma omp for simd
450 for (GoodIter I(begin); I < end; ++I)
451 ++I;
452 #pragma omp parallel
453 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
454 #pragma omp for simd
455 for (GoodIter I(nullptr); I < end; ++I)
456 ++I;
457 #pragma omp parallel
458 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
459 #pragma omp for simd
460 for (GoodIter I(0); I < end; ++I)
461 ++I;
462 #pragma omp parallel
463 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
464 #pragma omp for simd
465 for (GoodIter I(1, 2); I < end; ++I)
466 ++I;
467 #pragma omp parallel
468 #pragma omp for simd
469 for (begin = GoodIter(0); begin < end; ++begin)
470 ++begin;
471 #pragma omp parallel
472 // expected-error@+3 {{invalid operands to binary expression ('GoodIter' and 'const Iter0')}}
473 // expected-error@+2 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}
474 #pragma omp for simd
475 for (begin = begin0; begin < end; ++begin)
476 ++begin;
477 #pragma omp parallel
478 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
479 #pragma omp for simd
480 for (++begin; begin < end; ++begin)
481 ++begin;
482 #pragma omp parallel
483 #pragma omp for simd
484 for (begin = end; begin < end; ++begin)
485 ++begin;
486 #pragma omp parallel
487 // 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'}}
488 #pragma omp for simd
489 for (GoodIter I = begin; I - I; ++I)
490 ++I;
491 #pragma omp parallel
492 // 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'}}
493 #pragma omp for simd
494 for (GoodIter I = begin; begin < end; ++I)
495 ++I;
496 #pragma omp parallel
497 // 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'}}
498 #pragma omp for simd
499 for (GoodIter I = begin; !I; ++I)
500 ++I;
501 #pragma omp parallel
502 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
503 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
504 #pragma omp for simd
505 for (GoodIter I = begin; I >= end; I = I + 1)
506 ++I;
507 #pragma omp parallel
508 #pragma omp for simd
509 for (GoodIter I = begin; I >= end; I = I - 1)
510 ++I;
511 #pragma omp parallel
512 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}}
513 #pragma omp for simd
514 for (GoodIter I = begin; I >= end; I = -I)
515 ++I;
516 #pragma omp parallel
517 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
518 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
519 #pragma omp for simd
520 for (GoodIter I = begin; I >= end; I = 2 + I)
521 ++I;
522 #pragma omp parallel
523 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}}
524 #pragma omp for simd
525 for (GoodIter I = begin; I >= end; I = 2 - I)
526 ++I;
527 #pragma omp parallel
528 // expected-error@+2 {{invalid operands to binary expression ('Iter0' and 'int')}}
529 #pragma omp for simd
530 for (Iter0 I = begin0; I < end0; ++I)
531 ++I;
532 #pragma omp parallel
533 // Initializer is constructor without params.
534 // expected-error@+3 {{invalid operands to binary expression ('Iter0' and 'int')}}
535 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
536 #pragma omp for simd
537 for (Iter0 I; I < end0; ++I)
538 ++I;
539 Iter1 begin1, end1;
540 #pragma omp parallel
541 // expected-error@+3 {{invalid operands to binary expression ('Iter1' and 'Iter1')}}
542 // expected-error@+2 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}
543 #pragma omp for simd
544 for (Iter1 I = begin1; I < end1; ++I)
545 ++I;
546 #pragma omp parallel
547 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
548 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
549 #pragma omp for simd
550 for (Iter1 I = begin1; I >= end1; ++I)
551 ++I;
552 #pragma omp parallel
553 // expected-error@+5 {{invalid operands to binary expression ('Iter1' and 'float')}}
554 // expected-error@+4 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}
555 // Initializer is constructor with all default params.
556 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
557 #pragma omp for simd
558 for (Iter1 I; I < end1; ++I) {
560 return 0;
563 template <typename IT, int ST>
564 class TC {
565 public:
566 int dotest_lt(IT begin, IT end) {
567 #pragma omp parallel
568 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
569 // expected-error@+2 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}}
570 #pragma omp for simd
571 for (IT I = begin; I < end; I = I + ST) {
572 ++I;
574 #pragma omp parallel
575 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
576 // expected-error@+2 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}}
577 #pragma omp for simd
578 for (IT I = begin; I <= end; I += ST) {
579 ++I;
581 #pragma omp parallel
582 #pragma omp for simd
583 for (IT I = begin; I < end; ++I) {
584 ++I;
588 static IT step() {
589 return IT(ST);
592 template <typename IT, int ST = 0>
593 int dotest_gt(IT begin, IT end) {
594 #pragma omp parallel
595 // expected-note@+3 2 {{loop step is expected to be negative due to this condition}}
596 // expected-error@+2 2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
597 #pragma omp for simd
598 for (IT I = begin; I >= end; I = I + ST) {
599 ++I;
601 #pragma omp parallel
602 // expected-note@+3 2 {{loop step is expected to be negative due to this condition}}
603 // expected-error@+2 2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
604 #pragma omp for simd
605 for (IT I = begin; I >= end; I += ST) {
606 ++I;
609 #pragma omp parallel
610 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
611 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
612 #pragma omp for simd
613 for (IT I = begin; I >= end; ++I) {
614 ++I;
617 #pragma omp parallel
618 #pragma omp for simd
619 for (IT I = begin; I < end; I += TC<int, ST>::step()) {
620 ++I;
624 void test_with_template() {
625 GoodIter begin, end;
626 TC<GoodIter, 100> t1;
627 TC<GoodIter, -100> t2;
628 t1.dotest_lt(begin, end);
629 t2.dotest_lt(begin, end); // expected-note {{in instantiation of member function 'TC<GoodIter, -100>::dotest_lt' requested here}}
630 dotest_gt(begin, end); // expected-note {{in instantiation of function template specialization 'dotest_gt<GoodIter, 0>' requested here}}
631 dotest_gt<unsigned, 10>(0, 100); // expected-note {{in instantiation of function template specialization 'dotest_gt<unsigned int, 10>' requested here}}
634 void test_loop_break() {
635 const int N = 100;
636 float a[N], b[N], c[N];
637 #pragma omp parallel
638 #pragma omp for simd
639 for (int i = 0; i < 10; i++) {
640 c[i] = a[i] + b[i];
641 for (int j = 0; j < 10; ++j) {
642 if (a[i] > b[j])
643 break; // OK in nested loop
645 switch (i) {
646 case 1:
647 b[i]++;
648 break;
649 default:
650 break;
652 if (c[i] > 10)
653 break; // expected-error {{'break' statement cannot be used in OpenMP for loop}}
655 if (c[i] > 11)
656 break; // expected-error {{'break' statement cannot be used in OpenMP for loop}}
659 #pragma omp parallel
660 #pragma omp for simd
661 for (int i = 0; i < 10; i++) {
662 for (int j = 0; j < 10; j++) {
663 c[i] = a[i] + b[i];
664 if (c[i] > 10) {
665 if (c[i] < 20) {
666 break; // OK
673 void test_loop_eh() {
674 const int N = 100;
675 float a[N], b[N], c[N];
676 #pragma omp parallel
677 #pragma omp for simd
678 for (int i = 0; i < 10; i++) {
679 c[i] = a[i] + b[i];
680 try { // expected-error {{'try' statement cannot be used in OpenMP simd region}}
681 for (int j = 0; j < 10; ++j) {
682 if (a[i] > b[j])
683 throw a[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
685 throw a[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
687 catch (float f) {
688 if (f > 0.1)
689 throw a[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
690 return; // expected-error {{cannot return from OpenMP region}}
692 switch (i) {
693 case 1:
694 b[i]++;
695 break;
696 default:
697 break;
699 for (int j = 0; j < 10; j++) {
700 if (c[i] > 10)
701 throw c[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
704 if (c[9] > 10)
705 throw c[9]; // OK
707 #pragma omp parallel
708 #pragma omp for simd
709 for (int i = 0; i < 10; ++i) {
710 struct S {
711 void g() { throw 0; }
716 void test_loop_firstprivate_lastprivate() {
717 S s(4);
718 #pragma omp parallel
719 #pragma omp for simd lastprivate(s) firstprivate(s)
720 for (int i = 0; i < 16; ++i)
724 void test_ordered() {
725 #pragma omp parallel
726 #pragma omp for simd ordered ordered // expected-error {{directive '#pragma omp for simd' cannot contain more than one 'ordered' clause}}
727 for (int i = 0; i < 16; ++i)
729 #pragma omp parallel
730 #pragma omp for simd ordered
731 for (int i = 0; i < 16; ++i)
733 #pragma omp parallel
734 // expected-error@+1 {{'ordered' clause with a parameter can not be specified in '#pragma omp for simd' directive}}
735 #pragma omp for simd ordered(1)
736 for (int i = 0; i < 16; ++i)
740 void test_nowait() {
741 #pragma omp parallel
742 #pragma omp for simd nowait nowait // expected-error {{directive '#pragma omp for simd' cannot contain more than one 'nowait' clause}}
743 for (int i = 0; i < 16; ++i)