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