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