[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / OpenMP / taskloop_misc_messages.c
blobe2ff1101f19f161af539b34306ad32a5d170642c
1 // RUN: %clang_cc1 -fsyntax-only -fopenmp -triple x86_64-unknown-unknown -verify %s -Wuninitialized
3 // RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -triple x86_64-unknown-unknown -verify %s -Wuninitialized
5 void xxx(int argc) {
6 int x; // expected-note {{initialize the variable 'x' to silence this warning}}
7 #pragma omp taskloop
8 for (int i = 0; i < 10; ++i)
9 argc = x; // expected-warning {{variable 'x' is uninitialized when used here}}
12 // expected-error@+1 {{unexpected OpenMP directive '#pragma omp taskloop'}}
13 #pragma omp taskloop
15 // expected-error@+1 {{unexpected OpenMP directive '#pragma omp taskloop'}}
16 #pragma omp taskloop foo
18 void test_no_clause(void) {
19 int i;
20 #pragma omp taskloop
21 for (i = 0; i < 16; ++i)
24 // expected-error@+2 {{statement after '#pragma omp taskloop' must be a for loop}}
25 #pragma omp taskloop
26 ++i;
29 void test_branch_protected_scope(void) {
30 int i = 0;
31 L1:
32 ++i;
34 int x[24];
36 #pragma omp parallel
37 #pragma omp taskloop
38 for (i = 0; i < 16; ++i) {
39 if (i == 5)
40 goto L1; // expected-error {{use of undeclared label 'L1'}}
41 else if (i == 6)
42 return; // expected-error {{cannot return from OpenMP region}}
43 else if (i == 7)
44 goto L2;
45 else if (i == 8) {
46 L2:
47 x[i]++;
51 if (x[0] == 0)
52 goto L2; // expected-error {{use of undeclared label 'L2'}}
53 else if (x[1] == 1)
54 goto L1;
57 void test_invalid_clause(void) {
58 int i;
59 #pragma omp parallel
60 // expected-warning@+1 {{extra tokens at the end of '#pragma omp taskloop' are ignored}}
61 #pragma omp taskloop foo bar
62 for (i = 0; i < 16; ++i)
64 // expected-error@+1 {{directive '#pragma omp taskloop' cannot contain more than one 'nogroup' clause}}
65 #pragma omp taskloop nogroup nogroup
66 for (i = 0; i < 16; ++i)
70 void test_non_identifiers(void) {
71 int i, x;
73 #pragma omp parallel
74 // expected-warning@+1 {{extra tokens at the end of '#pragma omp taskloop' are ignored}}
75 #pragma omp taskloop;
76 for (i = 0; i < 16; ++i)
78 // expected-warning@+3 {{extra tokens at the end of '#pragma omp taskloop' are ignored}}
79 // expected-error@+2 {{unexpected OpenMP clause 'linear' in directive '#pragma omp taskloop'}}
80 #pragma omp parallel
81 #pragma omp taskloop linear(x);
82 for (i = 0; i < 16; ++i)
85 #pragma omp parallel
86 // expected-warning@+1 {{extra tokens at the end of '#pragma omp taskloop' are ignored}}
87 #pragma omp taskloop private(x);
88 for (i = 0; i < 16; ++i)
91 #pragma omp parallel
92 // expected-warning@+1 {{extra tokens at the end of '#pragma omp taskloop' are ignored}}
93 #pragma omp taskloop, private(x);
94 for (i = 0; i < 16; ++i)
98 extern int foo(void);
100 void test_collapse(void) {
101 int i;
102 #pragma omp parallel
103 // expected-error@+1 {{expected '('}}
104 #pragma omp taskloop collapse
105 for (i = 0; i < 16; ++i)
107 #pragma omp parallel
108 // expected-error@+1 {{expected expression}} expected-error@+1 {{expected ')'}} expected-note@+1 {{to match this '('}}
109 #pragma omp taskloop collapse(
110 for (i = 0; i < 16; ++i)
112 #pragma omp parallel
113 // expected-error@+1 {{expected expression}}
114 #pragma omp taskloop collapse()
115 for (i = 0; i < 16; ++i)
117 #pragma omp parallel
118 // expected-error@+1 {{expected expression}} expected-error@+1 {{expected ')'}} expected-note@+1 {{to match this '('}}
119 #pragma omp taskloop collapse(,
120 for (i = 0; i < 16; ++i)
122 #pragma omp parallel
123 // expected-error@+1 {{expected expression}} expected-error@+1 {{expected ')'}} expected-note@+1 {{to match this '('}}
124 #pragma omp taskloop collapse(, )
125 for (i = 0; i < 16; ++i)
127 #pragma omp parallel
128 // expected-warning@+2 {{extra tokens at the end of '#pragma omp taskloop' are ignored}}
129 // expected-error@+1 {{expected '('}}
130 #pragma omp taskloop collapse 4)
131 for (i = 0; i < 16; ++i)
133 #pragma omp parallel
134 // expected-error@+2 {{expected ')'}}
135 // expected-note@+1 {{to match this '('}} expected-note@+1 {{as specified in 'collapse' clause}}
136 #pragma omp taskloop collapse(4
137 for (i = 0; i < 16; ++i)
138 ; // expected-error {{expected 4 for loops after '#pragma omp taskloop', but found only 1}}
139 #pragma omp parallel
140 // expected-error@+2 {{expected ')'}}
141 // expected-note@+1 {{to match this '('}} expected-note@+1 {{as specified in 'collapse' clause}}
142 #pragma omp taskloop collapse(4,
143 for (i = 0; i < 16; ++i)
144 ; // expected-error {{expected 4 for loops after '#pragma omp taskloop', but found only 1}}
145 #pragma omp parallel
146 // expected-error@+2 {{expected ')'}}
147 // expected-note@+1 {{to match this '('}} expected-note@+1 {{as specified in 'collapse' clause}}
148 #pragma omp taskloop collapse(4, )
149 for (i = 0; i < 16; ++i)
150 ; // expected-error {{expected 4 for loops after '#pragma omp taskloop', but found only 1}}
151 #pragma omp parallel
152 // expected-note@+1 {{as specified in 'collapse' clause}}
153 #pragma omp taskloop collapse(4)
154 for (i = 0; i < 16; ++i)
155 ; // expected-error {{expected 4 for loops after '#pragma omp taskloop', but found only 1}}
156 #pragma omp parallel
157 // expected-error@+2 {{expected ')'}}
158 // expected-note@+1 {{to match this '('}} expected-note@+1 {{as specified in 'collapse' clause}}
159 #pragma omp taskloop collapse(4 4)
160 for (i = 0; i < 16; ++i)
161 ; // expected-error {{expected 4 for loops after '#pragma omp taskloop', but found only 1}}
162 #pragma omp parallel
163 // expected-error@+2 {{expected ')'}}
164 // expected-note@+1 {{to match this '('}} expected-note@+1 {{as specified in 'collapse' clause}}
165 #pragma omp taskloop collapse(4, , 4)
166 for (i = 0; i < 16; ++i)
167 ; // expected-error {{expected 4 for loops after '#pragma omp taskloop', but found only 1}}
168 #pragma omp parallel
169 #pragma omp taskloop collapse(4)
170 for (int i1 = 0; i1 < 16; ++i1)
171 for (int i2 = 0; i2 < 16; ++i2)
172 for (int i3 = 0; i3 < 16; ++i3)
173 for (int i4 = 0; i4 < 16; ++i4)
174 foo();
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 taskloop collapse(4, 8)
179 for (i = 0; i < 16; ++i)
180 ; // expected-error {{expected 4 for loops after '#pragma omp taskloop', but found only 1}}
181 #pragma omp parallel
182 // expected-error@+1 {{integer constant expression}}
183 #pragma omp taskloop collapse(2.5)
184 for (i = 0; i < 16; ++i)
186 #pragma omp parallel
187 // expected-error@+1 {{integer constant expression}}
188 #pragma omp taskloop collapse(foo())
189 for (i = 0; i < 16; ++i)
191 #pragma omp parallel
192 // expected-error@+1 {{argument to 'collapse' clause must be a strictly positive integer value}}
193 #pragma omp taskloop collapse(-5)
194 for (i = 0; i < 16; ++i)
196 #pragma omp parallel
197 // expected-error@+1 {{argument to 'collapse' clause must be a strictly positive integer value}}
198 #pragma omp taskloop collapse(0)
199 for (i = 0; i < 16; ++i)
201 #pragma omp parallel
202 // expected-error@+1 {{argument to 'collapse' clause must be a strictly positive integer value}}
203 #pragma omp taskloop collapse(5 - 5)
204 for (i = 0; i < 16; ++i)
208 void test_private(void) {
209 int i;
210 #pragma omp parallel
211 // expected-error@+2 {{expected expression}}
212 // expected-error@+1 {{expected ')'}} expected-note@+1 {{to match this '('}}
213 #pragma omp taskloop private(
214 for (i = 0; i < 16; ++i)
216 #pragma omp parallel
217 // expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
218 // expected-error@+1 2 {{expected expression}}
219 #pragma omp taskloop private(,
220 for (i = 0; i < 16; ++i)
222 #pragma omp parallel
223 // expected-error@+1 2 {{expected expression}}
224 #pragma omp taskloop private(, )
225 for (i = 0; i < 16; ++i)
227 #pragma omp parallel
228 // expected-error@+1 {{expected expression}}
229 #pragma omp taskloop private()
230 for (i = 0; i < 16; ++i)
232 #pragma omp parallel
233 // expected-error@+1 {{expected expression}}
234 #pragma omp taskloop private(int)
235 for (i = 0; i < 16; ++i)
237 #pragma omp parallel
238 // expected-error@+1 {{expected variable name}}
239 #pragma omp taskloop private(0)
240 for (i = 0; i < 16; ++i)
243 int x, y, z;
244 #pragma omp parallel
245 #pragma omp taskloop private(x)
246 for (i = 0; i < 16; ++i)
248 #pragma omp parallel
249 #pragma omp taskloop private(x, y)
250 for (i = 0; i < 16; ++i)
252 #pragma omp parallel
253 #pragma omp taskloop private(x, y, z)
254 for (i = 0; i < 16; ++i) {
255 x = y * i + z;
259 void test_lastprivate(void) {
260 int i;
261 #pragma omp parallel
262 // expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
263 // expected-error@+1 {{expected expression}}
264 #pragma omp taskloop lastprivate(
265 for (i = 0; i < 16; ++i)
268 #pragma omp parallel
269 // expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
270 // expected-error@+1 2 {{expected expression}}
271 #pragma omp taskloop lastprivate(,
272 for (i = 0; i < 16; ++i)
274 #pragma omp parallel
275 // expected-error@+1 2 {{expected expression}}
276 #pragma omp taskloop lastprivate(, )
277 for (i = 0; i < 16; ++i)
279 #pragma omp parallel
280 // expected-error@+1 {{expected expression}}
281 #pragma omp taskloop lastprivate()
282 for (i = 0; i < 16; ++i)
284 #pragma omp parallel
285 // expected-error@+1 {{expected expression}}
286 #pragma omp taskloop lastprivate(int)
287 for (i = 0; i < 16; ++i)
289 #pragma omp parallel
290 // expected-error@+1 {{expected variable name}}
291 #pragma omp taskloop lastprivate(0)
292 for (i = 0; i < 16; ++i)
295 int x, y, z;
296 #pragma omp parallel
297 #pragma omp taskloop lastprivate(x)
298 for (i = 0; i < 16; ++i)
300 #pragma omp parallel
301 #pragma omp taskloop lastprivate(x, y)
302 for (i = 0; i < 16; ++i)
304 #pragma omp parallel
305 #pragma omp taskloop lastprivate(x, y, z)
306 for (i = 0; i < 16; ++i)
310 void test_firstprivate(void) {
311 int i;
312 #pragma omp parallel
313 // expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
314 // expected-error@+1 {{expected expression}}
315 #pragma omp taskloop firstprivate(
316 for (i = 0; i < 16; ++i)
319 #pragma omp parallel
320 // expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
321 // expected-error@+1 2 {{expected expression}}
322 #pragma omp taskloop firstprivate(,
323 for (i = 0; i < 16; ++i)
325 #pragma omp parallel
326 // expected-error@+1 2 {{expected expression}}
327 #pragma omp taskloop firstprivate(, )
328 for (i = 0; i < 16; ++i)
330 #pragma omp parallel
331 // expected-error@+1 {{expected expression}}
332 #pragma omp taskloop firstprivate()
333 for (i = 0; i < 16; ++i)
335 #pragma omp parallel
336 // expected-error@+1 {{expected expression}}
337 #pragma omp taskloop firstprivate(int)
338 for (i = 0; i < 16; ++i)
340 #pragma omp parallel
341 // expected-error@+1 {{expected variable name}}
342 #pragma omp taskloop firstprivate(0)
343 for (i = 0; i < 16; ++i)
346 int x, y, z;
347 #pragma omp parallel
348 #pragma omp taskloop lastprivate(x) firstprivate(x)
349 for (i = 0; i < 16; ++i)
351 #pragma omp parallel
352 #pragma omp taskloop lastprivate(x, y) firstprivate(x, y)
353 for (i = 0; i < 16; ++i)
355 #pragma omp parallel
356 #pragma omp taskloop lastprivate(x, y, z) firstprivate(x, y, z)
357 for (i = 0; i < 16; ++i)
361 void test_loop_messages(void) {
362 float a[100], b[100], c[100];
363 #pragma omp parallel
364 // expected-error@+2 {{variable must be of integer or pointer type}}
365 #pragma omp taskloop
366 for (float fi = 0; fi < 10.0; fi++) {
367 c[(int)fi] = a[(int)fi] + b[(int)fi];
369 #pragma omp parallel
370 // expected-error@+2 {{variable must be of integer or pointer type}}
371 #pragma omp taskloop
372 for (double fi = 0; fi < 10.0; fi++) {
373 c[(int)fi] = a[(int)fi] + b[(int)fi];
376 // expected-warning@+2 {{OpenMP loop iteration variable cannot have more than 64 bits size and will be narrowed}}
377 #pragma omp taskloop
378 for (__int128 ii = 0; ii < 10; ii++) {
379 c[ii] = a[ii] + b[ii];