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