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