1 // RUN: %clang_cc1 -fsyntax-only -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify=expected,omp4,expectedw %s -Wuninitialized
2 // RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -fopenmp-version=45 -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify=expected,omp4,expectedw %s -Wuninitialized
3 // RUN: %clang_cc1 -fsyntax-only -fopenmp -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify=expected,omp5,expectedw %s -DOMP51 -Wuninitialized
4 // RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify=expected,omp5,expectedw %s -DOMP51 -Wuninitialized
5 // RUN: %clang_cc1 -fsyntax-only -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify=expected,omp4 %s -Wuninitialized -Wno-openmp-loop-form
6 // RUN: %clang_cc1 -fsyntax-only -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -fexceptions -fcxx-exceptions -verify=expected,omp4 %s -Wuninitialized -Wno-openmp
9 // expected-note@+1 {{defined as threadprivate or thread local}}
10 #pragma omp threadprivate(sii)
14 // expected-note@+1 {{static data member is predetermined as shared}}
18 int test_iteration_spaces() {
20 float a
[N
], b
[N
], c
[N
];
24 #pragma omp simd linear(S::ssi)
25 for (S::ssi
= 0; S::ssi
< 10; ++S::ssi
)
27 // expected-error@+1 {{shared variable cannot be private}}
28 #pragma omp simd private(S::ssi)
29 for (S::ssi
= 0; S::ssi
< 10; ++S::ssi
)
31 #pragma omp simd // no messages expected
32 for (S::ssi
= 0; S::ssi
< 10; ++S::ssi
)
35 for (int i
= 0; i
< 10; i
+=1) {
39 for (char i
= 0; i
< 10; i
++) {
43 for (char i
= 0; i
< 10; i
+='\1') {
47 for (long long i
= 0; i
< 10; i
++) {
50 // expected-error@+2 {{expression must have integral or unscoped enumeration type, not 'double'}}
52 for (long long i
= 0; i
< 10; i
+=1.5) {
56 for (long long i
= 0; i
< 'z'; i
+=1u) {
59 // expected-error@+2 {{variable must be of integer or random access iterator type}}
61 for (float fi
= 0; fi
< 10.0; fi
++) {
62 c
[(int)fi
] = a
[(int)fi
] + b
[(int)fi
];
64 // expected-error@+2 {{variable must be of integer or random access iterator type}}
66 for (double fi
= 0; fi
< 10.0; fi
++) {
67 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
++) {
73 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
75 for (int i
; i
< 10; i
++)
78 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
80 for (int i
= 0, j
= 0; i
< 10; ++i
)
83 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
88 // expected-warning@+3 {{expression result unused}}
89 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
91 for (ii
+ 1;ii
< 10; ++ii
)
94 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
96 for (c
[ii
] = 0;ii
< 10; ++ii
)
99 // Ok to skip parenthesises.
101 for (((ii
)) = 0;ii
< 10; ++ii
)
104 // omp4-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}} omp5-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'i'}}
106 for (int i
= 0; i
; i
++)
109 // omp4-error@+3 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}} omp5-error@+3 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'i'}}
110 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'i'}}
112 for (int i
= 0; jj
< kk
; ii
++)
115 // omp4-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}} omp5-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'i'}}
117 for (int i
= 0; !!i
; i
++)
120 // omp4-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}}
122 for (int i
= 0; i
!= 1; i
++)
125 // omp4-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'i'}} omp5-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'i'}}
127 for (int i
= 0; ; i
++)
132 for (int i
= 11; i
> 10; i
--)
137 for (int i
= 0; i
< 10; ++i
)
142 for (ii
= 0; ii
< 10; ++ii
)
145 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
147 for (ii
= 0; ii
< 10; ++jj
)
150 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
152 for (ii
= 0; ii
< 10; ++ ++ ii
)
155 // Ok but undefined behavior (in general, cannot check that incr
156 // is really loop-invariant).
158 for (ii
= 0; ii
< 10; ii
= ii
+ ii
)
161 // expected-error@+2 {{expression must have integral or unscoped enumeration type, not 'float'}}
163 for (ii
= 0; ii
< 10; ii
= ii
+ 1.0f
)
166 // Ok - step was converted to integer type.
168 for (ii
= 0; ii
< 10; ii
= ii
+ (int)1.1f
)
171 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
173 for (ii
= 0; ii
< 10; jj
= ii
+ 2)
176 // expected-warning@+3 {{relational comparison result unused}}
177 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
179 for (ii
= 0; ii
< 10; jj
> kk
+ 2)
182 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
184 for (ii
= 0; ii
< 10;)
187 // expected-warning@+3 {{expression result unused}}
188 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
190 for (ii
= 0; ii
< 10; !ii
)
193 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'ii'}}
195 for (ii
= 0; ii
< 10; ii
? ++ii
: ++jj
)
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; ii
= ii
< 10)
203 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
204 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
206 for (ii
= 0; ii
< 10; ii
= ii
+ 0)
209 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
210 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
212 for (ii
= 0; ii
< 10; ii
= ii
+ (int)(0.8 - 0.45))
215 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
216 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
218 for (ii
= 0; (ii
) < 10; ii
-=25)
221 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
222 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
224 for (ii
= 0; (ii
< 10); ii
-=0)
227 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
228 // expected-error@+2 {{increment expression must cause 'ii' to decrease on each iteration of OpenMP for loop}}
230 for (ii
= 0; ii
> 10; (ii
+=0))
233 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
234 // expected-error@+2 {{increment expression must cause 'ii' to increase on each iteration of OpenMP for loop}}
236 for (ii
= 0; ii
< 10; (ii
) = (1-1)+(ii
))
239 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
240 // expected-error@+2 {{increment expression must cause 'ii' to decrease on each iteration of OpenMP for loop}}
242 for ((ii
= 0); ii
> 10; (ii
-=0))
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}}
248 for (ii
= 0; (ii
< 10); (ii
-=0))
252 // expected-note@+3 {{defined as private}}
253 // expected-error@+3 {{loop iteration variable in the associated loop of 'omp simd' directive may not be private, predetermined as linear}}
255 #pragma omp simd private(ii)
256 for (ii
= 0; ii
< 10; ii
++)
260 // expected-note@+3 {{defined as lastprivate}}
261 // expected-error@+3 {{loop iteration variable in the associated loop of 'omp simd' directive may not be lastprivate, predetermined as linear}}
263 #pragma omp simd lastprivate(ii)
264 for (ii
= 0; ii
< 10; ii
++)
267 // expected-error@+1 {{unexpected OpenMP clause 'shared' in directive '#pragma omp simd'}}
268 #pragma omp simd shared(ii)
269 for (ii
= 0; ii
< 10; ii
++)
272 #pragma omp simd linear(ii)
273 for (ii
= 0; ii
< 10; ii
++)
276 #pragma omp simd lastprivate(ii) linear(jj) collapse(2) // expected-note {{defined as linear}}
277 for (ii
= 0; ii
< 10; ii
++)
278 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}}
284 // expected-error@+2 {{loop iteration variable in the associated loop of 'omp simd' directive may not be threadprivate or thread local, predetermined as linear}}
286 for (sii
= 0; sii
< 10; sii
+=1)
293 for (globalii
= 0; globalii
< 10; globalii
+=1)
294 c
[globalii
] = a
[globalii
];
299 #pragma omp simd collapse(2)
300 for (ii
= 0; ii
< 10; ii
+= 1)
301 for (globalii
= 0; globalii
< 10; globalii
+= 1)
302 c
[globalii
] += a
[globalii
] + ii
;
305 // omp4-error@+2 {{statement after '#pragma omp simd' must be a for loop}}
307 for (auto &item
: a
) {
311 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
312 // expected-error@+2 {{increment expression must cause 'i' to increase on each iteration of OpenMP for loop}}
314 for (unsigned i
= 9; i
< 10; i
--) {
318 int (*lb
)[4] = nullptr;
320 for (int (*p
)[4] = lb
; p
< lb
+ 8; ++p
) {
323 // expectedw-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
325 for (int a
{0}; a
<10; ++a
) {
331 // Iterators allowed in openmp for-loops.
333 struct random_access_iterator_tag
{ };
334 template <class Iter
> struct iterator_traits
{
335 typedef typename
Iter::difference_type difference_type
;
336 typedef typename
Iter::iterator_category iterator_category
;
338 template <class Iter
>
339 typename iterator_traits
<Iter
>::difference_type
340 distance(Iter first
, Iter last
) { return first
- last
; }
345 Iter0(const Iter0
&) { }
346 Iter0
operator ++() { return *this; }
347 Iter0
operator --() { return *this; }
348 Iter0
operator + (int delta
) { return *this; }
349 bool operator <(Iter0 a
) { return true; }
351 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'Iter0' for 1st argument}}
352 int operator -(Iter0 a
, Iter0 b
) { return 0; }
355 Iter1(float f
=0.0f
, double d
=0.0) { }
356 Iter1(const Iter1
&) { }
357 Iter1
operator ++() { return *this; }
358 Iter1
operator --() { return *this; }
359 bool operator <(Iter1 a
) { return true; }
360 bool operator >=(Iter1 a
) { return false; }
365 GoodIter(const GoodIter
&) { }
366 GoodIter(int fst
, int snd
) { }
367 GoodIter
&operator =(const GoodIter
&that
) { return *this; }
368 GoodIter
&operator =(const Iter0
&that
) { return *this; }
369 GoodIter
&operator +=(int x
) { return *this; }
370 explicit GoodIter(void *) { }
371 GoodIter
operator ++() { return *this; }
372 GoodIter
operator --() { return *this; }
373 bool operator !() { return true; }
374 bool operator <(GoodIter a
) { return true; }
375 bool operator <=(GoodIter a
) { return true; }
376 bool operator >=(GoodIter a
) { return false; }
377 typedef int difference_type
;
378 typedef std::random_access_iterator_tag iterator_category
;
380 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}}
381 int operator -(GoodIter a
, GoodIter b
) { return 0; }
382 // expected-note@+1 2 {{candidate function not viable: requires single argument 'a', but 2 arguments were provided}}
383 GoodIter
operator -(GoodIter a
) { return a
; }
384 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'GoodIter' for 1st argument}}
385 GoodIter
operator -(GoodIter a
, int v
) { return GoodIter(); }
386 GoodIter
operator +(GoodIter a
, int v
) { return GoodIter(); }
387 // expected-note@+1 2 {{candidate function not viable: no known conversion from 'Iter1' to 'int' for 1st argument}}
388 GoodIter
operator -(int v
, GoodIter a
) { return GoodIter(); }
389 GoodIter
operator +(int v
, GoodIter a
) { return GoodIter(); }
391 int test_with_random_access_iterator() {
395 for (GoodIter I
= begin
; I
< end
; ++I
)
397 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
399 for (GoodIter
&I
= begin
; I
< end
; ++I
)
402 for (GoodIter I
= begin
; I
>= end
; --I
)
404 // expectedw-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
406 for (GoodIter
I(begin
); I
< end
; ++I
)
408 // expectedw-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
410 for (GoodIter
I(nullptr); I
< end
; ++I
)
412 // expectedw-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
414 for (GoodIter
I(0); I
< end
; ++I
)
416 // expectedw-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
418 for (GoodIter
I(1,2); I
< end
; ++I
)
421 for (begin
= GoodIter(0); begin
< end
; ++begin
)
424 for (begin
= GoodIter(1,2); begin
< end
; ++begin
)
426 // expected-error@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
428 for (++begin
; begin
< end
; ++begin
)
431 for (begin
= end
; begin
< end
; ++begin
)
433 // omp4-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'I'}} omp5-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'I'}}
435 for (GoodIter I
= begin
; I
- I
; ++I
)
437 // omp4-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'I'}} omp5-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'I'}}
439 for (GoodIter I
= begin
; begin
< end
; ++I
)
441 // omp4-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', or '>=') of loop variable 'I'}} omp5-error@+2 {{condition of OpenMP for loop must be a relational comparison ('<', '<=', '>', '>=', or '!=') of loop variable 'I'}}
443 for (GoodIter I
= begin
; !I
; ++I
)
445 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
446 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
448 for (GoodIter I
= begin
; I
>= end
; I
= I
+ 1)
451 for (GoodIter I
= begin
; I
>= end
; I
= I
- 1)
453 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}}
455 for (GoodIter I
= begin
; I
>= end
; I
= -I
)
457 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
458 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
460 for (GoodIter I
= begin
; I
>= end
; I
= 2 + I
)
462 // expected-error@+2 {{increment clause of OpenMP for loop must perform simple addition or subtraction on loop variable 'I'}}
464 for (GoodIter I
= begin
; I
>= end
; I
= 2 - I
)
467 for (Iter0 I
= begin0
; I
< end0
; ++I
)
470 // Initializer is constructor without params.
471 // expectedw-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
473 for (Iter0 I
; I
< end0
; ++I
)
477 // expected-error@+3 {{invalid operands to binary expression ('Iter1' and 'Iter1')}}
478 // expected-error@+2 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}
480 for (Iter1 I
= begin1
; I
< end1
; ++I
)
482 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
483 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
485 for (Iter1 I
= begin1
; I
>= end1
; ++I
)
488 // Initializer is constructor with all default params.
489 // expected-error@+4 {{invalid operands to binary expression ('Iter1' and 'float')}}
490 // expected-error@+3 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}}
491 // expectedw-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}}
493 for (Iter1 I
; I
< end1
; ++I
) {
499 template <typename IT
, int ST
> class TC
{
501 int dotest_lt(IT begin
, IT end
) {
502 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
503 // expected-error@+2 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}}
505 for (IT I
= begin
; I
< end
; I
= I
+ ST
) {
508 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
509 // expected-error@+2 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}}
511 for (IT I
= begin
; I
<= end
; I
+= ST
) {
515 for (IT I
= begin
; I
< end
; ++I
) {
524 template <typename IT
, int ST
=0> int dotest_gt(IT begin
, IT end
) {
525 // expected-note@+3 2 {{loop step is expected to be negative due to this condition}}
526 // expected-error@+2 2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
528 for (IT I
= begin
; I
>= end
; I
= I
+ ST
) {
531 // expected-note@+3 2 {{loop step is expected to be negative due to this condition}}
532 // expected-error@+2 2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
534 for (IT I
= begin
; I
>= end
; I
+= ST
) {
538 // expected-note@+3 {{loop step is expected to be negative due to this condition}}
539 // expected-error@+2 {{increment expression must cause 'I' to decrease on each iteration of OpenMP for loop}}
541 for (IT I
= begin
; I
>= end
; ++I
) {
546 for (IT I
= begin
; I
< end
; I
+=TC
<int,ST
>::step()) {
551 void test_with_template() {
553 TC
<GoodIter
, 100> t1
;
554 TC
<GoodIter
, -100> t2
;
555 t1
.dotest_lt(begin
, end
);
556 t2
.dotest_lt(begin
, end
); // expected-note {{in instantiation of member function 'TC<GoodIter, -100>::dotest_lt' requested here}}
557 dotest_gt(begin
, end
); // expected-note {{in instantiation of function template specialization 'dotest_gt<GoodIter, 0>' requested here}}
558 dotest_gt
<unsigned, 10>(0, 100); // expected-note {{in instantiation of function template specialization 'dotest_gt<unsigned int, 10>' requested here}}
561 void test_loop_break() {
563 float a
[N
], b
[N
], c
[N
];
565 for (int i
= 0; i
< 10; i
++) {
567 for (int j
= 0; j
< 10; ++j
) {
569 break; // OK in nested loop
579 break; // expected-error {{'break' statement cannot be used in OpenMP for loop}}
582 break; // expected-error {{'break' statement cannot be used in OpenMP for loop}}
586 for (int i
= 0; i
< 10; i
++) {
587 for (int j
= 0; j
< 10; j
++) {
598 void test_loop_eh() {
600 float a
[N
], b
[N
], c
[N
];
602 for (int i
= 0; i
< 10; i
++) {
604 try { // expected-error {{'try' statement cannot be used in OpenMP simd region}}
605 for (int j
= 0; j
< 10; ++j
) {
607 throw a
[i
]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
609 throw a
[i
]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
613 throw a
[i
]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
614 return; // expected-error {{cannot return from OpenMP region}}
623 for (int j
= 0; j
< 10; j
++) {
625 throw c
[i
]; // expected-error {{'throw' statement cannot be used in OpenMP simd region}}
632 for (int i
= 0; i
< 10; ++i
) {
634 void g() { throw 0; }