1 // RUN: %clang_cc1 -fsyntax-only -fopenmp -fopenmp-version=45 -triple x86_64-unknown-unknown -verify=expected,omp45 %s -Wuninitialized
2 // RUN: %clang_cc1 -fsyntax-only -fopenmp -fopenmp-version=50 -triple x86_64-unknown-unknown -verify=expected,omp50 %s -Wuninitialized
3 // RUN: %clang_cc1 -fsyntax-only -fopenmp -triple x86_64-unknown-unknown -verify=expected,omp51 %s -Wuninitialized
5 // RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -fopenmp-version=45 -triple x86_64-unknown-unknown -verify=expected,omp45 %s -Wuninitialized
6 // RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -fopenmp-version=50 -triple x86_64-unknown-unknown -verify=expected,omp50 %s -Wuninitialized
7 // RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -triple x86_64-unknown-unknown -verify=expected,omp51 %s -Wuninitialized
10 int x
; // expected-note {{initialize the variable 'x' to silence this warning}}
12 for (int i
= 0; i
< 10; ++i
)
13 argc
= x
; // expected-warning {{variable 'x' is uninitialized when used here}}
16 // expected-error@+1 {{unexpected OpenMP directive '#pragma omp for'}}
19 // expected-error@+1 {{unexpected OpenMP directive '#pragma omp for'}}
22 void test_no_clause(void) {
25 for (i
= 0; i
< 16; ++i
)
28 // expected-error@+2 {{statement after '#pragma omp for' must be a for loop}}
33 void test_branch_protected_scope(void) {
42 for (i
= 0; i
< 16; ++i
) {
44 goto L1
; // expected-error {{use of undeclared label 'L1'}}
46 return; // expected-error {{cannot return from OpenMP region}}
56 goto L2
; // expected-error {{use of undeclared label 'L2'}}
61 void test_invalid_clause(void) {
64 // expected-warning@+1 {{extra tokens at the end of '#pragma omp for' are ignored}}
65 #pragma omp for foo bar
66 for (i
= 0; i
< 16; ++i
)
68 // At one time, this failed an assert.
69 // expected-error@+1 {{unexpected OpenMP clause 'num_teams' in directive '#pragma omp for'}}
70 #pragma omp for num_teams(3)
71 for (i
= 0; i
< 16; ++i
)
73 // At one time, this error was reported twice.
74 // expected-error@+1 {{unexpected OpenMP clause 'uniform' in directive '#pragma omp for'}}
75 #pragma omp for uniform
76 for (i
= 0; i
< 16; ++i
)
78 // expected-error@+1 {{unexpected OpenMP clause 'if' in directive '#pragma omp for'}}
80 for (i
= 0; i
< 16; ++i
)
84 void test_non_identifiers(void) {
88 // expected-warning@+1 {{extra tokens at the end of '#pragma omp for' are ignored}}
90 for (i
= 0; i
< 16; ++i
)
92 // expected-warning@+2 {{extra tokens at the end of '#pragma omp for' are ignored}}
94 #pragma omp for linear(x);
95 for (i
= 0; i
< 16; ++i
)
99 // expected-warning@+1 {{extra tokens at the end of '#pragma omp for' are ignored}}
100 #pragma omp for private(x);
101 for (i
= 0; i
< 16; ++i
)
105 // expected-warning@+1 {{extra tokens at the end of '#pragma omp for' are ignored}}
106 #pragma omp for, private(x);
107 for (i
= 0; i
< 16; ++i
)
111 extern int foo(void);
113 void test_collapse(void) {
116 // expected-error@+1 {{expected '('}}
117 #pragma omp for collapse
118 for (i
= 0; i
< 16; ++i
)
121 // expected-error@+1 {{expected expression}} expected-error@+1 {{expected ')'}} expected-note@+1 {{to match this '('}}
122 #pragma omp for collapse(
123 for (i
= 0; i
< 16; ++i
)
126 // expected-error@+1 {{expected expression}}
127 #pragma omp for collapse()
128 for (i
= 0; i
< 16; ++i
)
131 // expected-error@+1 {{expected expression}} expected-error@+1 {{expected ')'}} expected-note@+1 {{to match this '('}}
132 #pragma omp for collapse(,
133 for (i
= 0; i
< 16; ++i
)
136 // expected-error@+1 {{expected expression}} expected-error@+1 {{expected ')'}} expected-note@+1 {{to match this '('}}
137 #pragma omp for collapse(, )
138 for (i
= 0; i
< 16; ++i
)
141 // expected-warning@+2 {{extra tokens at the end of '#pragma omp for' are ignored}}
142 // expected-error@+1 {{expected '('}}
143 #pragma omp for collapse 4)
144 for (i
= 0; i
< 16; ++i
)
147 // expected-error@+2 {{expected ')'}}
148 // expected-note@+1 {{to match this '('}} expected-note@+1 {{as specified in 'collapse' clause}}
149 #pragma omp for collapse(4
150 for (i
= 0; i
< 16; ++i
)
151 ; // expected-error {{expected 4 for loops after '#pragma omp for', but found only 1}}
153 // expected-error@+2 {{expected ')'}}
154 // expected-note@+1 {{to match this '('}} expected-note@+1 {{as specified in 'collapse' clause}}
155 #pragma omp for collapse(4,
156 for (i
= 0; i
< 16; ++i
)
157 ; // expected-error {{expected 4 for loops after '#pragma omp for', but found only 1}}
159 // expected-error@+2 {{expected ')'}}
160 // expected-note@+1 {{to match this '('}} expected-note@+1 {{as specified in 'collapse' clause}}
161 #pragma omp for collapse(4, )
162 for (i
= 0; i
< 16; ++i
)
163 ; // expected-error {{expected 4 for loops after '#pragma omp for', but found only 1}}
165 // expected-note@+1 {{as specified in 'collapse' clause}}
166 #pragma omp for collapse(4)
167 for (i
= 0; i
< 16; ++i
)
168 ; // expected-error {{expected 4 for loops after '#pragma omp for', but found only 1}}
170 // expected-error@+2 {{expected ')'}}
171 // expected-note@+1 {{to match this '('}} expected-note@+1 {{as specified in 'collapse' clause}}
172 #pragma omp for collapse(4 4)
173 for (i
= 0; i
< 16; ++i
)
174 ; // expected-error {{expected 4 for loops after '#pragma omp for', but found only 1}}
176 // expected-error@+2 {{expected ')'}}
177 // expected-note@+1 {{to match this '('}} expected-note@+1 {{as specified in 'collapse' clause}}
178 #pragma omp for collapse(4, , 4)
179 for (i
= 0; i
< 16; ++i
)
180 ; // expected-error {{expected 4 for loops after '#pragma omp for', but found only 1}}
182 #pragma omp for collapse(4)
183 for (int i1
= 0; i1
< 16; ++i1
)
184 for (int i2
= 0; i2
< 16; ++i2
)
185 for (int i3
= 0; i3
< 16; ++i3
)
186 for (int i4
= 0; i4
< 16; ++i4
)
189 // expected-error@+2 {{expected ')'}}
190 // expected-note@+1 {{to match this '('}} expected-note@+1 {{as specified in 'collapse' clause}}
191 #pragma omp for collapse(4, 8)
192 for (i
= 0; i
< 16; ++i
)
193 ; // expected-error {{expected 4 for loops after '#pragma omp for', but found only 1}}
195 // expected-error@+1 {{integer constant expression}}
196 #pragma omp for collapse(2.5)
197 for (i
= 0; i
< 16; ++i
)
200 // expected-error@+1 {{integer constant expression}}
201 #pragma omp for collapse(foo())
202 for (i
= 0; i
< 16; ++i
)
205 // expected-error@+1 {{argument to 'collapse' clause must be a strictly positive integer value}}
206 #pragma omp for collapse(-5)
207 for (i
= 0; i
< 16; ++i
)
210 // expected-error@+1 {{argument to 'collapse' clause must be a strictly positive integer value}}
211 #pragma omp for collapse(0)
212 for (i
= 0; i
< 16; ++i
)
215 // expected-error@+1 {{argument to 'collapse' clause must be a strictly positive integer value}}
216 #pragma omp for collapse(5 - 5)
217 for (i
= 0; i
< 16; ++i
)
220 #pragma omp for collapse(2)
221 for (i
= 0; i
< 16; ++i
) // expected-note {{defined as private}}
222 // expected-note@+1 {{variable with automatic storage duration is predetermined as private; perhaps you forget to enclose 'omp for' directive into a parallel or another task region?}}
223 for (int j
= 0; j
< 16; ++j
)
224 // expected-error@+2 2 {{reduction variable must be shared}}
225 // expected-error@+1 {{region cannot be closely nested inside 'for' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}}
226 #pragma omp for reduction(+ : i, j)
227 for (int k
= 0; k
< 16; ++k
)
231 void test_private(void) {
234 // expected-error@+2 {{expected expression}}
235 // expected-error@+1 {{expected ')'}} expected-note@+1 {{to match this '('}}
236 #pragma omp for private(
237 for (i
= 0; i
< 16; ++i
)
240 // expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
241 // expected-error@+1 2 {{expected expression}}
242 #pragma omp for private(,
243 for (i
= 0; i
< 16; ++i
)
246 // expected-error@+1 2 {{expected expression}}
247 #pragma omp for private(, )
248 for (i
= 0; i
< 16; ++i
)
251 // expected-error@+1 {{expected expression}}
252 #pragma omp for private()
253 for (i
= 0; i
< 16; ++i
)
256 // expected-error@+1 {{expected expression}}
257 #pragma omp for private(int)
258 for (i
= 0; i
< 16; ++i
)
261 // expected-error@+1 {{expected variable name}}
262 #pragma omp for private(0)
263 for (i
= 0; i
< 16; ++i
)
268 #pragma omp for private(x)
269 for (i
= 0; i
< 16; ++i
)
272 #pragma omp for private(x, y)
273 for (i
= 0; i
< 16; ++i
)
276 #pragma omp for private(x, y, z)
277 for (i
= 0; i
< 16; ++i
) {
282 void test_lastprivate(void) {
285 // expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
286 // expected-error@+1 {{expected expression}}
287 #pragma omp for lastprivate(
288 for (i
= 0; i
< 16; ++i
)
292 // expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
293 // expected-error@+1 2 {{expected expression}}
294 #pragma omp for lastprivate(,
295 for (i
= 0; i
< 16; ++i
)
298 // expected-error@+1 2 {{expected expression}}
299 #pragma omp for lastprivate(, )
300 for (i
= 0; i
< 16; ++i
)
303 // expected-error@+1 {{expected expression}}
304 #pragma omp for lastprivate()
305 for (i
= 0; i
< 16; ++i
)
308 // expected-error@+1 {{expected expression}}
309 #pragma omp for lastprivate(int)
310 for (i
= 0; i
< 16; ++i
)
313 // expected-error@+1 {{expected variable name}}
314 #pragma omp for lastprivate(0)
315 for (i
= 0; i
< 16; ++i
)
320 #pragma omp for lastprivate(x)
321 for (i
= 0; i
< 16; ++i
)
324 #pragma omp for lastprivate(x, y)
325 for (i
= 0; i
< 16; ++i
)
328 #pragma omp for lastprivate(x, y, z)
329 for (i
= 0; i
< 16; ++i
)
333 void test_firstprivate(void) {
336 // expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
337 // expected-error@+1 {{expected expression}}
338 #pragma omp for firstprivate(
339 for (i
= 0; i
< 16; ++i
)
343 // expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
344 // expected-error@+1 2 {{expected expression}}
345 #pragma omp for firstprivate(,
346 for (i
= 0; i
< 16; ++i
)
349 // expected-error@+1 2 {{expected expression}}
350 #pragma omp for firstprivate(, )
351 for (i
= 0; i
< 16; ++i
)
354 // expected-error@+1 {{expected expression}}
355 #pragma omp for firstprivate()
356 for (i
= 0; i
< 16; ++i
)
359 // expected-error@+1 {{expected expression}}
360 #pragma omp for firstprivate(int)
361 for (i
= 0; i
< 16; ++i
)
364 // expected-error@+1 {{expected variable name}}
365 #pragma omp for firstprivate(0)
366 for (i
= 0; i
< 16; ++i
)
371 #pragma omp for lastprivate(x) firstprivate(x)
372 for (i
= 0; i
< 16; ++i
)
375 #pragma omp for lastprivate(x, y) firstprivate(x, y)
376 for (i
= 0; i
< 16; ++i
)
379 #pragma omp for lastprivate(x, y, z) firstprivate(x, y, z)
380 for (i
= 0; i
< 16; ++i
)
384 void test_loop_messages(void) {
385 float a
[100], b
[100], c
[100];
387 // expected-error@+2 {{variable must be of integer or pointer type}}
389 for (float fi
= 0; fi
< 10.0; fi
++) {
390 c
[(int)fi
] = a
[(int)fi
] + b
[(int)fi
];
393 // expected-error@+2 {{variable must be of integer or pointer type}}
395 for (double fi
= 0; fi
< 10.0; fi
++) {
396 c
[(int)fi
] = a
[(int)fi
] + b
[(int)fi
];
399 // expected-warning@+2 {{OpenMP loop iteration variable cannot have more than 64 bits size and will be narrowed}}
401 for (__int128 ii
= 0; ii
< 10; ii
++) {
402 c
[ii
] = a
[ii
] + b
[ii
];
404 #pragma omp for order // omp45-error {{unexpected OpenMP clause 'order' in directive '#pragma omp for'}} expected-error {{expected '(' after 'order'}}
405 for (int i
= 0; i
< 10; ++i
)
407 #pragma omp for order( // omp45-error {{unexpected OpenMP clause 'order' in directive '#pragma omp for'}} expected-error {{expected ')'}} expected-note {{to match this '('}} omp50-error {{expected 'concurrent' in OpenMP clause 'order'}} omp51-error {{expected 'concurrent' in OpenMP clause 'order'}}
408 for (int i
= 0; i
< 10; ++i
)
410 #pragma omp for order(none // omp45-error {{unexpected OpenMP clause 'order' in directive '#pragma omp for'}} expected-error {{expected ')'}} expected-note {{to match this '('}} omp50-error {{expected 'concurrent' in OpenMP clause 'order'}} omp51-error {{expected 'concurrent' in OpenMP clause 'order'}}
411 for (int i
= 0; i
< 10; ++i
)
413 #pragma omp for order(concurrent // omp45-error {{unexpected OpenMP clause 'order' in directive '#pragma omp for'}} expected-error {{expected ')'}} expected-note {{to match this '('}}
414 for (int i
= 0; i
< 10; ++i
)
416 #pragma omp for order(concurrent) // omp45-error {{unexpected OpenMP clause 'order' in directive '#pragma omp for'}}
417 for (int i
= 0; i
< 10; ++i
)
419 #pragma omp for ordered order(concurrent) // omp45-error {{unexpected OpenMP clause 'order' in directive '#pragma omp for'}} omp50-error {{'order' clause with 'concurrent' modifier cannot be specified if an 'ordered' clause is specified}} omp50-note {{'ordered' clause}} omp51-error {{'order' clause with 'concurrent' modifier cannot be specified if an 'ordered' clause is specified}} omp51-note {{'ordered' clause}}
420 for (int i
= 0; i
< 10; ++i
)
422 #pragma omp for order(unconstrained:) // omp45-error {{unexpected OpenMP clause 'order' in directive '#pragma omp for'}} omp50-error {{expected 'concurrent' in OpenMP clause 'order'}} omp51-error {{expected 'concurrent' in OpenMP clause 'order'}}
423 for (int i
= 0; i
< 10; ++i
)
425 #pragma omp for order(reproducible:concurrent // omp45-error {{unexpected OpenMP clause 'order' in directive '#pragma omp for'}} expected-error {{expected ')'}} expected-note {{to match this '('}} omp50-error {{expected 'concurrent' in OpenMP clause 'order'}}
426 for (int i
= 0; i
< 10; ++i
)
428 #pragma omp for order(reproducible:concurrent) // omp45-error {{unexpected OpenMP clause 'order' in directive '#pragma omp for'}} omp50-error {{expected 'concurrent' in OpenMP clause 'order'}}
429 for (int i
= 0; i
< 10; ++i
)
431 #pragma omp for order(unconstrained:concurrent) // omp45-error {{unexpected OpenMP clause 'order' in directive '#pragma omp for'}} omp50-error {{expected 'concurrent' in OpenMP clause 'order'}}
432 for (int i
= 0; i
< 10; ++i
)
434 #pragma omp for order(concurrent) order(concurrent) // omp45-error {{unexpected OpenMP clause 'order' in directive '#pragma omp for'}} omp45-error {{unexpected OpenMP clause 'order' in directive '#pragma omp for'}} omp51-error {{directive '#pragma omp for' cannot contain more than one 'order' clause}}
435 for (int i
= 0; i
< 10; ++i
)