Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / target_parallel_for_simd_loop_messages.cpp
blob18377a6f578f46de738272593e2bda7e23f4fcec
1 // RUN: %clang_cc1 -fsyntax-only -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify=expected,omp45 %s -Wno-openmp-mapping -Wuninitialized
2 // RUN: %clang_cc1 -fsyntax-only -fopenmp -fopenmp-version=50 -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify=expected,omp50 %s -Wno-openmp-mapping -Wuninitialized
3 // RUN: %clang_cc1 -fsyntax-only -fopenmp -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify=expected,omp51 %s -Wno-openmp-mapping -Wuninitialized
5 // RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -fopenmp-version=45 -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify=expected,omp45 %s -Wno-openmp-mapping -Wuninitialized
6 // RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -fopenmp-version=50 -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify=expected,omp50 %s -Wno-openmp-mapping -Wuninitialized
7 // RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify=expected,omp51 %s -Wno-openmp-mapping -Wuninitialized
9 class S {
10 int a;
11 S() : a(0) {}
13 public:
14 S(int v) : a(v) {}
15 S(const S &s) : a(s.a) {}
18 static int sii;
19 // expected-note@+1 {{defined as threadprivate or thread local}}
20 #pragma omp threadprivate(sii)
21 static int globalii;
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 #pragma omp target parallel for simd
30 for (int i = 0; i < 10; i += 1) {
31 c[i] = a[i] + b[i];
33 #pragma omp target parallel for simd
34 for (char i = 0; i < 10; i++) {
35 c[i] = a[i] + b[i];
37 #pragma omp target parallel for simd
38 for (char i = 0; i < 10; i += '\1') {
39 c[i] = a[i] + b[i];
41 #pragma omp target parallel for simd
42 for (long long i = 0; i < 10; i++) {
43 c[i] = a[i] + b[i];
45 // expected-error@+2 {{expression must have integral or unscoped enumeration type, not 'double'}}
46 #pragma omp target parallel for simd
47 for (long long i = 0; i < 10; i += 1.5) {
48 c[i] = a[i] + b[i];
50 #pragma omp target parallel for simd
51 for (long long i = 0; i < 'z'; i += 1u) {
52 c[i] = a[i] + b[i];
54 // expected-error@+2 {{variable must be of integer or random access iterator type}}
55 #pragma omp target parallel for simd
56 for (float fi = 0; fi < 10.0; fi++) {
57 c[(int)fi] = a[(int)fi] + b[(int)fi];
59 // expected-error@+2 {{variable must be of integer or random access iterator type}}
60 #pragma omp target parallel for simd
61 for (double fi = 0; fi < 10.0; fi++) {
62 c[(int)fi] = a[(int)fi] + b[(int)fi];
64 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
65 #pragma omp target parallel for simd
66 for (int &ref = ii; ref < 10; ref++) {
68 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
69 #pragma omp target parallel for simd
70 for (int i; i < 10; i++)
71 c[i] = a[i];
73 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
74 #pragma omp target parallel for simd
75 for (int i = 0, j = 0; i < 10; ++i)
76 c[i] = a[i];
78 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
79 #pragma omp target parallel for simd
80 for (; ii < 10; ++ii)
81 c[ii] = a[ii];
83 // expected-warning@+3 {{expression result unused}}
84 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
85 #pragma omp target parallel for simd
86 for (ii + 1; ii < 10; ++ii)
87 c[ii] = a[ii];
89 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
90 #pragma omp target parallel for simd
91 for (c[ii] = 0; ii < 10; ++ii)
92 c[ii] = a[ii];
94 // Ok to skip parenthesises.
95 #pragma omp target parallel for simd
96 for (((ii)) = 0; ii < 10; ++ii)
97 c[ii] = a[ii];
99 // omp45-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}} omp50-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'i'}} omp51-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'i'}}
100 #pragma omp target parallel for simd
101 for (int i = 0; i; i++)
102 c[i] = a[i];
104 // omp45-error@+3 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}} omp50-error@+3 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'i'}} omp51-error@+3 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'i'}}
105 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'i'}}
106 #pragma omp target parallel for simd
107 for (int i = 0; jj < kk; ii++)
108 c[i] = a[i];
110 // omp45-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}} omp50-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'i'}} omp51-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'i'}}
111 #pragma omp target parallel for simd
112 for (int i = 0; !!i; i++)
113 c[i] = a[i];
115 // omp45-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}}
116 #pragma omp target parallel for simd
117 for (int i = 0; i != 1; i++)
118 c[i] = a[i];
120 // omp45-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}} omp50-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'i'}} omp51-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'i'}}
121 #pragma omp target parallel for simd
122 for (int i = 0;; i++)
123 c[i] = a[i];
125 // Ok.
126 #pragma omp target parallel for simd
127 for (int i = 11; i > 10; i--)
128 c[i] = a[i];
130 // Ok.
131 #pragma omp target parallel for simd
132 for (int i = 0; i < 10; ++i)
133 c[i] = a[i];
135 // Ok.
136 #pragma omp target parallel for simd
137 for (ii = 0; ii < 10; ++ii)
138 c[ii] = a[ii];
140 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
141 #pragma omp target parallel for simd
142 for (ii = 0; ii < 10; ++jj)
143 c[ii] = a[jj];
145 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
146 #pragma omp target parallel for simd
147 for (ii = 0; ii < 10; ++++ii)
148 c[ii] = a[ii];
150 // Ok but undefined behavior (in general, cannot check that incr
151 // is really loop-invariant).
152 #pragma omp target parallel for simd
153 for (ii = 0; ii < 10; ii = ii + ii)
154 c[ii] = a[ii];
156 // expected-error@+2 {{expression must have integral or unscoped enumeration type, not 'float'}}
157 #pragma omp target parallel for simd
158 for (ii = 0; ii < 10; ii = ii + 1.0f)
159 c[ii] = a[ii];
161 // Ok - step was converted to integer type.
162 #pragma omp target parallel for simd
163 for (ii = 0; ii < 10; ii = ii + (int)1.1f)
164 c[ii] = a[ii];
166 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
167 #pragma omp target parallel for simd
168 for (ii = 0; ii < 10; jj = ii + 2)
169 c[ii] = a[ii];
171 // expected-warning@+3 {{relational comparison result unused}}
172 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
173 #pragma omp target parallel for simd
174 for (ii = 0; ii<10; jj> kk + 2)
175 c[ii] = a[ii];
177 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
178 #pragma omp target parallel for simd
179 for (ii = 0; ii < 10;)
180 c[ii] = a[ii];
182 // expected-warning@+3 {{expression result unused}}
183 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
184 #pragma omp target parallel for simd
185 for (ii = 0; ii < 10; !ii)
186 c[ii] = a[ii];
188 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
189 #pragma omp target parallel for simd
190 for (ii = 0; ii < 10; ii ? ++ii : ++jj)
191 c[ii] = a[ii];
193 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
194 #pragma omp target parallel for simd
195 for (ii = 0; ii < 10; ii = ii < 10)
196 c[ii] = a[ii];
198 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
199 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
200 #pragma omp target parallel for simd
201 for (ii = 0; ii < 10; ii = ii + 0)
202 c[ii] = a[ii];
204 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
205 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
206 #pragma omp target parallel for simd
207 for (ii = 0; ii < 10; ii = ii + (int)(0.8 - 0.45))
208 c[ii] = a[ii];
210 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
211 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
212 #pragma omp target parallel for simd
213 for (ii = 0; (ii) < 10; ii -= 25)
214 c[ii] = a[ii];
216 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
217 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
218 #pragma omp target parallel for simd
219 for (ii = 0; (ii < 10); ii -= 0)
220 c[ii] = a[ii];
222 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
223 // expected-error@+2 {{increment expression must cause 'ii' to decrease on each iteration of OpenMP for loop}}
224 #pragma omp target parallel for simd
225 for (ii = 0; ii > 10; (ii += 0))
226 c[ii] = a[ii];
228 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
229 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
230 #pragma omp target parallel for simd
231 for (ii = 0; ii < 10; (ii) = (1 - 1) + (ii))
232 c[ii] = a[ii];
234 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
235 // expected-error@+2 {{increment expression must cause 'ii' to decrease on each iteration of OpenMP for loop}}
236 #pragma omp target parallel for simd
237 for ((ii = 0); ii > 10; (ii -= 0))
238 c[ii] = a[ii];
240 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
241 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
242 #pragma omp target parallel for simd
243 for (ii = 0; (ii < 10); (ii -= 0))
244 c[ii] = a[ii];
246 // expected-note@+2 {{defined as firstprivate}}
247 // expected-error@+2 {{loop iteration variable in the associated loop of 'omp target parallel for simd' directive may not be firstprivate, predetermined as linear}}
248 #pragma omp target parallel for simd firstprivate(ii)
249 for (ii = 0; ii < 10; ii++)
250 c[ii] = a[ii];
252 #pragma omp target parallel for simd linear(ii)
253 for (ii = 0; ii < 10; ii++)
254 c[ii] = a[ii];
256 // omp45-note@+2 {{defined as private}}
257 // omp45-error@+2 {{loop iteration variable in the associated loop of 'omp target parallel for simd' directive may not be private, predetermined as linear}}
258 #pragma omp target parallel for simd private(ii)
259 for (ii = 0; ii < 10; ii++)
260 c[ii] = a[ii];
262 // omp45-note@+2 {{defined as lastprivate}}
263 // omp45-error@+2 {{loop iteration variable in the associated loop of 'omp target parallel for simd' directive may not be lastprivate, predetermined as linear}}
264 #pragma omp target parallel for simd lastprivate(ii)
265 for (ii = 0; ii < 10; ii++)
266 c[ii] = a[ii];
269 // expected-error@+2 {{loop iteration variable in the associated loop of 'omp target parallel for simd' directive may not be threadprivate or thread local, predetermined as linear}}
270 #pragma omp target parallel for simd
271 for (sii = 0; sii < 10; sii += 1)
272 c[sii] = a[sii];
276 #pragma omp target parallel for simd
277 for (globalii = 0; globalii < 10; globalii += 1)
278 c[globalii] = a[globalii];
282 #pragma omp target parallel for simd collapse(2)
283 for (ii = 0; ii < 10; ii += 1)
284 for (globalii = 0; globalii < 10; globalii += 1)
285 c[globalii] += a[globalii] + ii;
288 // omp45-error@+2 {{statement after '#pragma omp target parallel for simd' must be a for loop}}
289 #pragma omp target parallel for simd
290 for (auto &item : a) {
291 item = item + 1;
294 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
295 // expected-error@+2 {{increment expression must cause 'i' to increase on each iteration of OpenMP for loop}}
296 #pragma omp target parallel for simd
297 for (unsigned i = 9; i < 10; i--) {
298 c[i] = a[i] + b[i];
301 int(*lb)[4] = nullptr;
302 #pragma omp target parallel for simd
303 for (int(*p)[4] = lb; p < lb + 8; ++p) {
306 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
307 #pragma omp target parallel for simd
308 for (int a{0}; a < 10; ++a) {
311 return 0;
314 // Iterators allowed in openmp for-loops.
315 namespace std {
316 struct random_access_iterator_tag {};
317 template <class Iter>
318 struct iterator_traits {
319 typedef typename Iter::difference_type difference_type;
320 typedef typename Iter::iterator_category iterator_category;
322 template <class Iter>
323 typename iterator_traits<Iter>::difference_type
324 distance(Iter first, Iter last) { return first - last; }
326 class Iter0 {
327 public:
328 Iter0() {}
329 Iter0(const Iter0 &) {}
330 Iter0 operator++() { return *this; }
331 Iter0 operator--() { return *this; }
332 bool operator<(Iter0 a) { return true; }
334 // expected-note@+2 {{candidate function not viable: no known conversion from 'GoodIter' to 'Iter0' for 1st argument}}
335 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'Iter0' for 1st argument}}
336 int operator-(Iter0 a, Iter0 b) { return 0; }
337 class Iter1 {
338 public:
339 Iter1(float f = 0.0f, double d = 0.0) {}
340 Iter1(const Iter1 &) {}
341 Iter1 operator++() { return *this; }
342 Iter1 operator--() { return *this; }
343 bool operator<(Iter1 a) { return true; }
344 bool operator>=(Iter1 a) { return false; }
346 class GoodIter {
347 public:
348 GoodIter() {}
349 GoodIter(const GoodIter &) {}
350 GoodIter(int fst, int snd) {}
351 GoodIter &operator=(const GoodIter &that) { return *this; }
352 GoodIter &operator=(const Iter0 &that) { return *this; }
353 GoodIter &operator+=(int x) { return *this; }
354 GoodIter &operator-=(int x) { return *this; }
355 explicit GoodIter(void *) {}
356 GoodIter operator++() { return *this; }
357 GoodIter operator--() { return *this; }
358 bool operator!() { return true; }
359 bool operator<(GoodIter a) { return true; }
360 bool operator<=(GoodIter a) { return true; }
361 bool operator>=(GoodIter a) { return false; }
362 typedef int difference_type;
363 typedef std::random_access_iterator_tag iterator_category;
365 // expected-note@+2 {{candidate function not viable: no known conversion from 'const Iter0' to 'GoodIter' for 2nd argument}}
366 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}}
367 int operator-(GoodIter a, GoodIter b) { return 0; }
368 // expected-note@+1 3 {{candidate function not viable: requires single argument 'a', but 2 arguments were provided}}
369 GoodIter operator-(GoodIter a) { return a; }
370 // expected-note@+2 {{candidate function not viable: no known conversion from 'const Iter0' to 'int' for 2nd argument}}
371 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}}
372 GoodIter operator-(GoodIter a, int v) { return GoodIter(); }
373 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter0' to 'GoodIter' for 1st argument}}
374 GoodIter operator+(GoodIter a, int v) { return GoodIter(); }
375 // expected-note@+2 {{candidate function not viable: no known conversion from 'GoodIter' to 'int' for 1st argument}}
376 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'int' for 1st argument}}
377 GoodIter operator-(int v, GoodIter a) { return GoodIter(); }
378 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter0' to 'int' for 1st argument}}
379 GoodIter operator+(int v, GoodIter a) { return GoodIter(); }
381 int test_with_random_access_iterator() {
382 GoodIter begin, end;
383 Iter0 begin0, end0;
384 #pragma omp target parallel for simd
385 for (GoodIter I = begin; I < end; ++I)
386 ++I;
387 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
388 #pragma omp target parallel for simd
389 for (GoodIter &I = begin; I < end; ++I)
390 ++I;
391 #pragma omp target parallel for simd
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 simd
396 for (GoodIter I(begin); 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 simd
400 for (GoodIter I(nullptr); 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 simd
404 for (GoodIter I(0); I < end; ++I)
405 ++I;
406 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
407 #pragma omp target parallel for simd
408 for (GoodIter I(1, 2); I < end; ++I)
409 ++I;
410 #pragma omp target parallel for simd
411 for (begin = GoodIter(0); begin < end; ++begin)
412 ++begin;
413 // expected-error@+3 {{invalid operands to binary expression ('GoodIter' and 'const Iter0')}}
414 // expected-error@+2 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}
415 #pragma omp target parallel for simd
416 for (begin = begin0; begin < end; ++begin)
417 ++begin;
418 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
419 #pragma omp target parallel for simd
420 for (++begin; begin < end; ++begin)
421 ++begin;
422 #pragma omp target parallel for simd
423 for (begin = end; begin < end; ++begin)
424 ++begin;
425 // omp45-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'I'}} omp50-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'I'}} omp51-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'I'}}
426 #pragma omp target parallel for simd
427 for (GoodIter I = begin; I - I; ++I)
428 ++I;
429 // omp45-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'I'}} omp50-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'I'}} omp51-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'I'}}
430 #pragma omp target parallel for simd
431 for (GoodIter I = begin; begin < end; ++I)
432 ++I;
433 // omp45-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'I'}} omp50-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'I'}} omp51-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'I'}}
434 #pragma omp target parallel for simd
435 for (GoodIter I = begin; !I; ++I)
436 ++I;
437 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
438 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
439 #pragma omp target parallel for simd
440 for (GoodIter I = begin; I >= end; I = I + 1)
441 ++I;
442 #pragma omp target parallel for simd
443 for (GoodIter I = begin; I >= end; I = I - 1)
444 ++I;
445 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}}
446 #pragma omp target parallel for simd
447 for (GoodIter I = begin; I >= end; I = -I)
448 ++I;
449 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
450 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
451 #pragma omp target parallel for simd
452 for (GoodIter I = begin; I >= end; I = 2 + I)
453 ++I;
454 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}}
455 #pragma omp target parallel for simd
456 for (GoodIter I = begin; I >= end; I = 2 - I)
457 ++I;
458 // expected-error@+2 {{invalid operands to binary expression ('Iter0' and 'int')}}
459 #pragma omp target parallel for simd
460 for (Iter0 I = begin0; I < end0; ++I)
461 ++I;
462 // Initializer is constructor without params.
463 // expected-error@+3 {{invalid operands to binary expression ('Iter0' and 'int')}}
464 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
465 #pragma omp target parallel for simd
466 for (Iter0 I; I < end0; ++I)
467 ++I;
468 Iter1 begin1, end1;
469 // expected-error@+3 {{invalid operands to binary expression ('Iter1' and 'Iter1')}}
470 // expected-error@+2 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}
471 #pragma omp target parallel for simd
472 for (Iter1 I = begin1; I < end1; ++I)
473 ++I;
474 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
475 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
476 #pragma omp target parallel for simd
477 for (Iter1 I = begin1; I >= end1; ++I)
478 ++I;
479 // expected-error@+5 {{invalid operands to binary expression ('Iter1' and 'float')}}
480 // expected-error@+4 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}
481 // Initializer is constructor with all default params.
482 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
483 #pragma omp target parallel for simd
484 for (Iter1 I; I < end1; ++I) {
486 return 0;
489 template <typename IT, int ST>
490 class TC {
491 public:
492 int dotest_lt(IT begin, IT end) {
493 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
494 // expected-error@+2 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}}
495 #pragma omp target parallel for simd
496 for (IT I = begin; I < end; I = I + ST) {
497 ++I;
499 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
500 // expected-error@+2 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}}
501 #pragma omp target parallel for simd
502 for (IT I = begin; I <= end; I += ST) {
503 ++I;
505 #pragma omp target parallel for simd
506 for (IT I = begin; I < end; ++I) {
507 ++I;
511 static IT step() {
512 return IT(ST);
515 template <typename IT, int ST = 0>
516 int dotest_gt(IT begin, IT end) {
517 // expected-note@+3 2 {{loop step is expected to be negative due to this condition}}
518 // expected-error@+2 2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
519 #pragma omp target parallel for simd
520 for (IT I = begin; I >= end; I = I + ST) {
521 ++I;
523 // expected-note@+3 2 {{loop step is expected to be negative due to this condition}}
524 // expected-error@+2 2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
525 #pragma omp target parallel for simd
526 for (IT I = begin; I >= end; I += ST) {
527 ++I;
530 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
531 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
532 #pragma omp target parallel for simd
533 for (IT I = begin; I >= end; ++I) {
534 ++I;
537 #pragma omp target parallel for simd
538 for (IT I = begin; I < end; I += TC<int, ST>::step()) {
539 ++I;
543 void test_with_template() {
544 GoodIter begin, end;
545 TC<GoodIter, 100> t1;
546 TC<GoodIter, -100> t2;
547 t1.dotest_lt(begin, end);
548 t2.dotest_lt(begin, end); // expected-note {{in instantiation of member function 'TC<GoodIter, -100>::dotest_lt' requested here}}
549 dotest_gt(begin, end); // expected-note {{in instantiation of function template specialization 'dotest_gt<GoodIter, 0>' requested here}}
550 dotest_gt<unsigned, 10>(0, 100); // expected-note {{in instantiation of function template specialization 'dotest_gt<unsigned int, 10>' requested here}}
553 void test_loop_break() {
554 const int N = 100;
555 float a[N], b[N], c[N];
556 #pragma omp target parallel for simd
557 for (int i = 0; i < 10; i++) {
558 c[i] = a[i] + b[i];
559 for (int j = 0; j < 10; ++j) {
560 if (a[i] > b[j])
561 break; // OK in nested loop
563 switch (i) {
564 case 1:
565 b[i]++;
566 break;
567 default:
568 break;
570 if (c[i] > 10)
571 break; // expected-error {{'break' statement cannot be used in OpenMP for loop}}
573 if (c[i] > 11)
574 break; // expected-error {{'break' statement cannot be used in OpenMP for loop}}
577 #pragma omp target parallel for simd
578 for (int i = 0; i < 10; i++) {
579 for (int j = 0; j < 10; j++) {
580 c[i] = a[i] + b[i];
581 if (c[i] > 10) {
582 if (c[i] < 20) {
583 break; // OK
590 void test_loop_eh() {
591 const int N = 100;
592 float a[N], b[N], c[N];
593 #pragma omp target parallel for simd
594 for (int i = 0; i < 10; i++) {
595 c[i] = a[i] + b[i];
596 try { // expected-error {{'try' statement cannot be used in OpenMP simd region}}
597 for (int j = 0; j < 10; ++j) {
598 if (a[i] > b[j])
599 throw a[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
601 throw a[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
602 } catch (float f) {
603 if (f > 0.1)
604 throw a[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
605 return; // expected-error {{cannot return from OpenMP region}}
607 switch (i) {
608 case 1:
609 b[i]++;
610 break;
611 default:
612 break;
614 for (int j = 0; j < 10; j++) {
615 if (c[i] > 10)
616 throw c[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
619 if (c[9] > 10)
620 throw c[9]; // OK
622 #pragma omp target parallel for simd
623 for (int i = 0; i < 10; ++i) {
624 struct S {
625 void g() { throw 0; }
630 void test_loop_firstprivate_lastprivate() {
631 S s(4);
632 #pragma omp target parallel for simd lastprivate(s) firstprivate(s)
633 for (int i = 0; i < 16; ++i)
635 #pragma omp target parallel for simd order // omp45-error {{unexpected OpenMP clause 'order' in directive '#pragma omp target parallel for simd'}} expected-error {{expected '(' after 'order'}}
636 for (int i = 0; i < 10; ++i)
638 #pragma omp target parallel for simd order( // omp45-error {{unexpected OpenMP clause 'order' in directive '#pragma omp target parallel for simd'}} expected-error {{expected ')'}} expected-note {{to match this '('}} omp50-error {{expected 'concurrent' in OpenMP clause 'order'}} omp51-error {{expected 'concurrent' in OpenMP clause 'order'}}
639 for (int i = 0; i < 10; ++i)
641 #pragma omp target parallel for simd order(none // omp45-error {{unexpected OpenMP clause 'order' in directive '#pragma omp target parallel for simd'}} expected-error {{expected ')'}} expected-note {{to match this '('}} omp50-error {{expected 'concurrent' in OpenMP clause 'order'}} omp51-error {{expected 'concurrent' in OpenMP clause 'order'}}
642 for (int i = 0; i < 10; ++i)
644 #pragma omp target parallel for simd order(concurrent // omp45-error {{unexpected OpenMP clause 'order' in directive '#pragma omp target parallel for simd'}} expected-error {{expected ')'}} expected-note {{to match this '('}}
645 for (int i = 0; i < 10; ++i)
647 #pragma omp target parallel for simd order(concurrent) // omp45-error {{unexpected OpenMP clause 'order' in directive '#pragma omp target parallel for simd'}}
648 for (int i = 0; i < 10; ++i)
650 #pragma omp target parallel for simd order(unconstrained:) // omp45-error {{unexpected OpenMP clause 'order' in directive '#pragma omp target parallel for simd'}} omp50-error {{expected 'concurrent' in OpenMP clause 'order'}} omp51-error {{expected 'concurrent' in OpenMP clause 'order'}}
651 for (int i = 0; i < 10; ++i)
653 #pragma omp target parallel for simd order(reproducible:concurrent // omp45-error {{unexpected OpenMP clause 'order' in directive '#pragma omp target parallel for simd'}} expected-error {{expected ')'}} expected-note {{to match this '('}} omp50-error {{expected 'concurrent' in OpenMP clause 'order'}}
654 for (int i = 0; i < 10; ++i)
656 #pragma omp target parallel for simd order(reproducible:concurrent) // omp45-error {{unexpected OpenMP clause 'order' in directive '#pragma omp target parallel for simd'}} omp50-error {{expected 'concurrent' in OpenMP clause 'order'}}
657 for (int i = 0; i < 10; ++i)
659 #pragma omp target parallel for simd order(unconstrained:concurrent) // omp45-error {{unexpected OpenMP clause 'order' in directive '#pragma omp target parallel for simd'}} omp50-error {{expected 'concurrent' in OpenMP clause 'order'}}
660 for (int i = 0; i < 10; ++i)
662 #pragma omp target parallel for simd order(concurrent) order(concurrent) // omp45-error {{unexpected OpenMP clause 'order' in directive '#pragma omp target parallel for simd'}} omp45-error {{unexpected OpenMP clause 'order' in directive '#pragma omp target parallel for simd'}} omp51-error {{directive '#pragma omp target parallel for simd' cannot contain more than one 'order' clause}}
663 for (int i = 0; i < 10; ++i)