Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / parallel_for_simd_loop_messages.cpp
blobf55453f6e8e15a11d155a97378b3694c7150e4ea
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 for simd
28 for (int i = 0; i < 10; i += 1) {
29 c[i] = a[i] + b[i];
31 #pragma omp parallel for simd
32 for (char i = 0; i < 10; i++) {
33 c[i] = a[i] + b[i];
35 #pragma omp parallel for simd
36 for (char i = 0; i < 10; i += '\1') {
37 c[i] = a[i] + b[i];
39 #pragma omp parallel for simd
40 for (long long i = 0; i < 10; i++) {
41 c[i] = a[i] + b[i];
43 // expected-error@+2 {{expression must have integral or unscoped enumeration type, not 'double'}}
44 #pragma omp parallel for simd
45 for (long long i = 0; i < 10; i += 1.5) {
46 c[i] = a[i] + b[i];
48 #pragma omp parallel for simd
49 for (long long i = 0; i < 'z'; i += 1u) {
50 c[i] = a[i] + b[i];
52 // expected-error@+2 {{variable must be of integer or random access iterator type}}
53 #pragma omp parallel for simd
54 for (float fi = 0; fi < 10.0; fi++) {
55 c[(int)fi] = a[(int)fi] + b[(int)fi];
57 // expected-error@+2 {{variable must be of integer or random access iterator type}}
58 #pragma omp parallel for simd
59 for (double fi = 0; fi < 10.0; fi++) {
60 c[(int)fi] = a[(int)fi] + b[(int)fi];
62 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
63 #pragma omp parallel for simd
64 for (int &ref = ii; ref < 10; ref++) {
66 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
67 #pragma omp parallel for simd
68 for (int i; i < 10; i++)
69 c[i] = a[i];
71 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
72 #pragma omp parallel for simd
73 for (int i = 0, j = 0; i < 10; ++i)
74 c[i] = a[i];
76 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
77 #pragma omp parallel for simd
78 for (; ii < 10; ++ii)
79 c[ii] = a[ii];
81 // expected-warning@+3 {{expression result unused}}
82 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
83 #pragma omp parallel for simd
84 for (ii + 1; ii < 10; ++ii)
85 c[ii] = a[ii];
87 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
88 #pragma omp parallel for simd
89 for (c[ii] = 0; ii < 10; ++ii)
90 c[ii] = a[ii];
92 // Ok to skip parenthesises.
93 #pragma omp parallel for simd
94 for (((ii)) = 0; ii < 10; ++ii)
95 c[ii] = a[ii];
97 // 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'}}
98 #pragma omp parallel for simd
99 for (int i = 0; i; i++)
100 c[i] = a[i];
102 // 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'}}
103 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'i'}}
104 #pragma omp parallel for simd
105 for (int i = 0; jj < kk; ii++)
106 c[i] = a[i];
108 // 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'}}
109 #pragma omp parallel for simd
110 for (int i = 0; !!i; i++)
111 c[i] = a[i];
113 // omp4-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}}
114 #pragma omp parallel for simd
115 for (int i = 0; i != 1; i++)
116 c[i] = a[i];
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 parallel for simd
120 for (int i = 0;; i++)
121 c[i] = a[i];
123 // Ok.
124 #pragma omp parallel for simd
125 for (int i = 11; i > 10; i--)
126 c[i] = a[i];
128 // Ok.
129 #pragma omp parallel for simd
130 for (int i = 0; i < 10; ++i)
131 c[i] = a[i];
133 // Ok.
134 #pragma omp parallel for simd
135 for (ii = 0; ii < 10; ++ii)
136 c[ii] = a[ii];
138 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
139 #pragma omp parallel for simd
140 for (ii = 0; ii < 10; ++jj)
141 c[ii] = a[jj];
143 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
144 #pragma omp parallel for simd
145 for (ii = 0; ii < 10; ++++ii)
146 c[ii] = a[ii];
148 // Ok but undefined behavior (in general, cannot check that incr
149 // is really loop-invariant).
150 #pragma omp parallel for simd
151 for (ii = 0; ii < 10; ii = ii + ii)
152 c[ii] = a[ii];
154 // expected-error@+2 {{expression must have integral or unscoped enumeration type, not 'float'}}
155 #pragma omp parallel for simd
156 for (ii = 0; ii < 10; ii = ii + 1.0f)
157 c[ii] = a[ii];
159 // Ok - step was converted to integer type.
160 #pragma omp parallel for simd
161 for (ii = 0; ii < 10; ii = ii + (int)1.1f)
162 c[ii] = a[ii];
164 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
165 #pragma omp parallel for simd
166 for (ii = 0; ii < 10; jj = ii + 2)
167 c[ii] = a[ii];
169 // expected-warning@+3 {{relational comparison result unused}}
170 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
171 #pragma omp parallel for simd
172 for (ii = 0; ii<10; jj> kk + 2)
173 c[ii] = a[ii];
175 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
176 #pragma omp parallel for simd
177 for (ii = 0; ii < 10;)
178 c[ii] = a[ii];
180 // expected-warning@+3 {{expression result unused}}
181 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
182 #pragma omp parallel for simd
183 for (ii = 0; ii < 10; !ii)
184 c[ii] = a[ii];
186 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
187 #pragma omp parallel for simd
188 for (ii = 0; ii < 10; ii ? ++ii : ++jj)
189 c[ii] = a[ii];
191 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
192 #pragma omp parallel for simd
193 for (ii = 0; ii < 10; ii = ii < 10)
194 c[ii] = a[ii];
196 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
197 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
198 #pragma omp parallel for simd
199 for (ii = 0; ii < 10; ii = ii + 0)
200 c[ii] = a[ii];
202 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
203 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
204 #pragma omp parallel for simd
205 for (ii = 0; ii < 10; ii = ii + (int)(0.8 - 0.45))
206 c[ii] = a[ii];
208 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
209 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
210 #pragma omp parallel for simd
211 for (ii = 0; (ii) < 10; ii -= 25)
212 c[ii] = a[ii];
214 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
215 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
216 #pragma omp parallel for simd
217 for (ii = 0; (ii < 10); ii -= 0)
218 c[ii] = a[ii];
220 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
221 // expected-error@+2 {{increment expression must cause 'ii' to decrease on each iteration of OpenMP for loop}}
222 #pragma omp parallel for simd
223 for (ii = 0; ii > 10; (ii += 0))
224 c[ii] = a[ii];
226 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
227 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
228 #pragma omp parallel for simd
229 for (ii = 0; ii < 10; (ii) = (1 - 1) + (ii))
230 c[ii] = a[ii];
232 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
233 // expected-error@+2 {{increment expression must cause 'ii' to decrease on each iteration of OpenMP for loop}}
234 #pragma omp parallel for simd
235 for ((ii = 0); ii > 10; (ii -= 0))
236 c[ii] = a[ii];
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 parallel for simd
241 for (ii = 0; (ii < 10); (ii -= 0))
242 c[ii] = a[ii];
244 // expected-note@+2 {{defined as firstprivate}}
245 // expected-error@+2 {{loop iteration variable in the associated loop of 'omp parallel for simd' directive may not be firstprivate, predetermined as linear}}
246 #pragma omp parallel for simd firstprivate(ii)
247 for (ii = 0; ii < 10; ii++)
248 c[ii] = a[ii];
250 #pragma omp parallel for simd linear(ii)
251 for (ii = 0; ii < 10; ii++)
252 c[ii] = a[ii];
254 // omp4-note@+2 {{defined as private}}
255 // omp4-error@+2 {{loop iteration variable in the associated loop of 'omp parallel for simd' directive may not be private, predetermined as linear}}
256 #pragma omp parallel for simd private(ii)
257 for (ii = 0; ii < 10; ii++)
258 c[ii] = a[ii];
260 // omp4-note@+2 {{defined as lastprivate}}
261 // omp4-error@+2 {{loop iteration variable in the associated loop of 'omp parallel for simd' directive may not be lastprivate, predetermined as linear}}
262 #pragma omp parallel for simd lastprivate(ii)
263 for (ii = 0; ii < 10; ii++)
264 c[ii] = a[ii];
267 // expected-error@+2 {{loop iteration variable in the associated loop of 'omp parallel for simd' directive may not be threadprivate or thread local, predetermined as linear}}
268 #pragma omp parallel for simd
269 for (sii = 0; sii < 10; sii += 1)
270 c[sii] = a[sii];
274 #pragma omp parallel for simd
275 for (globalii = 0; globalii < 10; globalii += 1)
276 c[globalii] = a[globalii];
280 #pragma omp parallel for simd collapse(2)
281 for (ii = 0; ii < 10; ii += 1)
282 for (globalii = 0; globalii < 10; globalii += 1)
283 c[globalii] += a[globalii] + ii;
286 // omp4-error@+2 {{statement after '#pragma omp parallel for simd' must be a for loop}}
287 #pragma omp parallel for simd
288 for (auto &item : a) {
289 item = item + 1;
292 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
293 // expected-error@+2 {{increment expression must cause 'i' to increase on each iteration of OpenMP for loop}}
294 #pragma omp parallel for simd
295 for (unsigned i = 9; i < 10; i--) {
296 c[i] = a[i] + b[i];
299 int(*lb)[4] = nullptr;
300 #pragma omp parallel for simd
301 for (int(*p)[4] = lb; p < lb + 8; ++p) {
304 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
305 #pragma omp parallel for simd
306 for (int a{0}; a < 10; ++a) {
309 return 0;
312 // Iterators allowed in openmp for-loops.
313 namespace std {
314 struct random_access_iterator_tag {};
315 template <class Iter>
316 struct iterator_traits {
317 typedef typename Iter::difference_type difference_type;
318 typedef typename Iter::iterator_category iterator_category;
320 template <class Iter>
321 typename iterator_traits<Iter>::difference_type
322 distance(Iter first, Iter last) { return first - last; }
324 class Iter0 {
325 public:
326 Iter0() {}
327 Iter0(const Iter0 &) {}
328 Iter0 operator++() { return *this; }
329 Iter0 operator--() { return *this; }
330 bool operator<(Iter0 a) { return true; }
332 // expected-note@+2 {{candidate function not viable: no known conversion from 'GoodIter' to 'Iter0' for 1st argument}}
333 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'Iter0' for 1st argument}}
334 int operator-(Iter0 a, Iter0 b) { return 0; }
335 class Iter1 {
336 public:
337 Iter1(float f = 0.0f, double d = 0.0) {}
338 Iter1(const Iter1 &) {}
339 Iter1 operator++() { return *this; }
340 Iter1 operator--() { return *this; }
341 bool operator<(Iter1 a) { return true; }
342 bool operator>=(Iter1 a) { return false; }
344 class GoodIter {
345 public:
346 GoodIter() {}
347 GoodIter(const GoodIter &) {}
348 GoodIter(int fst, int snd) {}
349 GoodIter &operator=(const GoodIter &that) { return *this; }
350 GoodIter &operator=(const Iter0 &that) { return *this; }
351 GoodIter &operator+=(int x) { return *this; }
352 explicit GoodIter(void *) {}
353 GoodIter operator++() { return *this; }
354 GoodIter operator--() { return *this; }
355 bool operator!() { return true; }
356 bool operator<(GoodIter a) { return true; }
357 bool operator<=(GoodIter a) { return true; }
358 bool operator>=(GoodIter a) { return false; }
359 typedef int difference_type;
360 typedef std::random_access_iterator_tag iterator_category;
362 // expected-note@+2 {{candidate function not viable: no known conversion from 'const Iter0' to 'GoodIter' for 2nd argument}}
363 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}}
364 int operator-(GoodIter a, GoodIter b) { return 0; }
365 // expected-note@+1 3 {{candidate function not viable: requires single argument 'a', but 2 arguments were provided}}
366 GoodIter operator-(GoodIter a) { return a; }
367 // expected-note@+2 {{candidate function not viable: no known conversion from 'const Iter0' to 'int' for 2nd argument}}
368 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}}
369 GoodIter operator-(GoodIter a, int v) { return GoodIter(); }
370 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter0' to 'GoodIter' for 1st argument}}
371 GoodIter operator+(GoodIter a, int v) { return GoodIter(); }
372 // expected-note@+2 {{candidate function not viable: no known conversion from 'GoodIter' to 'int' for 1st argument}}
373 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'int' for 1st argument}}
374 GoodIter operator-(int v, GoodIter a) { return GoodIter(); }
375 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter0' to 'int' for 1st argument}}
376 GoodIter operator+(int v, GoodIter a) { return GoodIter(); }
378 int test_with_random_access_iterator() {
379 GoodIter begin, end;
380 Iter0 begin0, end0;
381 #pragma omp parallel for simd
382 for (GoodIter I = begin; I < end; ++I)
383 ++I;
384 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
385 #pragma omp parallel for simd
386 for (GoodIter &I = begin; I < end; ++I)
387 ++I;
388 #pragma omp parallel for simd
389 for (GoodIter I = begin; I >= end; --I)
390 ++I;
391 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
392 #pragma omp parallel for simd
393 for (GoodIter I(begin); I < end; ++I)
394 ++I;
395 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
396 #pragma omp parallel for simd
397 for (GoodIter I(nullptr); I < end; ++I)
398 ++I;
399 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
400 #pragma omp parallel for simd
401 for (GoodIter I(0); I < end; ++I)
402 ++I;
403 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
404 #pragma omp parallel for simd
405 for (GoodIter I(1, 2); I < end; ++I)
406 ++I;
407 #pragma omp parallel for simd
408 for (begin = GoodIter(0); begin < end; ++begin)
409 ++begin;
410 // expected-error@+3 {{invalid operands to binary expression ('GoodIter' and 'const Iter0')}}
411 // expected-error@+2 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}
412 #pragma omp parallel for simd
413 for (begin = begin0; begin < end; ++begin)
414 ++begin;
415 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
416 #pragma omp parallel for simd
417 for (++begin; begin < end; ++begin)
418 ++begin;
419 #pragma omp parallel for simd
420 for (begin = end; begin < end; ++begin)
421 ++begin;
422 // 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'}}
423 #pragma omp parallel for simd
424 for (GoodIter I = begin; I - I; ++I)
425 ++I;
426 // 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'}}
427 #pragma omp parallel for simd
428 for (GoodIter I = begin; begin < end; ++I)
429 ++I;
430 // 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'}}
431 #pragma omp parallel for simd
432 for (GoodIter I = begin; !I; ++I)
433 ++I;
434 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
435 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
436 #pragma omp parallel for simd
437 for (GoodIter I = begin; I >= end; I = I + 1)
438 ++I;
439 #pragma omp parallel for simd
440 for (GoodIter I = begin; I >= end; I = I - 1)
441 ++I;
442 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}}
443 #pragma omp parallel for simd
444 for (GoodIter I = begin; I >= end; I = -I)
445 ++I;
446 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
447 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
448 #pragma omp parallel for simd
449 for (GoodIter I = begin; I >= end; I = 2 + I)
450 ++I;
451 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}}
452 #pragma omp parallel for simd
453 for (GoodIter I = begin; I >= end; I = 2 - I)
454 ++I;
455 // expected-error@+2 {{invalid operands to binary expression ('Iter0' and 'int')}}
456 #pragma omp parallel for simd
457 for (Iter0 I = begin0; I < end0; ++I)
458 ++I;
459 // Initializer is constructor without params.
460 // expected-error@+3 {{invalid operands to binary expression ('Iter0' and 'int')}}
461 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
462 #pragma omp parallel for simd
463 for (Iter0 I; I < end0; ++I)
464 ++I;
465 Iter1 begin1, end1;
466 // expected-error@+3 {{invalid operands to binary expression ('Iter1' and 'Iter1')}}
467 // expected-error@+2 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}
468 #pragma omp parallel for simd
469 for (Iter1 I = begin1; I < end1; ++I)
470 ++I;
471 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
472 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
473 #pragma omp parallel for simd
474 for (Iter1 I = begin1; I >= end1; ++I)
475 ++I;
476 // expected-error@+5 {{invalid operands to binary expression ('Iter1' and 'float')}}
477 // expected-error@+4 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}
478 // Initializer is constructor with all default params.
479 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
480 #pragma omp parallel for simd
481 for (Iter1 I; I < end1; ++I) {
483 return 0;
486 template <typename IT, int ST>
487 class TC {
488 public:
489 int dotest_lt(IT begin, IT end) {
490 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
491 // expected-error@+2 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}}
492 #pragma omp parallel for simd
493 for (IT I = begin; I < end; I = I + ST) {
494 ++I;
496 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
497 // expected-error@+2 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}}
498 #pragma omp parallel for simd
499 for (IT I = begin; I <= end; I += ST) {
500 ++I;
502 #pragma omp parallel for simd
503 for (IT I = begin; I < end; ++I) {
504 ++I;
508 static IT step() {
509 return IT(ST);
512 template <typename IT, int ST = 0>
513 int dotest_gt(IT begin, IT end) {
514 // expected-note@+3 2 {{loop step is expected to be negative due to this condition}}
515 // expected-error@+2 2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
516 #pragma omp parallel for simd
517 for (IT I = begin; I >= end; I = I + ST) {
518 ++I;
520 // expected-note@+3 2 {{loop step is expected to be negative due to this condition}}
521 // expected-error@+2 2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
522 #pragma omp parallel for simd
523 for (IT I = begin; I >= end; I += ST) {
524 ++I;
527 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
528 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
529 #pragma omp parallel for simd
530 for (IT I = begin; I >= end; ++I) {
531 ++I;
534 #pragma omp parallel for simd
535 for (IT I = begin; I < end; I += TC<int, ST>::step()) {
536 ++I;
540 void test_with_template() {
541 GoodIter begin, end;
542 TC<GoodIter, 100> t1;
543 TC<GoodIter, -100> t2;
544 t1.dotest_lt(begin, end);
545 t2.dotest_lt(begin, end); // expected-note {{in instantiation of member function 'TC<GoodIter, -100>::dotest_lt' requested here}}
546 dotest_gt(begin, end); // expected-note {{in instantiation of function template specialization 'dotest_gt<GoodIter, 0>' requested here}}
547 dotest_gt<unsigned, 10>(0, 100); // expected-note {{in instantiation of function template specialization 'dotest_gt<unsigned int, 10>' requested here}}
550 void test_loop_break() {
551 const int N = 100;
552 float a[N], b[N], c[N];
553 #pragma omp parallel for simd
554 for (int i = 0; i < 10; i++) {
555 c[i] = a[i] + b[i];
556 for (int j = 0; j < 10; ++j) {
557 if (a[i] > b[j])
558 break; // OK in nested loop
560 switch (i) {
561 case 1:
562 b[i]++;
563 break;
564 default:
565 break;
567 if (c[i] > 10)
568 break; // expected-error {{'break' statement cannot be used in OpenMP for loop}}
570 if (c[i] > 11)
571 break; // expected-error {{'break' statement cannot be used in OpenMP for loop}}
574 #pragma omp parallel for simd
575 for (int i = 0; i < 10; i++) {
576 for (int j = 0; j < 10; j++) {
577 c[i] = a[i] + b[i];
578 if (c[i] > 10) {
579 if (c[i] < 20) {
580 break; // OK
587 void test_loop_eh() {
588 const int N = 100;
589 float a[N], b[N], c[N];
590 #pragma omp parallel for simd
591 for (int i = 0; i < 10; i++) {
592 c[i] = a[i] + b[i];
593 try { // expected-error {{'try' statement cannot be used in OpenMP simd region}}
594 for (int j = 0; j < 10; ++j) {
595 if (a[i] > b[j])
596 throw a[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
598 throw a[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
599 } catch (float f) {
600 if (f > 0.1)
601 throw a[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
602 return; // expected-error {{cannot return from OpenMP region}}
604 switch (i) {
605 case 1:
606 b[i]++;
607 break;
608 default:
609 break;
611 for (int j = 0; j < 10; j++) {
612 if (c[i] > 10)
613 throw c[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
616 if (c[9] > 10)
617 throw c[9]; // OK
619 #pragma omp parallel for simd
620 for (int i = 0; i < 10; ++i) {
621 struct S {
622 void g() { throw 0; }
627 void test_loop_firstprivate_lastprivate() {
628 S s(4);
629 #pragma omp parallel for simd lastprivate(s) firstprivate(s)
630 for (int i = 0; i < 16; ++i)
634 void test_ordered() {
635 #pragma omp parallel for simd ordered ordered // expected-error {{directive '#pragma omp parallel for simd' cannot contain more than one 'ordered' clause}}
636 for (int i = 0; i < 16; ++i)
638 #pragma omp parallel for simd ordered
639 for (int i = 0; i < 16; ++i)
641 //expected-error@+1 {{'ordered' clause with a parameter can not be specified in '#pragma omp parallel for simd' directive}}
642 #pragma omp parallel for simd ordered(1)
643 for (int i = 0; i < 16; ++i)
647 void test_nowait() {
648 // expected-error@+1 2 {{unexpected OpenMP clause 'nowait' in directive '#pragma omp parallel for simd'}}
649 #pragma omp parallel for simd nowait nowait // expected-error {{directive '#pragma omp parallel for simd' cannot contain more than one 'nowait' clause}}
650 for (int i = 0; i < 16; ++i)