Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / distribute_parallel_for_firstprivate_messages.cpp
blob84d6337be34bbc8d5029f2c53b94b69d828e318d
1 // RUN: %clang_cc1 -verify -fopenmp %s -Wuninitialized
3 // RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized
5 void foo() {
8 bool foobool(int argc) {
9 return argc;
12 void xxx(int argc) {
13 int fp; // expected-note {{initialize the variable 'fp' to silence this warning}}
14 #pragma omp distribute parallel for firstprivate(fp) // expected-warning {{variable 'fp' is uninitialized when used here}}
15 for (int i = 0; i < 10; ++i)
19 extern int omp_default_mem_alloc;
21 struct S1; // expected-note 2 {{declared here}} expected-note 3 {{forward declaration of 'S1'}}
22 extern S1 a;
23 class S2 {
24 mutable int a;
26 public:
27 S2() : a(0) {}
28 S2(const S2 &s2) : a(s2.a) {}
29 static float S2s;
30 static const float S2sc;
32 const float S2::S2sc = 0;
33 const S2 b;
34 const S2 ba[5];
35 class S3 {
36 int a;
37 S3 &operator=(const S3 &s3);
39 public:
40 S3() : a(0) {}
41 S3(const S3 &s3) : a(s3.a) {}
43 const S3 c;
44 const S3 ca[5];
45 extern const int f;
46 class S4 {
47 int a;
48 S4();
49 S4(const S4 &s4); // expected-note 2 {{implicitly declared private here}}
51 public:
52 S4(int v) : a(v) {}
54 class S5 {
55 int a;
56 S5(const S5 &s5) : a(s5.a) {} // expected-note 2 {{implicitly declared private here}}
58 public:
59 S5() : a(0) {}
60 S5(int v) : a(v) {}
62 class S6 {
63 int a;
64 S6() : a(0) {} // expected-note {{implicitly declared private here}}
66 public:
67 S6(const S6 &s6) : a(s6.a) {}
68 S6(int v) : a(v) {}
71 S3 h;
72 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
74 template <class I, class C>
75 int foomain(int argc, char **argv) {
76 I e(4);
77 C g(5);
78 int i, k;
79 int &j = i;
80 #pragma omp target
81 #pragma omp teams
82 #pragma omp distribute parallel for firstprivate // expected-error {{expected '(' after 'firstprivate'}}
83 for (int k = 0; k < argc; ++k)
84 ++k;
85 #pragma omp target
86 #pragma omp teams
87 #pragma omp distribute parallel for firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
88 for (int k = 0; k < argc; ++k)
89 ++k;
90 #pragma omp target
91 #pragma omp teams
92 #pragma omp distribute parallel for firstprivate() // expected-error {{expected expression}}
93 for (int k = 0; k < argc; ++k)
94 ++k;
95 #pragma omp target
96 #pragma omp teams
97 #pragma omp distribute parallel for firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
98 for (int k = 0; k < argc; ++k)
99 ++k;
100 #pragma omp target
101 #pragma omp teams
102 #pragma omp distribute parallel for firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
103 for (int k = 0; k < argc; ++k)
104 ++k;
105 #pragma omp target
106 #pragma omp teams
107 #pragma omp distribute parallel for firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
108 for (int k = 0; k < argc; ++k)
109 ++k;
110 #pragma omp target
111 #pragma omp teams
112 #pragma omp distribute parallel for firstprivate(argc) allocate , allocate(, allocate(omp_default , allocate(omp_default_mem_alloc, allocate(omp_default_mem_alloc:, allocate(omp_default_mem_alloc: argc, allocate(omp_default_mem_alloc: argv), allocate(argv) // expected-error {{expected '(' after 'allocate'}} expected-error 2 {{expected expression}} expected-error 2 {{expected ')'}} expected-error {{use of undeclared identifier 'omp_default'}} expected-note 2 {{to match this '('}}
113 for (int k = 0; k < argc; ++k)
114 ++k;
115 #pragma omp target
116 #pragma omp teams
117 #pragma omp distribute parallel for firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
118 for (int k = 0; k < argc; ++k)
119 ++k;
120 #pragma omp target
121 #pragma omp teams
122 #pragma omp distribute parallel for firstprivate(a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}} expected-warning {{Type 'const S2' is not trivially copyable and not guaranteed to be mapped correctly}}
123 for (int k = 0; k < argc; ++k)
124 ++k;
125 #pragma omp target
126 #pragma omp teams
127 #pragma omp distribute parallel for firstprivate(argv[1]) // expected-error {{expected variable name}}
128 for (int k = 0; k < argc; ++k)
129 ++k;
130 #pragma omp target
131 #pragma omp teams
132 #pragma omp distribute parallel for firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}} expected-warning {{Type 'S4' is not trivially copyable and not guaranteed to be mapped correctly}} expected-warning {{Type 'S5' is not trivially copyable and not guaranteed to be mapped correctly}}
133 for (int k = 0; k < argc; ++k)
134 ++k;
135 #pragma omp target
136 #pragma omp teams
137 #pragma omp distribute parallel for firstprivate(k, h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
138 for (int k = 0; k < argc; ++k)
139 ++k;
140 #pragma omp parallel
142 int v = 0;
143 int i;
144 #pragma omp target
145 #pragma omp teams
146 #pragma omp distribute parallel for firstprivate(i)
147 for (int k = 0; k < argc; ++k) {
148 i = k;
149 v += i;
152 #pragma omp parallel shared(i)
153 #pragma omp parallel private(i)
154 #pragma omp target
155 #pragma omp teams
156 #pragma omp distribute parallel for firstprivate(j)
157 for (int k = 0; k < argc; ++k)
158 ++k;
159 #pragma omp target
160 #pragma omp teams
161 #pragma omp distribute parallel for firstprivate(i)
162 for (int k = 0; k < argc; ++k)
163 ++k;
164 // expected-error@+3 {{lastprivate variable cannot be firstprivate}} expected-note@+3 {{defined as lastprivate}}
165 #pragma omp target
166 #pragma omp teams
167 #pragma omp distribute parallel for lastprivate(g) firstprivate(g)
168 for (i = 0; i < argc; ++i)
169 foo();
170 #pragma omp parallel private(i)
171 #pragma omp target
172 #pragma omp teams
173 #pragma omp distribute parallel for firstprivate(i) // expected-note 2 {{defined as firstprivate}}
174 for (i = 0; i < argc; ++i) // expected-error 2 {{loop iteration variable in the associated loop of 'omp distribute parallel for' directive may not be firstprivate, predetermined as private}}
175 foo();
176 #pragma omp parallel reduction(+ : i)
177 #pragma omp target
178 #pragma omp teams
179 #pragma omp distribute parallel for firstprivate(i) // expected-note 2 {{defined as firstprivate}}
180 for (i = 0; i < argc; ++i) // expected-error 2 {{loop iteration variable in the associated loop of 'omp distribute parallel for' directive may not be firstprivate, predetermined as private}}
181 foo();
182 return 0;
185 namespace A {
186 double x;
187 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
189 namespace B {
190 using A::x;
193 int main(int argc, char **argv) {
194 const int d = 5;
195 const int da[5] = {0};
196 S4 e(4);
197 S5 g(5);
198 S3 m;
199 S6 n(2);
200 int i, k;
201 int &j = i;
202 #pragma omp target
203 #pragma omp teams
204 #pragma omp distribute parallel for firstprivate // expected-error {{expected '(' after 'firstprivate'}}
205 for (i = 0; i < argc; ++i)
206 foo();
207 #pragma omp target
208 #pragma omp teams
209 #pragma omp distribute parallel for firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
210 for (i = 0; i < argc; ++i)
211 foo();
212 #pragma omp target
213 #pragma omp teams
214 #pragma omp distribute parallel for firstprivate() // expected-error {{expected expression}}
215 for (i = 0; i < argc; ++i)
216 foo();
217 #pragma omp target
218 #pragma omp teams
219 #pragma omp distribute parallel for firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
220 for (i = 0; i < argc; ++i)
221 foo();
222 #pragma omp target
223 #pragma omp teams
224 #pragma omp distribute parallel for firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
225 for (i = 0; i < argc; ++i)
226 foo();
227 #pragma omp target
228 #pragma omp teams
229 #pragma omp distribute parallel for firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
230 for (i = 0; i < argc; ++i)
231 foo();
232 #pragma omp target
233 #pragma omp teams
234 #pragma omp distribute parallel for firstprivate(argc)
235 for (i = 0; i < argc; ++i)
236 foo();
237 #pragma omp target
238 #pragma omp teams
239 #pragma omp distribute parallel for firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
240 for (i = 0; i < argc; ++i)
241 foo();
242 #pragma omp target
243 #pragma omp teams
244 #pragma omp distribute parallel for firstprivate(a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}} expected-error {{incomplete type 'S1' where a complete type is required}} expected-warning {{Type 'const S2' is not trivially copyable and not guaranteed to be mapped correctly}} expected-warning {{Type 'const S3' is not trivially copyable and not guaranteed to be mapped correctly}}
245 for (i = 0; i < argc; ++i)
246 foo();
247 #pragma omp target
248 #pragma omp teams
249 #pragma omp distribute parallel for firstprivate(argv[1]) // expected-error {{expected variable name}}
250 for (i = 0; i < argc; ++i)
251 foo();
252 #pragma omp target
253 #pragma omp teams
254 #pragma omp distribute parallel for firstprivate(2 * 2) // expected-error {{expected variable name}}
255 for (i = 0; i < argc; ++i)
256 foo();
257 #pragma omp target
258 #pragma omp teams
259 #pragma omp distribute parallel for firstprivate(ba) // expected-warning {{Type 'const S2[5]' is not trivially copyable and not guaranteed to be mapped correctly}}
260 for (i = 0; i < argc; ++i)
261 foo();
262 #pragma omp target
263 #pragma omp teams
264 #pragma omp distribute parallel for firstprivate(ca) // expected-warning {{Type 'const S3[5]' is not trivially copyable and not guaranteed to be mapped correctly}}
265 for (i = 0; i < argc; ++i)
266 foo();
267 #pragma omp target
268 #pragma omp teams
269 #pragma omp distribute parallel for firstprivate(da) // OK
270 for (i = 0; i < argc; ++i)
271 foo();
272 int xa;
273 #pragma omp target
274 #pragma omp teams
275 #pragma omp distribute parallel for firstprivate(xa) // OK
276 for (i = 0; i < argc; ++i)
277 foo();
278 #pragma omp target
279 #pragma omp teams
280 #pragma omp distribute parallel for firstprivate(S2::S2s) // OK
281 for (i = 0; i < argc; ++i)
282 foo();
283 #pragma omp target
284 #pragma omp teams
285 #pragma omp distribute parallel for firstprivate(S2::S2sc) // OK
286 for (i = 0; i < argc; ++i)
287 foo();
288 #pragma omp target
289 #pragma omp teams
290 #pragma omp distribute parallel for safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp distribute parallel for'}}
291 for (i = 0; i < argc; ++i)
292 foo();
293 #pragma omp target
294 #pragma omp teams
295 #pragma omp distribute parallel for firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}} expected-warning {{Type 'S4' is not trivially copyable and not guaranteed to be mapped correctly}} expected-warning {{Type 'S5' is not trivially copyable and not guaranteed to be mapped correctly}}
296 for (i = 0; i < argc; ++i)
297 foo();
298 #pragma omp target
299 #pragma omp teams
300 #pragma omp distribute parallel for firstprivate(m) // expected-warning {{Type 'S3' is not trivially copyable and not guaranteed to be mapped correctly}}
301 for (i = 0; i < argc; ++i)
302 foo();
303 #pragma omp target
304 #pragma omp teams
305 #pragma omp distribute parallel for firstprivate(k, h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be firstprivate}}
306 for (i = 0; i < argc; ++i)
307 foo();
308 #pragma omp target
309 #pragma omp teams
310 #pragma omp distribute parallel for private(xa), firstprivate(xa) // expected-error {{private variable cannot be firstprivate}} expected-note {{defined as private}}
311 for (i = 0; i < argc; ++i)
312 foo();
313 #pragma omp target
314 #pragma omp teams
315 #pragma omp distribute parallel for firstprivate(i) // expected-note {{defined as firstprivate}}
316 for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp distribute parallel for' directive may not be firstprivate, predetermined as private}}
317 foo();
318 #pragma omp parallel shared(xa)
319 #pragma omp target
320 #pragma omp teams
321 #pragma omp distribute parallel for firstprivate(xa) // OK: may be firstprivate
322 for (i = 0; i < argc; ++i)
323 foo();
324 #pragma omp target
325 #pragma omp teams
326 #pragma omp distribute parallel for firstprivate(j)
327 for (i = 0; i < argc; ++i)
328 foo();
329 // expected-error@+3 {{lastprivate variable cannot be firstprivate}} expected-note@+3 {{defined as lastprivate}}
330 #pragma omp target
331 #pragma omp teams
332 #pragma omp distribute parallel for lastprivate(g) firstprivate(g) // expected-warning {{Type 'S5' is not trivially copyable and not guaranteed to be mapped correctly}}
333 for (i = 0; i < argc; ++i)
334 foo();
335 // expected-error@+3 {{lastprivate variable cannot be firstprivate}} expected-note@+3 {{defined as lastprivate}}
336 #pragma omp target
337 #pragma omp teams
338 #pragma omp distribute parallel for lastprivate(n) firstprivate(n) // expected-error {{calling a private constructor of class 'S6'}} expected-warning {{Type 'S6' is not trivially copyable and not guaranteed to be mapped correctly}}
339 for (i = 0; i < argc; ++i)
340 foo();
341 #pragma omp parallel
343 int v = 0;
344 int i;
345 #pragma omp target
346 #pragma omp teams
347 #pragma omp distribute parallel for firstprivate(i)
348 for (int k = 0; k < argc; ++k) {
349 i = k;
350 v += i;
353 #pragma omp parallel private(i)
354 #pragma omp target
355 #pragma omp teams
356 #pragma omp distribute parallel for firstprivate(i) // expected-note {{defined as firstprivate}}
357 for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp distribute parallel for' directive may not be firstprivate, predetermined as private}}
358 foo();
359 #pragma omp parallel reduction(+ : i)
360 #pragma omp target
361 #pragma omp teams
362 #pragma omp distribute parallel for firstprivate(i) // expected-note {{defined as firstprivate}}
363 for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp distribute parallel for' directive may not be firstprivate, predetermined as private}}
364 foo();
365 static int si;
366 #pragma omp target
367 #pragma omp teams
368 #pragma omp distribute parallel for firstprivate(si) // OK
369 for (i = 0; i < argc; ++i)
370 si = i + 1;
372 return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}