Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / target_parallel_for_misc_messages.c
blobd225a1e93d53eedfee51c865e57c0280c6588157
1 // RUN: %clang_cc1 -fsyntax-only -fopenmp -verify %s -Wuninitialized
3 // RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -verify %s -Wuninitialized
5 // expected-error@+1 {{unexpected OpenMP directive '#pragma omp target parallel for'}}
6 #pragma omp target parallel for
8 // expected-error@+1 {{unexpected OpenMP directive '#pragma omp target parallel for'}}
9 #pragma omp target parallel for foo
11 void test_no_clause(void) {
12 int i;
13 #pragma omp target parallel for
14 for (i = 0; i < 16; ++i)
17 // expected-error@+2 {{statement after '#pragma omp target parallel for' must be a for loop}}
18 #pragma omp target parallel for
19 ++i;
22 void test_branch_protected_scope(void) {
23 int i = 0;
24 L1:
25 ++i;
27 int x[24];
29 #pragma omp target parallel for
30 for (i = 0; i < 16; ++i) {
31 if (i == 5)
32 goto L1; // expected-error {{use of undeclared label 'L1'}}
33 else if (i == 6)
34 return; // expected-error {{cannot return from OpenMP region}}
35 else if (i == 7)
36 goto L2;
37 else if (i == 8) {
38 L2:
39 x[i]++;
43 if (x[0] == 0)
44 goto L2; // expected-error {{use of undeclared label 'L2'}}
45 else if (x[1] == 1)
46 goto L1;
49 void test_invalid_clause(void) {
50 int i;
51 // expected-warning@+1 {{extra tokens at the end of '#pragma omp target parallel for' are ignored}}
52 #pragma omp target parallel for foo bar
53 for (i = 0; i < 16; ++i)
57 void test_non_identifiers(void) {
58 int i, x;
60 // expected-warning@+1 {{extra tokens at the end of '#pragma omp target parallel for' are ignored}}
61 #pragma omp target parallel for;
62 for (i = 0; i < 16; ++i)
65 // expected-warning@+1 {{extra tokens at the end of '#pragma omp target parallel for' are ignored}}
66 #pragma omp target parallel for private(x);
67 for (i = 0; i < 16; ++i)
70 // expected-warning@+1 {{extra tokens at the end of '#pragma omp target parallel for' are ignored}}
71 #pragma omp target parallel for, private(x);
72 for (i = 0; i < 16; ++i)
76 extern int foo(void);
78 void test_collapse(void) {
79 int i;
80 // expected-error@+1 {{expected '('}}
81 #pragma omp target parallel for collapse
82 for (i = 0; i < 16; ++i)
84 // expected-error@+1 {{expected expression}} expected-error@+1 {{expected ')'}} expected-note@+1 {{to match this '('}}
85 #pragma omp target parallel for collapse(
86 for (i = 0; i < 16; ++i)
88 // expected-error@+1 {{expected expression}}
89 #pragma omp target parallel for collapse()
90 for (i = 0; i < 16; ++i)
92 // expected-error@+1 {{expected expression}} expected-error@+1 {{expected ')'}} expected-note@+1 {{to match this '('}}
93 #pragma omp target parallel for collapse(,
94 for (i = 0; i < 16; ++i)
96 // expected-error@+1 {{expected expression}} expected-error@+1 {{expected ')'}} expected-note@+1 {{to match this '('}}
97 #pragma omp target parallel for collapse(, )
98 for (i = 0; i < 16; ++i)
100 // expected-warning@+2 {{extra tokens at the end of '#pragma omp target parallel for' are ignored}}
101 // expected-error@+1 {{expected '('}}
102 #pragma omp target parallel for collapse 4)
103 for (i = 0; i < 16; ++i)
105 // expected-error@+2 {{expected ')'}}
106 // expected-note@+1 {{to match this '('}} expected-note@+1 {{as specified in 'collapse' clause}}
107 #pragma omp target parallel for collapse(4
108 for (i = 0; i < 16; ++i)
109 ; // expected-error {{expected 4 for loops after '#pragma omp target parallel for', but found only 1}}
110 // expected-error@+2 {{expected ')'}}
111 // expected-note@+1 {{to match this '('}} expected-note@+1 {{as specified in 'collapse' clause}}
112 #pragma omp target parallel for collapse(4,
113 for (i = 0; i < 16; ++i)
114 ; // expected-error {{expected 4 for loops after '#pragma omp target parallel for', but found only 1}}
115 // expected-error@+2 {{expected ')'}}
116 // expected-note@+1 {{to match this '('}} expected-note@+1 {{as specified in 'collapse' clause}}
117 #pragma omp target parallel for collapse(4, )
118 for (i = 0; i < 16; ++i)
119 ; // expected-error {{expected 4 for loops after '#pragma omp target parallel for', but found only 1}}
120 // expected-note@+1 {{as specified in 'collapse' clause}}
121 #pragma omp target parallel for collapse(4)
122 for (i = 0; i < 16; ++i)
123 ; // expected-error {{expected 4 for loops after '#pragma omp target parallel for', but found only 1}}
124 // expected-error@+2 {{expected ')'}}
125 // expected-note@+1 {{to match this '('}} expected-note@+1 {{as specified in 'collapse' clause}}
126 #pragma omp target parallel for collapse(4 4)
127 for (i = 0; i < 16; ++i)
128 ; // expected-error {{expected 4 for loops after '#pragma omp target parallel for', but found only 1}}
129 // expected-error@+2 {{expected ')'}}
130 // expected-note@+1 {{to match this '('}} expected-note@+1 {{as specified in 'collapse' clause}}
131 #pragma omp target parallel for collapse(4, , 4)
132 for (i = 0; i < 16; ++i)
133 ; // expected-error {{expected 4 for loops after '#pragma omp target parallel for', but found only 1}}
134 #pragma omp target parallel for collapse(4)
135 for (int i1 = 0; i1 < 16; ++i1)
136 for (int i2 = 0; i2 < 16; ++i2)
137 for (int i3 = 0; i3 < 16; ++i3)
138 for (int i4 = 0; i4 < 16; ++i4)
139 foo();
140 // expected-error@+2 {{expected ')'}}
141 // expected-note@+1 {{to match this '('}} expected-note@+1 {{as specified in 'collapse' clause}}
142 #pragma omp target parallel for collapse(4, 8)
143 for (i = 0; i < 16; ++i)
144 ; // expected-error {{expected 4 for loops after '#pragma omp target parallel for', but found only 1}}
145 // expected-error@+1 {{integer constant expression}}
146 #pragma omp target parallel for collapse(2.5)
147 for (i = 0; i < 16; ++i)
149 // expected-error@+1 {{integer constant expression}}
150 #pragma omp target parallel for collapse(foo())
151 for (i = 0; i < 16; ++i)
153 // expected-error@+1 {{argument to 'collapse' clause must be a strictly positive integer value}}
154 #pragma omp target parallel for collapse(-5)
155 for (i = 0; i < 16; ++i)
157 // expected-error@+1 {{argument to 'collapse' clause must be a strictly positive integer value}}
158 #pragma omp target parallel for collapse(0)
159 for (i = 0; i < 16; ++i)
161 // expected-error@+1 {{argument to 'collapse' clause must be a strictly positive integer value}}
162 #pragma omp target parallel for collapse(5 - 5)
163 for (i = 0; i < 16; ++i)
165 // expected-note@+1 2 {{defined as firstprivate}}
166 #pragma omp target parallel for collapse(2) firstprivate(i)
167 for (i = 0; i < 16; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp target parallel for' directive may not be firstprivate, predetermined as private}}
168 // 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?}}
169 for (int j = 0; j < 16; ++j)
170 // expected-error@+2 2 {{reduction variable must be shared}}
171 // expected-error@+1 {{region cannot be closely nested inside 'target parallel for' region; perhaps you forget to enclose 'omp for' directive into a parallel region?}}
172 #pragma omp for reduction(+ : i, j)
173 for (int k = 0; k < 16; ++k)
174 i += j;
177 void test_private(void) {
178 int i;
179 // expected-error@+2 {{expected expression}}
180 // expected-error@+1 {{expected ')'}} expected-note@+1 {{to match this '('}}
181 #pragma omp target parallel for private(
182 for (i = 0; i < 16; ++i)
184 // expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
185 // expected-error@+1 2 {{expected expression}}
186 #pragma omp target parallel for private(,
187 for (i = 0; i < 16; ++i)
189 // expected-error@+1 2 {{expected expression}}
190 #pragma omp target parallel for private(, )
191 for (i = 0; i < 16; ++i)
193 // expected-error@+1 {{expected expression}}
194 #pragma omp target parallel for private()
195 for (i = 0; i < 16; ++i)
197 // expected-error@+1 {{expected expression}}
198 #pragma omp target parallel for private(int)
199 for (i = 0; i < 16; ++i)
201 // expected-error@+1 {{expected variable name}}
202 #pragma omp target parallel for private(0)
203 for (i = 0; i < 16; ++i)
206 int x, y, z;
207 #pragma omp target parallel for private(x)
208 for (i = 0; i < 16; ++i)
210 #pragma omp target parallel for private(x, y)
211 for (i = 0; i < 16; ++i)
213 #pragma omp target parallel for private(x, y, z)
214 for (i = 0; i < 16; ++i) {
215 x = y * i + z;
219 void test_lastprivate(void) {
220 int i;
221 // expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
222 // expected-error@+1 {{expected expression}}
223 #pragma omp target parallel for lastprivate(
224 for (i = 0; i < 16; ++i)
227 // expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
228 // expected-error@+1 2 {{expected expression}}
229 #pragma omp target parallel for lastprivate(,
230 for (i = 0; i < 16; ++i)
232 // expected-error@+1 2 {{expected expression}}
233 #pragma omp target parallel for lastprivate(, )
234 for (i = 0; i < 16; ++i)
236 // expected-error@+1 {{expected expression}}
237 #pragma omp target parallel for lastprivate()
238 for (i = 0; i < 16; ++i)
240 // expected-error@+1 {{expected expression}}
241 #pragma omp target parallel for lastprivate(int)
242 for (i = 0; i < 16; ++i)
244 // expected-error@+1 {{expected variable name}}
245 #pragma omp target parallel for lastprivate(0)
246 for (i = 0; i < 16; ++i)
249 int x, y, z;
250 #pragma omp target parallel for lastprivate(x)
251 for (i = 0; i < 16; ++i)
253 #pragma omp target parallel for lastprivate(x, y)
254 for (i = 0; i < 16; ++i)
256 #pragma omp target parallel for lastprivate(x, y, z)
257 for (i = 0; i < 16; ++i)
261 void test_firstprivate(void) {
262 int i;
263 // expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
264 // expected-error@+1 {{expected expression}}
265 #pragma omp target parallel for firstprivate(
266 for (i = 0; i < 16; ++i)
269 // expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
270 // expected-error@+1 2 {{expected expression}}
271 #pragma omp target parallel for firstprivate(,
272 for (i = 0; i < 16; ++i)
274 // expected-error@+1 2 {{expected expression}}
275 #pragma omp target parallel for firstprivate(, )
276 for (i = 0; i < 16; ++i)
278 // expected-error@+1 {{expected expression}}
279 #pragma omp target parallel for firstprivate()
280 for (i = 0; i < 16; ++i)
282 // expected-error@+1 {{expected expression}}
283 #pragma omp target parallel for firstprivate(int)
284 for (i = 0; i < 16; ++i)
286 // expected-error@+1 {{expected variable name}}
287 #pragma omp target parallel for firstprivate(0)
288 for (i = 0; i < 16; ++i)
291 int x, y, z;
292 #pragma omp target parallel for lastprivate(x) firstprivate(x)
293 for (i = 0; i < 16; ++i)
295 #pragma omp target parallel for lastprivate(x, y) firstprivate(x, y)
296 for (i = 0; i < 16; ++i)
298 #pragma omp target parallel for lastprivate(x, y, z) firstprivate(x, y, z)
299 for (i = 0; i < 16; ++i)
303 void test_loop_messages(void) {
304 float a[100], b[100], c[100];
305 // expected-error@+2 {{variable must be of integer or pointer type}}
306 #pragma omp target parallel for
307 for (float fi = 0; fi < 10.0; fi++) {
308 c[(int)fi] = a[(int)fi] + b[(int)fi];
310 // expected-error@+2 {{variable must be of integer or pointer type}}
311 #pragma omp target parallel for
312 for (double fi = 0; fi < 10.0; fi++) {
313 c[(int)fi] = a[(int)fi] + b[(int)fi];