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