[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / OpenMP / target_teams_distribute_simd_loop_messages.cpp
blob0c78ee0a21b32b5e42ea466c9f85f97f6ca7bc98
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) {} // expected-note {{implicitly declared private here}}
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 teams distribute simd
28 for (int i = 0; i < 10; i += 1) {
29 c[i] = a[i] + b[i];
31 #pragma omp target teams distribute simd
32 for (char i = 0; i < 10; i++) {
33 c[i] = a[i] + b[i];
35 #pragma omp target teams distribute simd
36 for (char i = 0; i < 10; i += '\1') {
37 c[i] = a[i] + b[i];
39 #pragma omp target teams distribute simd
40 for (long long i = 0; i < 10; i++) {
41 c[i] = a[i] + b[i];
43 #pragma omp target teams distribute simd
44 // expected-error@+1 {{expression must have integral or unscoped enumeration type, not 'double'}}
45 for (long long i = 0; i < 10; i += 1.5) {
46 c[i] = a[i] + b[i];
48 #pragma omp target teams distribute simd
49 for (long long i = 0; i < 'z'; i += 1u) {
50 c[i] = a[i] + b[i];
52 #pragma omp target teams distribute simd
53 // expected-error@+1 {{variable must be of integer or random access iterator type}}
54 for (float fi = 0; fi < 10.0; fi++) {
55 c[(int)fi] = a[(int)fi] + b[(int)fi];
57 #pragma omp target teams distribute simd
58 // expected-error@+1 {{variable must be of integer or random access iterator type}}
59 for (double fi = 0; fi < 10.0; fi++) {
60 c[(int)fi] = a[(int)fi] + b[(int)fi];
62 #pragma omp target teams distribute simd
63 // expected-error@+1 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
64 for (int &ref = ii; ref < 10; ref++) {
66 #pragma omp target teams distribute simd
67 // expected-error@+1 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
68 for (int i; i < 10; i++)
69 c[i] = a[i];
71 #pragma omp target teams distribute simd
72 // expected-error@+1 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
73 for (int i = 0, j = 0; i < 10; ++i)
74 c[i] = a[i];
76 #pragma omp target teams distribute simd
77 // expected-error@+1 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
78 for (; ii < 10; ++ii)
79 c[ii] = a[ii];
81 #pragma omp target teams distribute simd
82 // expected-warning@+2 {{expression result unused}}
83 // expected-error@+1 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
84 for (ii + 1; ii < 10; ++ii)
85 c[ii] = a[ii];
87 #pragma omp target teams distribute simd
88 // expected-error@+1 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
89 for (c[ii] = 0; ii < 10; ++ii)
90 c[ii] = a[ii];
92 #pragma omp target teams distribute simd
93 // Ok to skip parenthesises.
94 for (((ii)) = 0; ii < 10; ++ii)
95 c[ii] = a[ii];
97 #pragma omp target teams distribute simd
98 // omp4-error@+1 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}} expected-error@+1 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'i'}} omp5-error@+1 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'i'}}
99 for (int i = 0; jj < kk; ii++)
100 c[i] = a[i];
102 #pragma omp target teams distribute simd
103 // omp4-error@+1 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}} omp5-error@+1 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'i'}}
104 for (int i = 0; !!i; i++)
105 c[i] = a[i];
107 // omp4-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}}
108 #pragma omp target teams distribute simd
109 for (int i = 0; i != 1; i++)
110 c[i] = a[i];
112 #pragma omp target teams distribute simd
113 // omp4-error@+1 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}} omp5-error@+1 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'i'}}
114 for (int i = 0;; i++)
115 c[i] = a[i];
117 // Ok.
118 #pragma omp target teams distribute simd
119 for (int i = 11; i > 10; i--)
120 c[i] = a[i];
122 // Ok.
123 #pragma omp target teams distribute simd
124 for (int i = 0; i < 10; ++i)
125 c[i] = a[i];
127 // Ok.
128 #pragma omp target teams distribute simd
129 for (ii = 0; ii < 10; ++ii)
130 c[ii] = a[ii];
132 #pragma omp target teams distribute simd
133 // expected-error@+1 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
134 for (ii = 0; ii < 10; ++jj)
135 c[ii] = a[jj];
137 #pragma omp target teams distribute simd
138 // expected-error@+1 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
139 for (ii = 0; ii < 10; ++++ii)
140 c[ii] = a[ii];
142 // Ok but undefined behavior (in general, cannot check that incr
143 // is really loop-invariant).
144 #pragma omp target teams distribute simd
145 for (ii = 0; ii < 10; ii = ii + ii)
146 c[ii] = a[ii];
148 #pragma omp target teams distribute simd
149 // expected-error@+1 {{expression must have integral or unscoped enumeration type, not 'float'}}
150 for (ii = 0; ii < 10; ii = ii + 1.0f)
151 c[ii] = a[ii];
153 // Ok - step was converted to integer type.
154 #pragma omp target teams distribute simd
155 for (ii = 0; ii < 10; ii = ii + (int)1.1f)
156 c[ii] = a[ii];
158 #pragma omp target teams distribute simd
159 // expected-error@+1 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
160 for (ii = 0; ii < 10; jj = ii + 2)
161 c[ii] = a[ii];
163 #pragma omp target teams distribute simd
164 // expected-warning@+2 {{relational comparison result unused}}
165 // expected-error@+1 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
166 for (ii = 0; ii<10; jj> kk + 2)
167 c[ii] = a[ii];
169 #pragma omp target teams distribute simd
170 // expected-error@+1 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
171 for (ii = 0; ii < 10;)
172 c[ii] = a[ii];
174 #pragma omp target teams distribute simd
175 // expected-warning@+2 {{expression result unused}}
176 // expected-error@+1 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
177 for (ii = 0; ii < 10; !ii)
178 c[ii] = a[ii];
180 #pragma omp target teams distribute simd
181 // expected-error@+1 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
182 for (ii = 0; ii < 10; ii ? ++ii : ++jj)
183 c[ii] = a[ii];
185 #pragma omp target teams distribute simd
186 // expected-error@+1 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
187 for (ii = 0; ii < 10; ii = ii < 10)
188 c[ii] = a[ii];
190 #pragma omp target teams distribute simd
191 // expected-note@+2 {{loop step is expected to be positive due to this condition}}
192 // expected-error@+1 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
193 for (ii = 0; ii < 10; ii = ii + 0)
194 c[ii] = a[ii];
196 #pragma omp target teams distribute simd
197 // expected-note@+2 {{loop step is expected to be positive due to this condition}}
198 // expected-error@+1 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
199 for (ii = 0; ii < 10; ii = ii + (int)(0.8 - 0.45))
200 c[ii] = a[ii];
202 #pragma omp target teams distribute simd
203 // expected-note@+2 {{loop step is expected to be positive due to this condition}}
204 // expected-error@+1 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
205 for (ii = 0; (ii) < 10; ii -= 25)
206 c[ii] = a[ii];
208 #pragma omp target teams distribute simd
209 // expected-note@+2 {{loop step is expected to be positive due to this condition}}
210 // expected-error@+1 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
211 for (ii = 0; (ii < 10); ii -= 0)
212 c[ii] = a[ii];
214 #pragma omp target teams distribute simd
215 // expected-note@+2 {{loop step is expected to be negative due to this condition}}
216 // expected-error@+1 {{increment expression must cause 'ii' to decrease on each iteration of OpenMP for loop}}
217 for (ii = 0; ii > 10; (ii += 0))
218 c[ii] = a[ii];
220 #pragma omp target teams distribute simd
221 // expected-note@+2 {{loop step is expected to be positive due to this condition}}
222 // expected-error@+1 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
223 for (ii = 0; ii < 10; (ii) = (1 - 1) + (ii))
224 c[ii] = a[ii];
226 #pragma omp target teams distribute simd
227 // expected-note@+2 {{loop step is expected to be negative due to this condition}}
228 // expected-error@+1 {{increment expression must cause 'ii' to decrease on each iteration of OpenMP for loop}}
229 for ((ii = 0); ii > 10; (ii -= 0))
230 c[ii] = a[ii];
232 #pragma omp target teams distribute simd
233 // expected-note@+2 {{loop step is expected to be positive due to this condition}}
234 // expected-error@+1 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
235 for (ii = 0; (ii < 10); (ii -= 0))
236 c[ii] = a[ii];
238 #pragma omp target teams distribute simd firstprivate(ii) // expected-note {{defined as firstprivate}}
239 // expected-error@+1 {{loop iteration variable in the associated loop of 'omp target teams distribute simd' directive may not be firstprivate, predetermined as linear}}
240 for (ii = 0; ii < 10; ii++)
241 c[ii] = a[ii];
243 #pragma omp target teams distribute simd private(ii) // omp4-note {{defined as private}}
244 // omp4-error@+1 {{loop iteration variable in the associated loop of 'omp target teams distribute simd' directive may not be private, predetermined as linear}}
245 for (ii = 0; ii < 10; ii++)
246 c[ii] = a[ii];
248 #pragma omp target teams distribute simd lastprivate(ii) // omp4-note {{defined as lastprivate}}
249 // omp4-error@+1 {{loop iteration variable in the associated loop of 'omp target teams distribute simd' directive may not be lastprivate, predetermined as linear}}
250 for (ii = 0; ii < 10; ii++)
251 c[ii] = a[ii];
253 #pragma omp target teams distribute simd
254 // expected-error@+1 {{loop iteration variable in the associated loop of 'omp target teams distribute simd' directive may not be threadprivate or thread local, predetermined as linear}}
255 for (sii = 0; sii < 10; sii++)
256 c[sii] = a[sii];
259 #pragma omp target teams distribute simd collapse(2)
260 for (ii = 0; ii < 10; ii += 1)
261 for (globalii = 0; globalii < 10; globalii += 1)
262 c[globalii] += a[globalii] + ii;
265 #pragma omp target teams distribute simd
266 // omp4-error@+1 {{statement after '#pragma omp target teams distribute simd' must be a for loop}}
267 for (auto &item : a) {
268 item = item + 1;
271 #pragma omp target teams distribute simd
272 // expected-note@+2 {{loop step is expected to be positive due to this condition}}
273 // expected-error@+1 {{increment expression must cause 'i' to increase on each iteration of OpenMP for loop}}
274 for (unsigned i = 9; i < 10; i--) {
275 c[i] = a[i] + b[i];
278 int(*lb)[4] = nullptr;
279 #pragma omp target teams distribute simd
280 for (int(*p)[4] = lb; p < lb + 8; ++p) {
283 #pragma omp target teams distribute simd
284 // expected-warning@+1 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
285 for (int a{0}; a < 10; ++a) {
288 return 0;
291 // Iterators allowed in openmp for-loops.
292 namespace std {
293 struct random_access_iterator_tag {};
294 template <class Iter>
295 struct iterator_traits {
296 typedef typename Iter::difference_type difference_type;
297 typedef typename Iter::iterator_category iterator_category;
299 template <class Iter>
300 typename iterator_traits<Iter>::difference_type
301 distance(Iter first, Iter last) { return first - last; }
303 class Iter0 {
304 public:
305 Iter0() {}
306 Iter0(const Iter0 &) {}
307 Iter0 operator++() { return *this; }
308 Iter0 operator--() { return *this; }
309 bool operator<(Iter0 a) { return true; }
311 // expected-note@+2 {{candidate function not viable: no known conversion from 'GoodIter' to 'Iter0' for 1st argument}}
312 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'Iter0' for 1st argument}}
313 int operator-(Iter0 a, Iter0 b) { return 0; }
314 class Iter1 {
315 public:
316 Iter1(float f = 0.0f, double d = 0.0) {}
317 Iter1(const Iter1 &) {}
318 Iter1 operator++() { return *this; }
319 Iter1 operator--() { return *this; }
320 bool operator<(Iter1 a) { return true; }
321 bool operator>=(Iter1 a) { return false; }
323 class GoodIter {
324 public:
325 GoodIter() {}
326 GoodIter(const GoodIter &) {}
327 GoodIter(int fst, int snd) {}
328 GoodIter &operator=(const GoodIter &that) { return *this; }
329 GoodIter &operator=(const Iter0 &that) { return *this; }
330 GoodIter &operator+=(int x) { return *this; }
331 explicit GoodIter(void *) {}
332 GoodIter operator++() { return *this; }
333 GoodIter operator--() { return *this; }
334 bool operator!() { return true; }
335 bool operator<(GoodIter a) { return true; }
336 bool operator<=(GoodIter a) { return true; }
337 bool operator>=(GoodIter a) { return false; }
338 typedef int difference_type;
339 typedef std::random_access_iterator_tag iterator_category;
341 // expected-note@+2 {{candidate function not viable: no known conversion from 'const Iter0' to 'GoodIter' for 2nd argument}}
342 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}}
343 int operator-(GoodIter a, GoodIter b) { return 0; }
344 // expected-note@+1 3 {{candidate function not viable: requires single argument 'a', but 2 arguments were provided}}
345 GoodIter operator-(GoodIter a) { return a; }
346 // expected-note@+2 {{candidate function not viable: no known conversion from 'const Iter0' to 'int' for 2nd argument}}
347 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}}
348 GoodIter operator-(GoodIter a, int v) { return GoodIter(); }
349 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter0' to 'GoodIter' for 1st argument}}
350 GoodIter operator+(GoodIter a, int v) { return GoodIter(); }
351 // expected-note@+2 {{candidate function not viable: no known conversion from 'GoodIter' to 'int' for 1st argument}}
352 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'int' for 1st argument}}
353 GoodIter operator-(int v, GoodIter a) { return GoodIter(); }
354 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter0' to 'int' for 1st argument}}
355 GoodIter operator+(int v, GoodIter a) { return GoodIter(); }
357 int test_with_random_access_iterator() {
358 GoodIter begin, end;
359 Iter0 begin0, end0;
360 #pragma omp target teams distribute simd
361 for (GoodIter I = begin; I < end; ++I)
362 ++I;
363 #pragma omp target teams distribute simd
364 // expected-error@+1 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
365 for (GoodIter &I = begin; I < end; ++I)
366 ++I;
367 #pragma omp target teams distribute simd
368 for (GoodIter I = begin; I >= end; --I)
369 ++I;
370 #pragma omp target teams distribute simd
371 // expected-warning@+1 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
372 for (GoodIter I(begin); I < end; ++I)
373 ++I;
374 #pragma omp target teams distribute simd
375 // expected-warning@+1 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
376 for (GoodIter I(nullptr); I < end; ++I)
377 ++I;
378 #pragma omp target teams distribute simd
379 // expected-warning@+1 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
380 for (GoodIter I(0); I < end; ++I)
381 ++I;
382 #pragma omp target teams distribute simd
383 // expected-warning@+1 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
384 for (GoodIter I(1, 2); I < end; ++I)
385 ++I;
386 #pragma omp target teams distribute simd
387 for (begin = GoodIter(0); begin < end; ++begin)
388 ++begin;
389 #pragma omp target teams distribute simd
390 // expected-error@+2 {{invalid operands to binary expression ('GoodIter' and 'const Iter0')}}
391 // expected-error@+1 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}
392 for (begin = begin0; begin < end; ++begin)
393 ++begin;
394 #pragma omp target teams distribute simd
395 // expected-error@+1 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
396 for (++begin; begin < end; ++begin)
397 ++begin;
398 #pragma omp target teams distribute simd
399 for (begin = end; begin < end; ++begin)
400 ++begin;
401 #pragma omp target teams distribute simd
402 // omp4-error@+1 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'I'}} omp5-error@+1 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'I'}}
403 for (GoodIter I = begin; I - I; ++I)
404 ++I;
405 #pragma omp target teams distribute simd
406 // omp4-error@+1 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'I'}} omp5-error@+1 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'I'}}
407 for (GoodIter I = begin; begin < end; ++I)
408 ++I;
409 #pragma omp target teams distribute simd
410 // omp4-error@+1 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'I'}} omp5-error@+1 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'I'}}
411 for (GoodIter I = begin; !I; ++I)
412 ++I;
413 #pragma omp target teams distribute simd
414 // expected-note@+2 {{loop step is expected to be negative due to this condition}}
415 // expected-error@+1 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
416 for (GoodIter I = begin; I >= end; I = I + 1)
417 ++I;
418 #pragma omp target teams distribute simd
419 for (GoodIter I = begin; I >= end; I = I - 1)
420 ++I;
421 #pragma omp target teams distribute simd
422 // expected-error@+1 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}}
423 for (GoodIter I = begin; I >= end; I = -I)
424 ++I;
425 #pragma omp target teams distribute simd
426 // expected-note@+2 {{loop step is expected to be negative due to this condition}}
427 // expected-error@+1 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
428 for (GoodIter I = begin; I >= end; I = 2 + I)
429 ++I;
430 #pragma omp target teams distribute simd
431 // expected-error@+1 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}}
432 for (GoodIter I = begin; I >= end; I = 2 - I)
433 ++I;
434 #pragma omp target teams distribute simd
435 // expected-error@+1 {{invalid operands to binary expression ('Iter0' and 'int')}}
436 for (Iter0 I = begin0; I < end0; ++I)
437 ++I;
438 #pragma omp target teams distribute simd
439 // Initializer is constructor without params.
440 // expected-error@+2 {{invalid operands to binary expression ('Iter0' and 'int')}}
441 // expected-warning@+1 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
442 for (Iter0 I; I < end0; ++I)
443 ++I;
444 Iter1 begin1, end1;
445 #pragma omp target teams distribute simd
446 // expected-error@+2 {{invalid operands to binary expression ('Iter1' and 'Iter1')}}
447 // expected-error@+1 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}
448 for (Iter1 I = begin1; I < end1; ++I)
449 ++I;
450 #pragma omp target teams distribute simd
451 // expected-note@+2 {{loop step is expected to be negative due to this condition}}
452 // expected-error@+1 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
453 for (Iter1 I = begin1; I >= end1; ++I)
454 ++I;
455 #pragma omp target teams distribute simd
456 // expected-error@+4 {{invalid operands to binary expression ('Iter1' and 'float')}}
457 // expected-error@+3 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}
458 // Initializer is constructor with all default params.
459 // expected-warning@+1 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
460 for (Iter1 I; I < end1; ++I) {
462 return 0;
465 template <typename IT, int ST>
466 class TC {
467 public:
468 int dotest_lt(IT begin, IT end) {
469 #pragma omp target teams distribute simd
470 // expected-note@+2 {{loop step is expected to be positive due to this condition}}
471 // expected-error@+1 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}}
472 for (IT I = begin; I < end; I = I + ST) {
473 ++I;
475 #pragma omp target teams distribute simd
476 // expected-note@+2 {{loop step is expected to be positive due to this condition}}
477 // expected-error@+1 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}}
478 for (IT I = begin; I <= end; I += ST) {
479 ++I;
481 #pragma omp target teams distribute simd
482 for (IT I = begin; I < end; ++I) {
483 ++I;
487 static IT step() {
488 return IT(ST);
491 template <typename IT, int ST = 0>
492 int dotest_gt(IT begin, IT end) {
493 #pragma omp target teams distribute simd
494 // expected-note@+2 2 {{loop step is expected to be negative due to this condition}}
495 // expected-error@+1 2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
496 for (IT I = begin; I >= end; I = I + ST) {
497 ++I;
499 #pragma omp target teams distribute simd
500 // expected-note@+2 2 {{loop step is expected to be negative due to this condition}}
501 // expected-error@+1 2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
502 for (IT I = begin; I >= end; I += ST) {
503 ++I;
506 #pragma omp target teams distribute simd
507 // expected-note@+2 {{loop step is expected to be negative due to this condition}}
508 // expected-error@+1 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
509 for (IT I = begin; I >= end; ++I) {
510 ++I;
513 #pragma omp target teams distribute simd
514 for (IT I = begin; I < end; I += TC<int, ST>::step()) {
515 ++I;
519 void test_with_template() {
520 GoodIter begin, end;
521 TC<GoodIter, 100> t1;
522 TC<GoodIter, -100> t2;
523 t1.dotest_lt(begin, end);
524 t2.dotest_lt(begin, end); // expected-note {{in instantiation of member function 'TC<GoodIter, -100>::dotest_lt' requested here}}
525 dotest_gt(begin, end); // expected-note {{in instantiation of function template specialization 'dotest_gt<GoodIter, 0>' requested here}}
526 dotest_gt<unsigned, 10>(0, 100); // expected-note {{in instantiation of function template specialization 'dotest_gt<unsigned int, 10>' requested here}}
529 void test_loop_break() {
530 const int N = 100;
531 float a[N], b[N], c[N];
532 #pragma omp target teams distribute simd
533 for (int i = 0; i < 10; i++) {
534 c[i] = a[i] + b[i];
535 for (int j = 0; j < 10; ++j) {
536 if (a[i] > b[j])
537 break; // OK in nested loop
539 switch (i) {
540 case 1:
541 b[i]++;
542 break;
543 default:
544 break;
546 if (c[i] > 10)
547 break; // expected-error {{'break' statement cannot be used in OpenMP for loop}}
549 if (c[i] > 11)
550 break; // expected-error {{'break' statement cannot be used in OpenMP for loop}}
553 #pragma omp target teams distribute simd
554 for (int i = 0; i < 10; i++) {
555 for (int j = 0; j < 10; j++) {
556 c[i] = a[i] + b[i];
557 if (c[i] > 10) {
558 if (c[i] < 20) {
559 break; // OK
566 void test_loop_eh() {
567 const int N = 100;
568 float a[N], b[N], c[N];
569 #pragma omp target teams distribute simd
570 for (int i = 0; i < 10; i++) {
571 c[i] = a[i] + b[i];
572 try { // expected-error {{'try' statement cannot be used in OpenMP simd region}}
573 for (int j = 0; j < 10; ++j) {
574 if (a[i] > b[j])
575 throw a[i]; // expected-error {{throw' statement cannot be used in OpenMP simd region}}
577 throw a[i]; // expected-error {{throw' statement cannot be used in OpenMP simd region}}
578 } catch (float f) {
579 if (f > 0.1)
580 throw a[i]; // expected-error {{throw' statement cannot be used in OpenMP simd region}}
581 return; // expected-error {{cannot return from OpenMP region}}
583 switch (i) {
584 case 1:
585 b[i]++;
586 break;
587 default:
588 break;
590 for (int j = 0; j < 10; j++) {
591 if (c[i] > 10)
592 throw c[i]; // expected-error {{throw' statement cannot be used in OpenMP simd region}}
595 if (c[9] > 10)
596 throw c[9]; // OK
598 #pragma omp target teams distribute simd
599 for (int i = 0; i < 10; ++i) {
600 struct S {
601 void g() { throw 0; }
606 void test_loop_firstprivate_lastprivate() {
607 S s(4);
608 // expected-error@+1 {{lastprivate variable cannot be firstprivate}} expected-note@+1 {{defined as lastprivate}}
609 #pragma omp target teams distribute simd lastprivate(s) firstprivate(s) // expected-error {{calling a private constructor of class 'S'}}
610 for (int i = 0; i < 16; ++i)
614 void test_ordered() {
615 #pragma omp target teams distribute simd ordered // expected-error {{unexpected OpenMP clause 'ordered' in directive '#pragma omp target teams distribute simd'}}
616 for (int i = 0; i < 16; ++i)
620 void test_nowait() {
621 // expected-error@+1 {{directive '#pragma omp target teams distribute simd' cannot contain more than one 'nowait' clause}}
622 #pragma omp target teams distribute simd nowait nowait
623 for (int i = 0; i < 16; ++i)