Clang Project

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