Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / target_parallel_for_loop_messages.cpp
blobfbc2c44bea47cd41c0e7bab14705fe32557cb730
1 // RUN: %clang_cc1 -fsyntax-only -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify=expected,omp4 %s -Wno-openmp-mapping -Wuninitialized
2 // RUN: %clang_cc1 -fsyntax-only -fopenmp -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify=expected,omp5 %s -Wno-openmp-mapping -Wuninitialized
4 // RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -fopenmp-version=45 -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify=expected,omp4 %s -Wno-openmp-mapping -Wuninitialized
5 // RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify=expected,omp5 %s -Wno-openmp-mapping -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 target parallel for
28 for (int i = 0; i < 10; i += 1) {
29 c[i] = a[i] + b[i];
31 #pragma omp target parallel for
32 for (char i = 0; i < 10; i++) {
33 c[i] = a[i] + b[i];
35 #pragma omp target parallel for
36 for (char i = 0; i < 10; i += '\1') {
37 c[i] = a[i] + b[i];
39 #pragma omp target parallel for
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 target parallel for
45 for (long long i = 0; i < 10; i += 1.5) {
46 c[i] = a[i] + b[i];
48 #pragma omp target parallel for
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 target parallel for
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 target parallel for
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 target parallel for
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 target parallel for
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 target parallel for
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 target parallel for
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 target parallel for
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 target parallel for
89 for (c[ii] = 0; ii < 10; ++ii)
90 c[ii] = a[ii];
92 // Ok to skip parenthesises.
93 #pragma omp target parallel for
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 target parallel for
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 target parallel for
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 target parallel for
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 target parallel for
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 target parallel for
120 for (int i = 0;; i++)
121 c[i] = a[i];
123 // Ok.
124 #pragma omp target parallel for
125 for (int i = 11; i > 10; i--)
126 c[i] = a[i];
128 // Ok.
129 #pragma omp target parallel for
130 for (int i = 0; i < 10; ++i)
131 c[i] = a[i];
133 // Ok.
134 #pragma omp target parallel for
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 target parallel for
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 target parallel for
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 target parallel for
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 target parallel for
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 target parallel for
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 target parallel for
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 target parallel for
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 target parallel for
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 target parallel for
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 target parallel for
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 target parallel for
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 target parallel for
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 target parallel for
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 target parallel for
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 target parallel for
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 target parallel for
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 target parallel for
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 target parallel for
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 target parallel for
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 target parallel for' directive may not be firstprivate, predetermined as private}}
246 #pragma omp target parallel for firstprivate(ii)
247 for (ii = 0; ii < 10; ii++)
248 c[ii] = a[ii];
250 // expected-note@+2 {{defined as linear}}
251 // expected-error@+2 {{loop iteration variable in the associated loop of 'omp target parallel for' directive may not be linear, predetermined as private}}
252 #pragma omp target parallel for linear(ii)
253 for (ii = 0; ii < 10; ii++)
254 c[ii] = a[ii];
256 #pragma omp target parallel for private(ii)
257 for (ii = 0; ii < 10; ii++)
258 c[ii] = a[ii];
260 #pragma omp target parallel for lastprivate(ii)
261 for (ii = 0; ii < 10; ii++)
262 c[ii] = a[ii];
265 // expected-error@+2 {{loop iteration variable in the associated loop of 'omp target parallel for' directive may not be threadprivate or thread local, predetermined as private}}
266 #pragma omp target parallel for
267 for (sii = 0; sii < 10; sii += 1)
268 c[sii] = a[sii];
272 #pragma omp target parallel for
273 for (globalii = 0; globalii < 10; globalii += 1)
274 c[globalii] = a[globalii];
278 #pragma omp target parallel for collapse(2)
279 for (ii = 0; ii < 10; ii += 1)
280 for (globalii = 0; globalii < 10; globalii += 1)
281 c[globalii] += a[globalii] + ii;
284 // omp4-error@+2 {{statement after '#pragma omp target parallel for' must be a for loop}}
285 #pragma omp target parallel for
286 for (auto &item : a) {
287 item = item + 1;
290 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
291 // expected-error@+2 {{increment expression must cause 'i' to increase on each iteration of OpenMP for loop}}
292 #pragma omp target parallel for
293 for (unsigned i = 9; i < 10; i--) {
294 c[i] = a[i] + b[i];
297 int(*lb)[4] = nullptr;
298 #pragma omp target parallel for
299 for (int(*p)[4] = lb; p < lb + 8; ++p) {
302 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
303 #pragma omp target parallel for
304 for (int a{0}; a < 10; ++a) {
307 return 0;
310 // Iterators allowed in openmp for-loops.
311 namespace std {
312 struct random_access_iterator_tag {};
313 template <class Iter>
314 struct iterator_traits {
315 typedef typename Iter::difference_type difference_type;
316 typedef typename Iter::iterator_category iterator_category;
318 template <class Iter>
319 typename iterator_traits<Iter>::difference_type
320 distance(Iter first, Iter last) { return first - last; }
322 class Iter0 {
323 public:
324 Iter0() {}
325 Iter0(const Iter0 &) {}
326 Iter0 operator++() { return *this; }
327 Iter0 operator--() { return *this; }
328 bool operator<(Iter0 a) { return true; }
330 // expected-note@+2 {{candidate function not viable: no known conversion from 'GoodIter' to 'Iter0' for 1st argument}}
331 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'Iter0' for 1st argument}}
332 int operator-(Iter0 a, Iter0 b) { return 0; }
333 class Iter1 {
334 public:
335 Iter1(float f = 0.0f, double d = 0.0) {}
336 Iter1(const Iter1 &) {}
337 Iter1 operator++() { return *this; }
338 Iter1 operator--() { return *this; }
339 bool operator<(Iter1 a) { return true; }
340 bool operator>=(Iter1 a) { return false; }
342 class GoodIter {
343 public:
344 GoodIter() {}
345 GoodIter(const GoodIter &) {}
346 GoodIter(int fst, int snd) {}
347 GoodIter &operator=(const GoodIter &that) { return *this; }
348 GoodIter &operator=(const Iter0 &that) { return *this; }
349 GoodIter &operator+=(int x) { return *this; }
350 GoodIter &operator-=(int x) { return *this; }
351 explicit GoodIter(void *) {}
352 GoodIter operator++() { return *this; }
353 GoodIter operator--() { return *this; }
354 bool operator!() { return true; }
355 bool operator<(GoodIter a) { return true; }
356 bool operator<=(GoodIter a) { return true; }
357 bool operator>=(GoodIter a) { return false; }
358 typedef int difference_type;
359 typedef std::random_access_iterator_tag iterator_category;
361 // expected-note@+2 {{candidate function not viable: no known conversion from 'const Iter0' to 'GoodIter' for 2nd argument}}
362 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}}
363 int operator-(GoodIter a, GoodIter b) { return 0; }
364 // expected-note@+1 3 {{candidate function not viable: requires single argument 'a', but 2 arguments were provided}}
365 GoodIter operator-(GoodIter a) { return a; }
366 // expected-note@+2 {{candidate function not viable: no known conversion from 'const Iter0' to 'int' for 2nd argument}}
367 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}}
368 GoodIter operator-(GoodIter a, int v) { return GoodIter(); }
369 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter0' to 'GoodIter' for 1st argument}}
370 GoodIter operator+(GoodIter a, int v) { return GoodIter(); }
371 // expected-note@+2 {{candidate function not viable: no known conversion from 'GoodIter' to 'int' for 1st argument}}
372 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'int' for 1st argument}}
373 GoodIter operator-(int v, GoodIter a) { return GoodIter(); }
374 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter0' to 'int' for 1st argument}}
375 GoodIter operator+(int v, GoodIter a) { return GoodIter(); }
377 int test_with_random_access_iterator() {
378 GoodIter begin, end;
379 Iter0 begin0, end0;
380 #pragma omp target parallel for
381 for (GoodIter I = begin; I < end; ++I)
382 ++I;
383 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
384 #pragma omp target parallel for
385 for (GoodIter &I = begin; I < end; ++I)
386 ++I;
387 #pragma omp target parallel for
388 for (GoodIter I = begin; I >= end; --I)
389 ++I;
390 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
391 #pragma omp target parallel for
392 for (GoodIter I(begin); I < end; ++I)
393 ++I;
394 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
395 #pragma omp target parallel for
396 for (GoodIter I(nullptr); I < end; ++I)
397 ++I;
398 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
399 #pragma omp target parallel for
400 for (GoodIter I(0); I < end; ++I)
401 ++I;
402 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
403 #pragma omp target parallel for
404 for (GoodIter I(1, 2); I < end; ++I)
405 ++I;
406 #pragma omp target parallel for
407 for (begin = GoodIter(0); begin < end; ++begin)
408 ++begin;
409 // expected-error@+3 {{invalid operands to binary expression ('GoodIter' and 'const Iter0')}}
410 // expected-error@+2 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}
411 #pragma omp target parallel for
412 for (begin = begin0; begin < end; ++begin)
413 ++begin;
414 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
415 #pragma omp target parallel for
416 for (++begin; begin < end; ++begin)
417 ++begin;
418 #pragma omp target parallel for
419 for (begin = end; begin < end; ++begin)
420 ++begin;
421 // 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'}}
422 #pragma omp target parallel for
423 for (GoodIter I = begin; I - I; ++I)
424 ++I;
425 // 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'}}
426 #pragma omp target parallel for
427 for (GoodIter I = begin; begin < end; ++I)
428 ++I;
429 // 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'}}
430 #pragma omp target parallel for
431 for (GoodIter I = begin; !I; ++I)
432 ++I;
433 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
434 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
435 #pragma omp target parallel for
436 for (GoodIter I = begin; I >= end; I = I + 1)
437 ++I;
438 #pragma omp target parallel for
439 for (GoodIter I = begin; I >= end; I = I - 1)
440 ++I;
441 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}}
442 #pragma omp target parallel for
443 for (GoodIter I = begin; I >= end; I = -I)
444 ++I;
445 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
446 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
447 #pragma omp target parallel for
448 for (GoodIter I = begin; I >= end; I = 2 + I)
449 ++I;
450 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}}
451 #pragma omp target parallel for
452 for (GoodIter I = begin; I >= end; I = 2 - I)
453 ++I;
454 // expected-error@+2 {{invalid operands to binary expression ('Iter0' and 'int')}}
455 #pragma omp target parallel for
456 for (Iter0 I = begin0; I < end0; ++I)
457 ++I;
458 // Initializer is constructor without params.
459 // expected-error@+3 {{invalid operands to binary expression ('Iter0' and 'int')}}
460 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
461 #pragma omp target parallel for
462 for (Iter0 I; I < end0; ++I)
463 ++I;
464 Iter1 begin1, end1;
465 // expected-error@+3 {{invalid operands to binary expression ('Iter1' and 'Iter1')}}
466 // expected-error@+2 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}
467 #pragma omp target parallel for
468 for (Iter1 I = begin1; I < end1; ++I)
469 ++I;
470 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
471 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
472 #pragma omp target parallel for
473 for (Iter1 I = begin1; I >= end1; ++I)
474 ++I;
475 // expected-error@+5 {{invalid operands to binary expression ('Iter1' and 'float')}}
476 // expected-error@+4 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}
477 // Initializer is constructor with all default params.
478 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
479 #pragma omp target parallel for
480 for (Iter1 I; I < end1; ++I) {
482 return 0;
485 template <typename IT, int ST>
486 class TC {
487 public:
488 int dotest_lt(IT begin, IT end) {
489 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
490 // expected-error@+2 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}}
491 #pragma omp target parallel for
492 for (IT I = begin; I < end; I = I + ST) {
493 ++I;
495 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
496 // expected-error@+2 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}}
497 #pragma omp target parallel for
498 for (IT I = begin; I <= end; I += ST) {
499 ++I;
501 #pragma omp target parallel for
502 for (IT I = begin; I < end; ++I) {
503 ++I;
507 static IT step() {
508 return IT(ST);
511 template <typename IT, int ST = 0>
512 int dotest_gt(IT begin, IT end) {
513 // expected-note@+3 2 {{loop step is expected to be negative due to this condition}}
514 // expected-error@+2 2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
515 #pragma omp target parallel for
516 for (IT I = begin; I >= end; I = I + ST) {
517 ++I;
519 // expected-note@+3 2 {{loop step is expected to be negative due to this condition}}
520 // expected-error@+2 2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
521 #pragma omp target parallel for
522 for (IT I = begin; I >= end; I += ST) {
523 ++I;
526 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
527 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
528 #pragma omp target parallel for
529 for (IT I = begin; I >= end; ++I) {
530 ++I;
533 #pragma omp target parallel for
534 for (IT I = begin; I < end; I += TC<int, ST>::step()) {
535 ++I;
539 void test_with_template() {
540 GoodIter begin, end;
541 TC<GoodIter, 100> t1;
542 TC<GoodIter, -100> t2;
543 t1.dotest_lt(begin, end);
544 t2.dotest_lt(begin, end); // expected-note {{in instantiation of member function 'TC<GoodIter, -100>::dotest_lt' requested here}}
545 dotest_gt(begin, end); // expected-note {{in instantiation of function template specialization 'dotest_gt<GoodIter, 0>' requested here}}
546 dotest_gt<unsigned, 10>(0, 100); // expected-note {{in instantiation of function template specialization 'dotest_gt<unsigned int, 10>' requested here}}
549 void test_loop_break() {
550 const int N = 100;
551 float a[N], b[N], c[N];
552 #pragma omp target parallel for
553 for (int i = 0; i < 10; i++) {
554 c[i] = a[i] + b[i];
555 for (int j = 0; j < 10; ++j) {
556 if (a[i] > b[j])
557 break; // OK in nested loop
559 switch (i) {
560 case 1:
561 b[i]++;
562 break;
563 default:
564 break;
566 if (c[i] > 10)
567 break; // expected-error {{'break' statement cannot be used in OpenMP for loop}}
569 if (c[i] > 11)
570 break; // expected-error {{'break' statement cannot be used in OpenMP for loop}}
573 #pragma omp target parallel for
574 for (int i = 0; i < 10; i++) {
575 for (int j = 0; j < 10; j++) {
576 c[i] = a[i] + b[i];
577 if (c[i] > 10) {
578 if (c[i] < 20) {
579 break; // OK
586 void test_loop_eh() {
587 const int N = 100;
588 float a[N], b[N], c[N];
589 #pragma omp target parallel for
590 for (int i = 0; i < 10; i++) {
591 c[i] = a[i] + b[i];
592 try {
593 for (int j = 0; j < 10; ++j) {
594 if (a[i] > b[j])
595 throw a[i];
597 throw a[i];
598 } catch (float f) {
599 if (f > 0.1)
600 throw a[i];
601 return; // expected-error {{cannot return from OpenMP region}}
603 switch (i) {
604 case 1:
605 b[i]++;
606 break;
607 default:
608 break;
610 for (int j = 0; j < 10; j++) {
611 if (c[i] > 10)
612 throw c[i];
615 if (c[9] > 10)
616 throw c[9]; // OK
618 #pragma omp target parallel for
619 for (int i = 0; i < 10; ++i) {
620 struct S {
621 void g() { throw 0; }
626 void test_loop_firstprivate_lastprivate() {
627 S s(4);
628 #pragma omp target parallel for lastprivate(s) firstprivate(s)
629 for (int i = 0; i < 16; ++i)