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