Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / for_misc_messages.c
blob124dfdb3cd100ab1e8545242eacc6ac3ddd3aa01
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
9 void xxx(int argc) {
10 int x; // expected-note {{initialize the variable 'x' to silence this warning}}
11 #pragma omp for
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'}}
17 #pragma omp for
19 // expected-error@+1 {{unexpected OpenMP directive '#pragma omp for'}}
20 #pragma omp for foo
22 void test_no_clause(void) {
23 int i;
24 #pragma omp for
25 for (i = 0; i < 16; ++i)
28 // expected-error@+2 {{statement after '#pragma omp for' must be a for loop}}
29 #pragma omp for
30 ++i;
33 void test_branch_protected_scope(void) {
34 int i = 0;
35 L1:
36 ++i;
38 int x[24];
40 #pragma omp parallel
41 #pragma omp for
42 for (i = 0; i < 16; ++i) {
43 if (i == 5)
44 goto L1; // expected-error {{use of undeclared label 'L1'}}
45 else if (i == 6)
46 return; // expected-error {{cannot return from OpenMP region}}
47 else if (i == 7)
48 goto L2;
49 else if (i == 8) {
50 L2:
51 x[i]++;
55 if (x[0] == 0)
56 goto L2; // expected-error {{use of undeclared label 'L2'}}
57 else if (x[1] == 1)
58 goto L1;
61 void test_invalid_clause(void) {
62 int i;
63 #pragma omp parallel
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'}}
79 #pragma omp for if(0)
80 for (i = 0; i < 16; ++i)
84 void test_non_identifiers(void) {
85 int i, x;
87 #pragma omp parallel
88 // expected-warning@+1 {{extra tokens at the end of '#pragma omp for' are ignored}}
89 #pragma omp for;
90 for (i = 0; i < 16; ++i)
92 // expected-warning@+2 {{extra tokens at the end of '#pragma omp for' are ignored}}
93 #pragma omp parallel
94 #pragma omp for linear(x);
95 for (i = 0; i < 16; ++i)
98 #pragma omp parallel
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)
104 #pragma omp parallel
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) {
114 int i;
115 #pragma omp parallel
116 // expected-error@+1 {{expected '('}}
117 #pragma omp for collapse
118 for (i = 0; i < 16; ++i)
120 #pragma omp parallel
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)
125 #pragma omp parallel
126 // expected-error@+1 {{expected expression}}
127 #pragma omp for collapse()
128 for (i = 0; i < 16; ++i)
130 #pragma omp parallel
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)
135 #pragma omp parallel
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)
140 #pragma omp parallel
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)
146 #pragma omp parallel
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}}
152 #pragma omp parallel
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}}
158 #pragma omp parallel
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}}
164 #pragma omp parallel
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}}
169 #pragma omp parallel
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}}
175 #pragma omp parallel
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}}
181 #pragma omp parallel
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)
187 foo();
188 #pragma omp parallel
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}}
194 #pragma omp parallel
195 // expected-error@+1 {{integer constant expression}}
196 #pragma omp for collapse(2.5)
197 for (i = 0; i < 16; ++i)
199 #pragma omp parallel
200 // expected-error@+1 {{integer constant expression}}
201 #pragma omp for collapse(foo())
202 for (i = 0; i < 16; ++i)
204 #pragma omp parallel
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)
209 #pragma omp parallel
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)
214 #pragma omp parallel
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)
219 #pragma omp parallel
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)
228 i += j;
231 void test_private(void) {
232 int i;
233 #pragma omp parallel
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)
239 #pragma omp parallel
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)
245 #pragma omp parallel
246 // expected-error@+1 2 {{expected expression}}
247 #pragma omp for private(, )
248 for (i = 0; i < 16; ++i)
250 #pragma omp parallel
251 // expected-error@+1 {{expected expression}}
252 #pragma omp for private()
253 for (i = 0; i < 16; ++i)
255 #pragma omp parallel
256 // expected-error@+1 {{expected expression}}
257 #pragma omp for private(int)
258 for (i = 0; i < 16; ++i)
260 #pragma omp parallel
261 // expected-error@+1 {{expected variable name}}
262 #pragma omp for private(0)
263 for (i = 0; i < 16; ++i)
266 int x, y, z;
267 #pragma omp parallel
268 #pragma omp for private(x)
269 for (i = 0; i < 16; ++i)
271 #pragma omp parallel
272 #pragma omp for private(x, y)
273 for (i = 0; i < 16; ++i)
275 #pragma omp parallel
276 #pragma omp for private(x, y, z)
277 for (i = 0; i < 16; ++i) {
278 x = y * i + z;
282 void test_lastprivate(void) {
283 int i;
284 #pragma omp parallel
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)
291 #pragma omp parallel
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)
297 #pragma omp parallel
298 // expected-error@+1 2 {{expected expression}}
299 #pragma omp for lastprivate(, )
300 for (i = 0; i < 16; ++i)
302 #pragma omp parallel
303 // expected-error@+1 {{expected expression}}
304 #pragma omp for lastprivate()
305 for (i = 0; i < 16; ++i)
307 #pragma omp parallel
308 // expected-error@+1 {{expected expression}}
309 #pragma omp for lastprivate(int)
310 for (i = 0; i < 16; ++i)
312 #pragma omp parallel
313 // expected-error@+1 {{expected variable name}}
314 #pragma omp for lastprivate(0)
315 for (i = 0; i < 16; ++i)
318 int x, y, z;
319 #pragma omp parallel
320 #pragma omp for lastprivate(x)
321 for (i = 0; i < 16; ++i)
323 #pragma omp parallel
324 #pragma omp for lastprivate(x, y)
325 for (i = 0; i < 16; ++i)
327 #pragma omp parallel
328 #pragma omp for lastprivate(x, y, z)
329 for (i = 0; i < 16; ++i)
333 void test_firstprivate(void) {
334 int i;
335 #pragma omp parallel
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)
342 #pragma omp parallel
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)
348 #pragma omp parallel
349 // expected-error@+1 2 {{expected expression}}
350 #pragma omp for firstprivate(, )
351 for (i = 0; i < 16; ++i)
353 #pragma omp parallel
354 // expected-error@+1 {{expected expression}}
355 #pragma omp for firstprivate()
356 for (i = 0; i < 16; ++i)
358 #pragma omp parallel
359 // expected-error@+1 {{expected expression}}
360 #pragma omp for firstprivate(int)
361 for (i = 0; i < 16; ++i)
363 #pragma omp parallel
364 // expected-error@+1 {{expected variable name}}
365 #pragma omp for firstprivate(0)
366 for (i = 0; i < 16; ++i)
369 int x, y, z;
370 #pragma omp parallel
371 #pragma omp for lastprivate(x) firstprivate(x)
372 for (i = 0; i < 16; ++i)
374 #pragma omp parallel
375 #pragma omp for lastprivate(x, y) firstprivate(x, y)
376 for (i = 0; i < 16; ++i)
378 #pragma omp parallel
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];
386 #pragma omp parallel
387 // expected-error@+2 {{variable must be of integer or pointer type}}
388 #pragma omp for
389 for (float fi = 0; fi < 10.0; fi++) {
390 c[(int)fi] = a[(int)fi] + b[(int)fi];
392 #pragma omp parallel
393 // expected-error@+2 {{variable must be of integer or pointer type}}
394 #pragma omp for
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}}
400 #pragma omp for
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)