1 // RUN: %clang_cc1 -fsyntax-only -fopenmp -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify %s
3 // RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify %s
11 S(const S &s) : a(s.a) {}
15 // expected-note@+1 {{defined as threadprivate or thread local}}
16 #pragma omp threadprivate(sii)
19 int test_iteration_spaces() {
21 float a[N], b[N], c[N];
27 for (int i = 0; i < 10; i += 1) {
32 for (char i = 0; i < 10; i++) {
37 for (char i = 0; i < 10; i += '\1') {
42 for (long long i = 0; i < 10; i++) {
46 // expected-error@+2 {{expression must have integral or unscoped enumeration type, not 'double'}}
48 for (long long i = 0; i < 10; i += 1.5) {
53 for (long long i = 0; i < 'z'; i += 1u) {
57 // expected-error@+2 {{variable must be of integer or random access iterator type}}
59 for (float fi = 0; fi < 10.0; fi++) {
60 c[(int)fi] = a[(int)fi] + b[(int)fi];
63 // expected-error@+2 {{variable must be of integer or random access iterator type}}
65 for (double fi = 0; fi < 10.0; fi++) {
66 c[(int)fi] = a[(int)fi] + b[(int)fi];
69 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
71 for (int &ref = ii; ref < 10; ref++) {
74 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
76 for (int i; i < 10; i++)
80 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
82 for (int i = 0, j = 0; i < 10; ++i)
86 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
92 // expected-warning@+3 {{expression result unused}}
93 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
95 for (ii + 1; ii < 10; ++ii)
99 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
101 for (c[ii] = 0; ii < 10; ++ii)
105 // Ok to skip parenthesises.
107 for (((ii)) = 0; ii < 10; ++ii)
111 // expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}}
113 for (int i = 0; i; i++)
117 // expected-error@+3 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}}
118 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'i'}}
120 for (int i = 0; jj < kk; ii++)
124 // expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}}
126 for (int i = 0; !!i; i++)
130 // expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}}
132 for (int i = 0; i != 1; i++)
136 // expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}}
138 for (int i = 0;; i++)
144 for (int i = 11; i > 10; i--)
150 for (int i = 0; i < 10; ++i)
156 for (ii = 0; ii < 10; ++ii)
160 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
162 for (ii = 0; ii < 10; ++jj)
166 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
168 for (ii = 0; ii < 10; ++++ii)
172 // Ok but undefined behavior (in general, cannot check that incr
173 // is really loop-invariant).
175 for (ii = 0; ii < 10; ii = ii + ii)
179 // expected-error@+2 {{expression must have integral or unscoped enumeration type, not 'float'}}
181 for (ii = 0; ii < 10; ii = ii + 1.0f)
185 // Ok - step was converted to integer type.
187 for (ii = 0; ii < 10; ii = ii + (int)1.1f)
191 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
193 for (ii = 0; ii < 10; jj = ii + 2)
197 // expected-warning@+3 {{relational comparison result unused}}
198 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
200 for (ii = 0; ii<10; jj> kk + 2)
204 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
206 for (ii = 0; ii < 10;)
210 // expected-warning@+3 {{expression result unused}}
211 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
213 for (ii = 0; ii < 10; !ii)
217 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
219 for (ii = 0; ii < 10; ii ? ++ii : ++jj)
223 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
225 for (ii = 0; ii < 10; ii = ii < 10)
229 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
230 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
232 for (ii = 0; ii < 10; ii = ii + 0)
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}}
239 for (ii = 0; ii < 10; ii = ii + (int)(0.8 - 0.45))
243 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
244 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
246 for (ii = 0; (ii) < 10; ii -= 25)
250 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
251 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
253 for (ii = 0; (ii < 10); ii -= 0)
257 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
258 // expected-error@+2 {{increment expression must cause 'ii' to decrease on each iteration of OpenMP for loop}}
260 for (ii = 0; ii > 10; (ii += 0))
264 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
265 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
267 for (ii = 0; ii < 10; (ii) = (1 - 1) + (ii))
271 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
272 // expected-error@+2 {{increment expression must cause 'ii' to decrease on each iteration of OpenMP for loop}}
274 for ((ii = 0); ii > 10; (ii -= 0))
278 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
279 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
281 for (ii = 0; (ii < 10); (ii -= 0))
285 // expected-note@+2 {{defined as firstprivate}}
286 // expected-error@+2 {{loop iteration variable in the associated loop of 'omp for simd' directive may not be firstprivate, predetermined as linear}}
287 #pragma omp for simd firstprivate(ii)
288 for (ii = 0; ii < 10; ii++)
292 #pragma omp for simd linear(ii)
293 for (ii = 0; ii < 10; ii++)
297 // expected-note@+2 {{defined as private}}
298 // expected-error@+2 {{loop iteration variable in the associated loop of 'omp for simd' directive may not be private, predetermined as linear}}
299 #pragma omp for simd private(ii)
300 for (ii = 0; ii < 10; ii++)
304 // expected-note@+2 {{defined as lastprivate}}
305 // expected-error@+2 {{loop iteration variable in the associated loop of 'omp for simd' directive may not be lastprivate, predetermined as linear}}
306 #pragma omp for simd lastprivate(ii)
307 for (ii = 0; ii < 10; ii++)
312 // 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}}
314 for (sii = 0; sii < 10; sii += 1)
321 for (globalii = 0; globalii < 10; globalii += 1)
322 c[globalii] = a[globalii];
327 #pragma omp for simd collapse(2)
328 for (ii = 0; ii < 10; ii += 1)
329 for (globalii = 0; globalii < 10; globalii += 1)
330 c[globalii] += a[globalii] + ii;
334 // expected-error@+2 {{statement after '#pragma omp for simd' must be a for loop}}
336 for (auto &item : a) {
341 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
342 // expected-error@+2 {{increment expression must cause 'i' to increase on each iteration of OpenMP for loop}}
344 for (unsigned i = 9; i < 10; i--) {
348 int(*lb)[4] = nullptr;
351 for (int(*p)[4] = lb; p < lb + 8; ++p) {
355 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
357 for (int a{0}; a < 10; ++a) {
363 // Iterators allowed in openmp for-loops.
365 struct random_access_iterator_tag {};
366 template <class Iter>
367 struct iterator_traits {
368 typedef typename Iter::difference_type difference_type;
369 typedef typename Iter::iterator_category iterator_category;
371 template <class Iter>
372 typename iterator_traits<Iter>::difference_type
373 distance(Iter first, Iter last) { return first - last; }
378 Iter0(const Iter0 &) {}
379 Iter0 operator++() { return *this; }
380 Iter0 operator--() { return *this; }
381 bool operator<(Iter0 a) { return true; }
383 // expected-note@+2 {{candidate function not viable: no known conversion from 'GoodIter' to 'Iter0' for 1st argument}}
384 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'Iter0' for 1st argument}}
385 int operator-(Iter0 a, Iter0 b) { return 0; }
388 Iter1(float f = 0.0f, double d = 0.0) {}
389 Iter1(const Iter1 &) {}
390 Iter1 operator++() { return *this; }
391 Iter1 operator--() { return *this; }
392 bool operator<(Iter1 a) { return true; }
393 bool operator>=(Iter1 a) { return false; }
398 GoodIter(const GoodIter &) {}
399 GoodIter(int fst, int snd) {}
400 GoodIter &operator=(const GoodIter &that) { return *this; }
401 GoodIter &operator=(const Iter0 &that) { return *this; }
402 GoodIter &operator+=(int x) { return *this; }
403 explicit GoodIter(void *) {}
404 GoodIter operator++() { return *this; }
405 GoodIter operator--() { return *this; }
406 bool operator!() { return true; }
407 bool operator<(GoodIter a) { return true; }
408 bool operator<=(GoodIter a) { return true; }
409 bool operator>=(GoodIter a) { return false; }
410 typedef int difference_type;
411 typedef std::random_access_iterator_tag iterator_category;
413 // expected-note@+2 {{candidate function not viable: no known conversion from 'const Iter0' to 'GoodIter' for 2nd argument}}
414 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}}
415 int operator-(GoodIter a, GoodIter b) { return 0; }
416 // expected-note@+1 3 {{candidate function not viable: requires single argument 'a', but 2 arguments were provided}}
417 GoodIter operator-(GoodIter a) { return a; }
418 // expected-note@+2 {{candidate function not viable: no known conversion from 'const Iter0' to 'int' for 2nd argument}}
419 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}}
420 GoodIter operator-(GoodIter a, int v) { return GoodIter(); }
421 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter0' to 'GoodIter' for 1st argument}}
422 GoodIter operator+(GoodIter a, int v) { return GoodIter(); }
423 // expected-note@+2 {{candidate function not viable: no known conversion from 'GoodIter' to 'int' for 1st argument}}
424 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'int' for 1st argument}}
425 GoodIter operator-(int v, GoodIter a) { return GoodIter(); }
426 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter0' to 'int' for 1st argument}}
427 GoodIter operator+(int v, GoodIter a) { return GoodIter(); }
429 int test_with_random_access_iterator() {
434 for (GoodIter I = begin; I < end; ++I)
437 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
439 for (GoodIter &I = begin; I < end; ++I)
443 for (GoodIter I = begin; I >= end; --I)
446 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
448 for (GoodIter I(begin); I < end; ++I)
451 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
453 for (GoodIter I(nullptr); I < end; ++I)
456 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
458 for (GoodIter I(0); I < end; ++I)
461 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
463 for (GoodIter I(1, 2); I < end; ++I)
467 for (begin = GoodIter(0); begin < end; ++begin)
470 // expected-error@+3 {{invalid operands to binary expression ('GoodIter' and 'const Iter0')}}
471 // expected-error@+2 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}
473 for (begin = begin0; begin < end; ++begin)
476 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
478 for (++begin; begin < end; ++begin)
482 for (begin = end; begin < end; ++begin)
485 // expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'I'}}
487 for (GoodIter I = begin; I - I; ++I)
490 // expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'I'}}
492 for (GoodIter I = begin; begin < end; ++I)
495 // expected-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'I'}}
497 for (GoodIter I = begin; !I; ++I)
500 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
501 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
503 for (GoodIter I = begin; I >= end; I = I + 1)
507 for (GoodIter I = begin; I >= end; I = I - 1)
510 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}}
512 for (GoodIter I = begin; I >= end; I = -I)
515 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
516 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
518 for (GoodIter I = begin; I >= end; I = 2 + I)
521 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}}
523 for (GoodIter I = begin; I >= end; I = 2 - I)
526 // expected-error@+2 {{invalid operands to binary expression ('Iter0' and 'int')}}
528 for (Iter0 I = begin0; I < end0; ++I)
531 // Initializer is constructor without params.
532 // expected-error@+3 {{invalid operands to binary expression ('Iter0' and 'int')}}
533 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
535 for (Iter0 I; I < end0; ++I)
539 // expected-error@+3 {{invalid operands to binary expression ('Iter1' and 'Iter1')}}
540 // expected-error@+2 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}
542 for (Iter1 I = begin1; I < end1; ++I)
545 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
546 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
548 for (Iter1 I = begin1; I >= end1; ++I)
551 // expected-error@+5 {{invalid operands to binary expression ('Iter1' and 'float')}}
552 // expected-error@+4 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}
553 // Initializer is constructor with all default params.
554 // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
556 for (Iter1 I; I < end1; ++I) {
561 template <typename IT, int ST>
564 int dotest_lt(IT begin, IT end) {
566 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
567 // expected-error@+2 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}}
569 for (IT I = begin; I < end; I = I + ST) {
573 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
574 // expected-error@+2 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}}
576 for (IT I = begin; I <= end; I += ST) {
581 for (IT I = begin; I < end; ++I) {
590 template <typename IT, int ST = 0>
591 int dotest_gt(IT begin, IT end) {
593 // expected-note@+3 2 {{loop step is expected to be negative due to this condition}}
594 // expected-error@+2 2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
596 for (IT I = begin; I >= end; I = I + ST) {
600 // expected-note@+3 2 {{loop step is expected to be negative due to this condition}}
601 // expected-error@+2 2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
603 for (IT I = begin; I >= end; I += ST) {
608 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
609 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
611 for (IT I = begin; I >= end; ++I) {
617 for (IT I = begin; I < end; I += TC<int, ST>::step()) {
622 void test_with_template() {
624 TC<GoodIter, 100> t1;
625 TC<GoodIter, -100> t2;
626 t1.dotest_lt(begin, end);
627 t2.dotest_lt(begin, end); // expected-note {{in instantiation of member function 'TC<GoodIter, -100>::dotest_lt' requested here}}
628 dotest_gt(begin, end); // expected-note {{in instantiation of function template specialization 'dotest_gt<GoodIter, 0>' requested here}}
629 dotest_gt<unsigned, 10>(0, 100); // expected-note {{in instantiation of function template specialization 'dotest_gt<unsigned int, 10>' requested here}}
632 void test_loop_break() {
634 float a[N], b[N], c[N];
637 for (int i = 0; i < 10; i++) {
639 for (int j = 0; j < 10; ++j) {
641 break; // OK in nested loop
651 break; // expected-error {{'break' statement cannot be used in OpenMP for loop}}
654 break; // expected-error {{'break' statement cannot be used in OpenMP for loop}}
659 for (int i = 0; i < 10; i++) {
660 for (int j = 0; j < 10; j++) {
671 void test_loop_eh() {
673 float a[N], b[N], c[N];
676 for (int i = 0; i < 10; i++) {
678 try { // expected-error {{'try' statement cannot be used in OpenMP simd region}}
679 for (int j = 0; j < 10; ++j) {
681 throw a[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
683 throw a[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
687 throw a[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
688 return; // expected-error {{cannot return from OpenMP region}}
697 for (int j = 0; j < 10; j++) {
699 throw c[i]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
707 for (int i = 0; i < 10; ++i) {
709 void g() { throw 0; }
714 void test_loop_firstprivate_lastprivate() {
717 #pragma omp for simd lastprivate(s) firstprivate(s)
718 for (int i = 0; i < 16; ++i)
722 void test_ordered() {
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)
728 #pragma omp for simd ordered
729 for (int i = 0; i < 16; ++i)
732 // expected-error@+1 {{'ordered' clause with a parameter can not be specified in '#pragma omp for simd' directive}}
733 #pragma omp for simd ordered(1)
734 for (int i = 0; i < 16; ++i)
740 #pragma omp for simd nowait nowait // expected-error {{directive '#pragma omp for simd' cannot contain more than one 'nowait' clause}}
741 for (int i = 0; i < 16; ++i)