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