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