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 parallel for |
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 parallel for |
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 parallel for |
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 parallel for |
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 parallel for |
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 parallel for |
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 parallel for |
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 parallel for |
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 parallel for |
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 parallel for |
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 parallel for |
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 parallel for |
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 parallel for |
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 parallel for |
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 parallel for |
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 parallel for |
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 parallel for |
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 parallel for |
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 parallel for |
132 | for (int i = 0; i != 1; i++) |
133 | c[i] = a[i]; |
134 | |
135 | #pragma omp target |
136 | #pragma omp teams distribute parallel for |
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 parallel for |
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 parallel for |
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 parallel for |
156 | for (ii = 0; ii < 10; ++ii) |
157 | c[ii] = a[ii]; |
158 | |
159 | #pragma omp target |
160 | #pragma omp teams distribute parallel for |
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 parallel for |
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 parallel for |
175 | for (ii = 0; ii < 10; ii = ii + ii) |
176 | c[ii] = a[ii]; |
177 | |
178 | #pragma omp target |
179 | #pragma omp teams distribute parallel for |
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 parallel for |
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 parallel for |
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 parallel for |
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 parallel for |
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 parallel for |
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 parallel for |
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 parallel for |
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 parallel for |
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 parallel for |
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 parallel for |
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 parallel for |
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 parallel for |
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 parallel for |
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 parallel for |
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 parallel for |
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 parallel for firstprivate(ii) // expected-note {{defined as firstprivate}} |
286 | // expected-error@+1 {{loop iteration variable in the associated loop of 'omp teams distribute parallel for' 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 parallel for private(ii) // OK |
292 | for (ii = 0; ii < 10; ii++) |
293 | c[ii] = a[ii]; |
294 | |
295 | #pragma omp target |
296 | #pragma omp teams distribute parallel for lastprivate(ii) // OK |
297 | for (ii = 0; ii < 10; ii++) |
298 | c[ii] = a[ii]; |
299 | |
300 | #pragma omp target |
301 | #pragma omp teams distribute parallel for |
302 | // expected-error@+1 {{loop iteration variable in the associated loop of 'omp teams distribute parallel for' directive may not be threadprivate or thread local, predetermined as private}} |
303 | for (sii = 0; sii < 10; sii++) |
304 | c[sii] = a[sii]; |
305 | |
306 | { |
307 | #pragma omp target |
308 | #pragma omp teams distribute parallel for collapse(2) |
309 | for (ii = 0; ii < 10; ii += 1) |
310 | for (globalii = 0; globalii < 10; globalii += 1) |
311 | c[globalii] += a[globalii] + ii; |
312 | } |
313 | |
314 | #pragma omp target |
315 | #pragma omp teams distribute parallel for |
316 | // expected-error@+1 {{statement after '#pragma omp teams distribute parallel for' must be a for loop}} |
317 | for (auto &item : a) { |
318 | item = item + 1; |
319 | } |
320 | |
321 | #pragma omp target |
322 | #pragma omp teams distribute parallel for |
323 | // expected-note@+2 {{loop step is expected to be positive due to this condition}} |
324 | // expected-error@+1 {{increment expression must cause 'i' to increase on each iteration of OpenMP for loop}} |
325 | for (unsigned i = 9; i < 10; i--) { |
326 | c[i] = a[i] + b[i]; |
327 | } |
328 | |
329 | int(*lb)[4] = nullptr; |
330 | #pragma omp target |
331 | #pragma omp teams distribute parallel for |
332 | for (int(*p)[4] = lb; p < lb + 8; ++p) { |
333 | } |
334 | |
335 | #pragma omp target |
336 | #pragma omp teams distribute parallel for |
337 | // expected-warning@+1 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} |
338 | for (int a{0}; a < 10; ++a) { |
339 | } |
340 | |
341 | return 0; |
342 | } |
343 | |
344 | // Iterators allowed in openmp for-loops. |
345 | namespace std { |
346 | struct random_access_iterator_tag {}; |
347 | template <class Iter> |
348 | struct iterator_traits { |
349 | typedef typename Iter::difference_type difference_type; |
350 | typedef typename Iter::iterator_category iterator_category; |
351 | }; |
352 | template <class Iter> |
353 | typename iterator_traits<Iter>::difference_type |
354 | distance(Iter first, Iter last) { return first - last; } |
355 | } |
356 | class Iter0 { |
357 | public: |
358 | Iter0() {} |
359 | Iter0(const Iter0 &) {} |
360 | Iter0 operator++() { return *this; } |
361 | Iter0 operator--() { return *this; } |
362 | bool operator<(Iter0 a) { return true; } |
363 | }; |
364 | // expected-note@+2 {{candidate function not viable: no known conversion from 'GoodIter' to 'Iter0' for 1st argument}} |
365 | // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'Iter0' for 1st argument}} |
366 | int operator-(Iter0 a, Iter0 b) { return 0; } |
367 | class Iter1 { |
368 | public: |
369 | Iter1(float f = 0.0f, double d = 0.0) {} |
370 | Iter1(const Iter1 &) {} |
371 | Iter1 operator++() { return *this; } |
372 | Iter1 operator--() { return *this; } |
373 | bool operator<(Iter1 a) { return true; } |
374 | bool operator>=(Iter1 a) { return false; } |
375 | }; |
376 | class GoodIter { |
377 | public: |
378 | GoodIter() {} |
379 | GoodIter(const GoodIter &) {} |
380 | GoodIter(int fst, int snd) {} |
381 | GoodIter &operator=(const GoodIter &that) { return *this; } |
382 | GoodIter &operator=(const Iter0 &that) { return *this; } |
383 | GoodIter &operator+=(int x) { return *this; } |
384 | explicit GoodIter(void *) {} |
385 | GoodIter operator++() { return *this; } |
386 | GoodIter operator--() { return *this; } |
387 | bool operator!() { return true; } |
388 | bool operator<(GoodIter a) { return true; } |
389 | bool operator<=(GoodIter a) { return true; } |
390 | bool operator>=(GoodIter a) { return false; } |
391 | typedef int difference_type; |
392 | typedef std::random_access_iterator_tag iterator_category; |
393 | }; |
394 | // expected-note@+2 {{candidate function not viable: no known conversion from 'const Iter0' to 'GoodIter' for 2nd argument}} |
395 | // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}} |
396 | int operator-(GoodIter a, GoodIter b) { return 0; } |
397 | // expected-note@+1 3 {{candidate function not viable: requires single argument 'a', but 2 arguments were provided}} |
398 | GoodIter operator-(GoodIter a) { return a; } |
399 | // expected-note@+2 {{candidate function not viable: no known conversion from 'const Iter0' to 'int' for 2nd argument}} |
400 | // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}} |
401 | GoodIter operator-(GoodIter a, int v) { return GoodIter(); } |
402 | // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter0' to 'GoodIter' for 1st argument}} |
403 | GoodIter operator+(GoodIter a, int v) { return GoodIter(); } |
404 | // expected-note@+2 {{candidate function not viable: no known conversion from 'GoodIter' to 'int' for 1st argument}} |
405 | // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'int' for 1st argument}} |
406 | GoodIter operator-(int v, GoodIter a) { return GoodIter(); } |
407 | // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter0' to 'int' for 1st argument}} |
408 | GoodIter operator+(int v, GoodIter a) { return GoodIter(); } |
409 | |
410 | int test_with_random_access_iterator() { |
411 | GoodIter begin, end; |
412 | Iter0 begin0, end0; |
413 | #pragma omp target |
414 | #pragma omp teams distribute parallel for |
415 | 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}} |
416 | ++I; |
417 | #pragma omp target |
418 | #pragma omp teams distribute parallel for |
419 | // expected-error@+1 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} |
420 | for (GoodIter &I = begin; I < end; ++I) |
421 | ++I; |
422 | #pragma omp target |
423 | #pragma omp teams distribute parallel for |
424 | 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}} |
425 | ++I; |
426 | #pragma omp target |
427 | #pragma omp teams distribute parallel for |
428 | // expected-warning@+1 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} |
429 | 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}} |
430 | ++I; |
431 | #pragma omp target |
432 | #pragma omp teams distribute parallel for |
433 | // expected-warning@+1 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} |
434 | for (GoodIter I(nullptr); I < end; ++I) // expected-warning {{Non-trivial type 'GoodIter' is mapped, only trivial types are guaranteed to be mapped correctly}} |
435 | ++I; |
436 | #pragma omp target |
437 | #pragma omp teams distribute parallel for |
438 | // expected-warning@+1 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} |
439 | for (GoodIter I(0); I < end; ++I) // expected-warning {{Non-trivial type 'GoodIter' is mapped, only trivial types are guaranteed to be mapped correctly}} |
440 | ++I; |
441 | #pragma omp target |
442 | #pragma omp teams distribute parallel for |
443 | // expected-warning@+1 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} |
444 | 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}} |
445 | ++I; |
446 | #pragma omp target |
447 | #pragma omp teams distribute parallel for |
448 | for (begin = GoodIter(0); begin < end; ++begin) // expected-warning {{Non-trivial type 'GoodIter' is mapped, only trivial types are guaranteed to be mapped correctly}} |
449 | ++begin; |
450 | #pragma omp target |
451 | #pragma omp teams distribute parallel for |
452 | // expected-error@+2 {{invalid operands to binary expression ('GoodIter' and 'const Iter0')}} |
453 | // expected-error@+1 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}} |
454 | for (begin = begin0; begin < end; ++begin) |
455 | ++begin; |
456 | #pragma omp target |
457 | #pragma omp teams distribute parallel for |
458 | // expected-error@+1 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} |
459 | for (++begin; begin < end; ++begin) |
460 | ++begin; |
461 | #pragma omp target |
462 | #pragma omp teams distribute parallel for |
463 | for (begin = end; begin < end; ++begin) // expected-warning {{Non-trivial type 'GoodIter' is mapped, only trivial types are guaranteed to be mapped correctly}} |
464 | ++begin; |
465 | #pragma omp target |
466 | #pragma omp teams distribute parallel for |
467 | // expected-error@+1 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'I'}} |
468 | for (GoodIter I = begin; I - I; ++I) |
469 | ++I; |
470 | #pragma omp target |
471 | #pragma omp teams distribute parallel for |
472 | // expected-error@+1 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'I'}} |
473 | for (GoodIter I = begin; begin < end; ++I) |
474 | ++I; |
475 | #pragma omp target |
476 | #pragma omp teams distribute parallel for |
477 | // expected-error@+1 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'I'}} |
478 | for (GoodIter I = begin; !I; ++I) |
479 | ++I; |
480 | #pragma omp target |
481 | #pragma omp teams distribute parallel for |
482 | // expected-note@+2 {{loop step is expected to be negative due to this condition}} |
483 | // expected-error@+1 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}} |
484 | for (GoodIter I = begin; I >= end; I = I + 1) |
485 | ++I; |
486 | #pragma omp target |
487 | #pragma omp teams distribute parallel for |
488 | 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}} |
489 | ++I; |
490 | #pragma omp target |
491 | #pragma omp teams distribute parallel for |
492 | // expected-error@+1 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}} |
493 | for (GoodIter I = begin; I >= end; I = -I) |
494 | ++I; |
495 | #pragma omp target |
496 | #pragma omp teams distribute parallel for |
497 | // expected-note@+2 {{loop step is expected to be negative due to this condition}} |
498 | // expected-error@+1 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}} |
499 | for (GoodIter I = begin; I >= end; I = 2 + I) |
500 | ++I; |
501 | #pragma omp target |
502 | #pragma omp teams distribute parallel for |
503 | // expected-error@+1 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}} |
504 | for (GoodIter I = begin; I >= end; I = 2 - I) |
505 | ++I; |
506 | #pragma omp target |
507 | #pragma omp teams distribute parallel for |
508 | // expected-error@+1 {{invalid operands to binary expression ('Iter0' and 'int')}} |
509 | for (Iter0 I = begin0; I < end0; ++I) |
510 | ++I; |
511 | #pragma omp target |
512 | #pragma omp teams distribute parallel for |
513 | // Initializer is constructor without params. |
514 | // expected-error@+2 {{invalid operands to binary expression ('Iter0' and 'int')}} |
515 | // expected-warning@+1 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} |
516 | for (Iter0 I; I < end0; ++I) |
517 | ++I; |
518 | Iter1 begin1, end1; |
519 | #pragma omp target |
520 | #pragma omp teams distribute parallel for |
521 | // expected-error@+2 {{invalid operands to binary expression ('Iter1' and 'Iter1')}} |
522 | // expected-error@+1 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}} |
523 | for (Iter1 I = begin1; I < end1; ++I) |
524 | ++I; |
525 | #pragma omp target |
526 | #pragma omp teams distribute parallel for |
527 | // expected-note@+2 {{loop step is expected to be negative due to this condition}} |
528 | // expected-error@+1 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}} |
529 | for (Iter1 I = begin1; I >= end1; ++I) |
530 | ++I; |
531 | #pragma omp target |
532 | #pragma omp teams distribute parallel for |
533 | // expected-error@+4 {{invalid operands to binary expression ('Iter1' and 'float')}} |
534 | // expected-error@+3 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}} |
535 | // Initializer is constructor with all default params. |
536 | // expected-warning@+1 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} |
537 | for (Iter1 I; I < end1; ++I) { |
538 | } |
539 | return 0; |
540 | } |
541 | |
542 | template <typename IT, int ST> |
543 | class TC { |
544 | public: |
545 | int dotest_lt(IT begin, IT end) { |
546 | #pragma omp target |
547 | #pragma omp teams distribute parallel for |
548 | // expected-note@+2 {{loop step is expected to be positive due to this condition}} |
549 | // expected-error@+1 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}} |
550 | 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}} |
551 | ++I; |
552 | } |
553 | #pragma omp target |
554 | #pragma omp teams distribute parallel for |
555 | // expected-note@+2 {{loop step is expected to be positive due to this condition}} |
556 | // expected-error@+1 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}} |
557 | 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}} |
558 | ++I; |
559 | } |
560 | #pragma omp target |
561 | #pragma omp teams distribute parallel for |
562 | 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}} |
563 | ++I; |
564 | } |
565 | } |
566 | |
567 | static IT step() { |
568 | return IT(ST); |
569 | } |
570 | }; |
571 | template <typename IT, int ST = 0> |
572 | int dotest_gt(IT begin, IT end) { |
573 | #pragma omp target |
574 | #pragma omp teams distribute parallel for |
575 | // expected-note@+2 2 {{loop step is expected to be negative due to this condition}} |
576 | // expected-error@+1 2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}} |
577 | for (IT I = begin; I >= end; I = I + ST) { |
578 | ++I; |
579 | } |
580 | #pragma omp target |
581 | #pragma omp teams distribute parallel for |
582 | // expected-note@+2 2 {{loop step is expected to be negative due to this condition}} |
583 | // expected-error@+1 2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}} |
584 | for (IT I = begin; I >= end; I += ST) { |
585 | ++I; |
586 | } |
587 | |
588 | #pragma omp target |
589 | #pragma omp teams distribute parallel for |
590 | // expected-note@+2 {{loop step is expected to be negative due to this condition}} |
591 | // expected-error@+1 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}} |
592 | for (IT I = begin; I >= end; ++I) { |
593 | ++I; |
594 | } |
595 | |
596 | #pragma omp target |
597 | #pragma omp teams distribute parallel for |
598 | 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}} |
599 | ++I; |
600 | } |
601 | } |
602 | |
603 | void test_with_template() { |
604 | GoodIter begin, end; |
605 | TC<GoodIter, 100> t1; |
606 | TC<GoodIter, -100> t2; |
607 | t1.dotest_lt(begin, end); // expected-note {{in instantiation of member function 'TC<GoodIter, 100>::dotest_lt' requested here}} |
608 | t2.dotest_lt(begin, end); // expected-note {{in instantiation of member function 'TC<GoodIter, -100>::dotest_lt' requested here}} |
609 | dotest_gt(begin, end); // expected-note {{in instantiation of function template specialization 'dotest_gt<GoodIter, 0>' requested here}} |
610 | dotest_gt<unsigned, 10>(0, 100); // expected-note {{in instantiation of function template specialization 'dotest_gt<unsigned int, 10>' requested here}} |
611 | } |
612 | |
613 | void test_loop_break() { |
614 | const int N = 100; |
615 | float a[N], b[N], c[N]; |
616 | #pragma omp target |
617 | #pragma omp teams distribute parallel for |
618 | for (int i = 0; i < 10; i++) { |
619 | c[i] = a[i] + b[i]; |
620 | for (int j = 0; j < 10; ++j) { |
621 | if (a[i] > b[j]) |
622 | break; // OK in nested loop |
623 | } |
624 | switch (i) { |
625 | case 1: |
626 | b[i]++; |
627 | break; |
628 | default: |
629 | break; |
630 | } |
631 | if (c[i] > 10) |
632 | break; // expected-error {{'break' statement cannot be used in OpenMP for loop}} |
633 | |
634 | if (c[i] > 11) |
635 | break; // expected-error {{'break' statement cannot be used in OpenMP for loop}} |
636 | } |
637 | |
638 | #pragma omp target |
639 | #pragma omp teams distribute parallel for |
640 | for (int i = 0; i < 10; i++) { |
641 | for (int j = 0; j < 10; j++) { |
642 | c[i] = a[i] + b[i]; |
643 | if (c[i] > 10) { |
644 | if (c[i] < 20) { |
645 | break; // OK |
646 | } |
647 | } |
648 | } |
649 | } |
650 | } |
651 | |
652 | void test_loop_eh() { |
653 | const int N = 100; |
654 | float a[N], b[N], c[N]; |
655 | #pragma omp target |
656 | #pragma omp teams distribute parallel for |
657 | for (int i = 0; i < 10; i++) { |
658 | c[i] = a[i] + b[i]; |
659 | try { // OK |
660 | for (int j = 0; j < 10; ++j) { |
661 | if (a[i] > b[j]) |
662 | throw a[i]; // OK |
663 | } |
664 | throw a[i]; // OK |
665 | } catch (float f) { |
666 | if (f > 0.1) |
667 | throw a[i]; // OK |
668 | return; // expected-error {{cannot return from OpenMP region}} |
669 | } |
670 | switch (i) { |
671 | case 1: |
672 | b[i]++; |
673 | break; |
674 | default: |
675 | break; |
676 | } |
677 | for (int j = 0; j < 10; j++) { |
678 | if (c[i] > 10) |
679 | throw c[i]; // OK |
680 | } |
681 | } |
682 | if (c[9] > 10) |
683 | throw c[9]; // OK |
684 | |
685 | #pragma omp target |
686 | #pragma omp teams distribute parallel for |
687 | for (int i = 0; i < 10; ++i) { |
688 | struct S { |
689 | void g() { throw 0; } |
690 | }; |
691 | } |
692 | } |
693 | |
694 | void test_loop_firstprivate_lastprivate() { |
695 | S s(4); |
696 | // expected-error@+2 {{lastprivate variable cannot be firstprivate}} expected-note@+2 {{defined as lastprivate}} |
697 | #pragma omp target |
698 | #pragma omp teams distribute parallel for 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}} |
699 | for (int i = 0; i < 16; ++i) |
700 | ; |
701 | } |
702 | |
703 | void test_ordered() { |
704 | #pragma omp target |
705 | #pragma omp teams distribute parallel for ordered // expected-error {{unexpected OpenMP clause 'ordered' in directive '#pragma omp teams distribute parallel for'}} |
706 | for (int i = 0; i < 16; ++i) |
707 | ; |
708 | } |
709 | |
710 | void test_nowait() { |
711 | #pragma omp target |
712 | // expected-error@+1 2 {{unexpected OpenMP clause 'nowait' in directive '#pragma omp teams distribute parallel for'}} |
713 | #pragma omp teams distribute parallel for nowait nowait // expected-error {{directive '#pragma omp teams distribute parallel for' cannot contain more than one 'nowait' clause}} |
714 | for (int i = 0; i < 16; ++i) |
715 | ; |
716 | } |
717 | |
718 | |