blob: 84d6337be34bbc8d5029f2c53b94b69d828e318d [file] [log] [blame]
Alexey Bataeva9148882019-07-08 15:45:24 +00001// RUN: %clang_cc1 -verify -fopenmp %s -Wuninitialized
Carlo Bertolli9925f152016-06-27 14:55:37 +00002
Alexey Bataeva9148882019-07-08 15:45:24 +00003// RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00004
Carlo Bertolli9925f152016-06-27 14:55:37 +00005void foo() {
6}
7
8bool foobool(int argc) {
9 return argc;
10}
Alexey Bataev25569292019-07-22 13:51:07 +000011
12void 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)
16 ;
17}
18
Alexey Bataeve04483e2019-03-27 14:14:31 +000019extern int omp_default_mem_alloc;
Carlo Bertolli9925f152016-06-27 14:55:37 +000020
Jennifer Yu656d0222021-08-03 10:35:04 -070021struct S1; // expected-note 2 {{declared here}} expected-note 3 {{forward declaration of 'S1'}}
Carlo Bertolli9925f152016-06-27 14:55:37 +000022extern S1 a;
23class S2 {
24 mutable int a;
25
26public:
27 S2() : a(0) {}
28 S2(const S2 &s2) : a(s2.a) {}
29 static float S2s;
30 static const float S2sc;
31};
32const float S2::S2sc = 0;
33const S2 b;
34const S2 ba[5];
35class S3 {
36 int a;
37 S3 &operator=(const S3 &s3);
38
39public:
40 S3() : a(0) {}
41 S3(const S3 &s3) : a(s3.a) {}
42};
43const S3 c;
44const S3 ca[5];
45extern const int f;
46class S4 {
47 int a;
48 S4();
49 S4(const S4 &s4); // expected-note 2 {{implicitly declared private here}}
50
51public:
52 S4(int v) : a(v) {}
53};
54class S5 {
55 int a;
Alexey Bataevb358f992017-12-01 17:40:15 +000056 S5(const S5 &s5) : a(s5.a) {} // expected-note 2 {{implicitly declared private here}}
Carlo Bertolli9925f152016-06-27 14:55:37 +000057
58public:
59 S5() : a(0) {}
60 S5(int v) : a(v) {}
61};
62class S6 {
63 int a;
Alexey Bataevb358f992017-12-01 17:40:15 +000064 S6() : a(0) {} // expected-note {{implicitly declared private here}}
Carlo Bertolli9925f152016-06-27 14:55:37 +000065
66public:
67 S6(const S6 &s6) : a(s6.a) {}
68 S6(int v) : a(v) {}
69};
70
71S3 h;
72#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
73
74template <class I, class C>
75int foomain(int argc, char **argv) {
76 I e(4);
77 C g(5);
Alexey Bataeva9148882019-07-08 15:45:24 +000078 int i, k;
Carlo Bertolli9925f152016-06-27 14:55:37 +000079 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
Alexey Bataeve04483e2019-03-27 14:14:31 +0000112#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 '('}}
Carlo Bertolli9925f152016-06-27 14:55:37 +0000113 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
Jonas Hahnfeld071dca22019-12-07 13:31:46 +0100122#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}}
Carlo Bertolli9925f152016-06-27 14:55:37 +0000123 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
Jonas Hahnfeld071dca22019-12-07 13:31:46 +0100132#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}}
Carlo Bertolli9925f152016-06-27 14:55:37 +0000133 for (int k = 0; k < argc; ++k)
134 ++k;
135#pragma omp target
136#pragma omp teams
Alexey Bataeva9148882019-07-08 15:45:24 +0000137#pragma omp distribute parallel for firstprivate(k, h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
Carlo Bertolli9925f152016-06-27 14:55:37 +0000138 for (int k = 0; k < argc; ++k)
139 ++k;
140#pragma omp parallel
141 {
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;
150 }
151 }
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;
Alexey Bataevb358f992017-12-01 17:40:15 +0000164// expected-error@+3 {{lastprivate variable cannot be firstprivate}} expected-note@+3 {{defined as lastprivate}}
Carlo Bertolli9925f152016-06-27 14:55:37 +0000165#pragma omp target
166#pragma omp teams
Alexey Bataevb358f992017-12-01 17:40:15 +0000167#pragma omp distribute parallel for lastprivate(g) firstprivate(g)
Carlo Bertolli9925f152016-06-27 14:55:37 +0000168 for (i = 0; i < argc; ++i)
169 foo();
170#pragma omp parallel private(i)
171#pragma omp target
172#pragma omp teams
Alexey Bataev05be1da2019-07-18 17:49:13 +0000173#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}}
Carlo Bertolli9925f152016-06-27 14:55:37 +0000175 foo();
176#pragma omp parallel reduction(+ : i)
177#pragma omp target
178#pragma omp teams
Alexey Bataev05be1da2019-07-18 17:49:13 +0000179#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}}
Carlo Bertolli9925f152016-06-27 14:55:37 +0000181 foo();
182 return 0;
183}
184
185namespace A {
186double x;
187#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
188}
189namespace B {
190using A::x;
191}
192
193int 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);
Alexey Bataeva9148882019-07-08 15:45:24 +0000200 int i, k;
Carlo Bertolli9925f152016-06-27 14:55:37 +0000201 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
Jonas Hahnfeld071dca22019-12-07 13:31:46 +0100244#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}}
Carlo Bertolli9925f152016-06-27 14:55:37 +0000245 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
David Blaikieaee49252021-10-14 14:52:47 -0700259#pragma omp distribute parallel for firstprivate(ba) // expected-warning {{Type 'const S2[5]' is not trivially copyable and not guaranteed to be mapped correctly}}
Carlo Bertolli9925f152016-06-27 14:55:37 +0000260 for (i = 0; i < argc; ++i)
261 foo();
262#pragma omp target
263#pragma omp teams
David Blaikieaee49252021-10-14 14:52:47 -0700264#pragma omp distribute parallel for firstprivate(ca) // expected-warning {{Type 'const S3[5]' is not trivially copyable and not guaranteed to be mapped correctly}}
Carlo Bertolli9925f152016-06-27 14:55:37 +0000265 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
Jonas Hahnfeld071dca22019-12-07 13:31:46 +0100295#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}}
Carlo Bertolli9925f152016-06-27 14:55:37 +0000296 for (i = 0; i < argc; ++i)
297 foo();
298#pragma omp target
299#pragma omp teams
Jonas Hahnfeld071dca22019-12-07 13:31:46 +0100300#pragma omp distribute parallel for firstprivate(m) // expected-warning {{Type 'S3' is not trivially copyable and not guaranteed to be mapped correctly}}
Carlo Bertolli9925f152016-06-27 14:55:37 +0000301 for (i = 0; i < argc; ++i)
302 foo();
303#pragma omp target
304#pragma omp teams
Alexey Bataeva9148882019-07-08 15:45:24 +0000305#pragma omp distribute parallel for firstprivate(k, h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be firstprivate}}
Carlo Bertolli9925f152016-06-27 14:55:37 +0000306 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();
Alexey Bataevb358f992017-12-01 17:40:15 +0000329// expected-error@+3 {{lastprivate variable cannot be firstprivate}} expected-note@+3 {{defined as lastprivate}}
Carlo Bertolli9925f152016-06-27 14:55:37 +0000330#pragma omp target
331#pragma omp teams
Jonas Hahnfeld071dca22019-12-07 13:31:46 +0100332#pragma omp distribute parallel for lastprivate(g) firstprivate(g) // expected-warning {{Type 'S5' is not trivially copyable and not guaranteed to be mapped correctly}}
Carlo Bertolli9925f152016-06-27 14:55:37 +0000333 for (i = 0; i < argc; ++i)
334 foo();
Alexey Bataevb358f992017-12-01 17:40:15 +0000335// expected-error@+3 {{lastprivate variable cannot be firstprivate}} expected-note@+3 {{defined as lastprivate}}
Carlo Bertolli9925f152016-06-27 14:55:37 +0000336#pragma omp target
337#pragma omp teams
Jonas Hahnfeld071dca22019-12-07 13:31:46 +0100338#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}}
Carlo Bertolli9925f152016-06-27 14:55:37 +0000339 for (i = 0; i < argc; ++i)
340 foo();
341#pragma omp parallel
342 {
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;
351 }
352 }
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;
371
372 return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}
373}