blob: de2ad14ae5a39cd1455ece19f20e5315557d87a6 [file] [log] [blame]
Alexey Bataeva9148882019-07-08 15:45:24 +00001// RUN: %clang_cc1 -verify -fopenmp %s -Wuninitialized
2// RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized
Alexey Bataevf29276e2014-06-18 04:14:57 +00003
Alexey Bataeve04483e2019-03-27 14:14:31 +00004extern int omp_default_mem_alloc;
Alexey Bataevf29276e2014-06-18 04:14:57 +00005void foo() {
6}
7
8bool foobool(int argc) {
9 return argc;
10}
11
12struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
13extern S1 a;
14class S2 {
15 mutable int a;
16
17public:
18 S2() : a(0) {}
Alexey Bataev4a5bb772014-10-08 14:01:46 +000019 S2(const S2 &s2) : a(s2.a) {}
Alexey Bataevf29276e2014-06-18 04:14:57 +000020 static float S2s;
21 static const float S2sc;
22};
23const float S2::S2sc = 0;
24const S2 b;
25const S2 ba[5];
26class S3 {
27 int a;
28 S3 &operator=(const S3 &s3);
29
30public:
Alexey Bataev69c62a92015-04-15 04:52:20 +000031 S3() : a(0) {} // expected-note 2 {{candidate constructor not viable: requires 0 arguments, but 1 was provided}}
32 S3(S3 &s3) : a(s3.a) {} // expected-note 2 {{candidate constructor not viable: 1st argument ('const S3') would lose const qualifier}}
Alexey Bataevf29276e2014-06-18 04:14:57 +000033};
34const S3 c;
35const S3 ca[5];
36extern const int f;
Alexey Bataev4a5bb772014-10-08 14:01:46 +000037class S4 {
Alexey Bataevf29276e2014-06-18 04:14:57 +000038 int a;
39 S4();
Alexey Bataev5129d3a2015-05-21 09:47:46 +000040 S4(const S4 &s4); // expected-note 2 {{implicitly declared private here}}
Alexey Bataevf29276e2014-06-18 04:14:57 +000041
42public:
43 S4(int v) : a(v) {}
44};
Alexey Bataev4a5bb772014-10-08 14:01:46 +000045class S5 {
Alexey Bataevf29276e2014-06-18 04:14:57 +000046 int a;
Alexey Bataev4a5bb772014-10-08 14:01:46 +000047 S5(const S5 &s5) : a(s5.a) {} // expected-note 4 {{implicitly declared private here}}
Alexey Bataevf29276e2014-06-18 04:14:57 +000048
49public:
50 S5() : a(0) {}
51 S5(int v) : a(v) {}
52};
53class S6 {
54 int a;
55 S6() : a(0) {}
56
57public:
58 S6(const S6 &s6) : a(s6.a) {}
59 S6(int v) : a(v) {}
60};
61
62S3 h;
63#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
64
65template <class I, class C>
66int foomain(int argc, char **argv) {
Alexey Bataev4a5bb772014-10-08 14:01:46 +000067 I e(4);
68 C g(5);
Alexey Bataevf29276e2014-06-18 04:14:57 +000069 int i;
Alexey Bataevbd9fec12015-08-18 06:47:21 +000070 int &j = i;
Alexey Bataevf29276e2014-06-18 04:14:57 +000071#pragma omp parallel
72#pragma omp for firstprivate // expected-error {{expected '(' after 'firstprivate'}}
73 for (int k = 0; k < argc; ++k)
74 ++k;
75#pragma omp parallel
76#pragma omp for firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
77 for (int k = 0; k < argc; ++k)
78 ++k;
79#pragma omp parallel
80#pragma omp for firstprivate() // expected-error {{expected expression}}
81 for (int k = 0; k < argc; ++k)
82 ++k;
83#pragma omp parallel
84#pragma omp for firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
85 for (int k = 0; k < argc; ++k)
86 ++k;
87#pragma omp parallel
Alexey Bataevc5970622016-04-01 08:43:42 +000088#pragma omp for firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
Alexey Bataevf29276e2014-06-18 04:14:57 +000089 for (int k = 0; k < argc; ++k)
90 ++k;
91#pragma omp parallel
92#pragma omp for firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
93 for (int k = 0; k < argc; ++k)
94 ++k;
95#pragma omp parallel
Alexey Bataeve04483e2019-03-27 14:14:31 +000096#pragma omp 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 '('}}
Alexey Bataevf29276e2014-06-18 04:14:57 +000097 for (int k = 0; k < argc; ++k)
98 ++k;
99#pragma omp parallel
100#pragma omp for firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
101 for (int k = 0; k < argc; ++k)
102 ++k;
103#pragma omp parallel
104#pragma omp for firstprivate(a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}}
105 for (int k = 0; k < argc; ++k)
106 ++k;
107#pragma omp parallel
108#pragma omp for firstprivate(argv[1]) // expected-error {{expected variable name}}
109 for (int k = 0; k < argc; ++k)
110 ++k;
111#pragma omp parallel
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000112#pragma omp for firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
Alexey Bataevf29276e2014-06-18 04:14:57 +0000113 for (int k = 0; k < argc; ++k)
114 ++k;
115#pragma omp parallel
116#pragma omp for firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
117 for (int k = 0; k < argc; ++k)
118 ++k;
119#pragma omp parallel
Alexey Bataevf29276e2014-06-18 04:14:57 +0000120 {
121 int v = 0;
Alexey Bataev7ff55242014-06-19 09:13:45 +0000122 int i; // expected-note {{variable with automatic storage duration is predetermined as private; perhaps you forget to enclose 'omp for' directive into a parallel or another task region?}}
Alexey Bataevdffa93a2015-12-10 08:20:58 +0000123#pragma omp for firstprivate(i) // expected-error {{firstprivate variable must be shared}}
Alexey Bataevf29276e2014-06-18 04:14:57 +0000124 for (int k = 0; k < argc; ++k) {
125 i = k;
126 v += i;
127 }
128 }
129#pragma omp parallel shared(i)
130#pragma omp parallel private(i)
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000131#pragma omp for firstprivate(j)
Alexey Bataevf29276e2014-06-18 04:14:57 +0000132 for (int k = 0; k < argc; ++k)
133 ++k;
134#pragma omp parallel
135#pragma omp for firstprivate(i)
136 for (int k = 0; k < argc; ++k)
137 ++k;
138#pragma omp parallel
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000139#pragma omp for lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
Alexey Bataevf29276e2014-06-18 04:14:57 +0000140 for (i = 0; i < argc; ++i)
141 foo();
142#pragma omp parallel private(i) // expected-note {{defined as private}}
143#pragma omp for firstprivate(i) // expected-error {{firstprivate variable must be shared}}
144 for (i = 0; i < argc; ++i)
145 foo();
146#pragma omp parallel reduction(+ : i) // expected-note {{defined as reduction}}
Alexey Bataev7ff55242014-06-19 09:13:45 +0000147#pragma omp for firstprivate(i) // expected-error {{firstprivate variable must be shared}}
Alexey Bataeva839ddd2016-03-17 10:19:46 +0000148 for (int k = 0; k < argc; ++k)
Alexey Bataevf29276e2014-06-18 04:14:57 +0000149 foo();
150 return 0;
151}
152
Alexey Bataevf120c0d2015-05-19 07:46:42 +0000153void bar(S4 a[2]) {
154#pragma omp parallel
Alexey Bataev5129d3a2015-05-21 09:47:46 +0000155#pragma omp for firstprivate(a)
Alexey Bataevf120c0d2015-05-19 07:46:42 +0000156 for (int i = 0; i < 2; ++i)
157 foo();
158}
159
Alexey Bataev6ddfe1a2015-04-16 13:49:42 +0000160namespace A {
161double x;
162#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
163}
164namespace B {
165using A::x;
166}
167
Alexey Bataevf29276e2014-06-18 04:14:57 +0000168int main(int argc, char **argv) {
169 const int d = 5;
170 const int da[5] = {0};
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000171 S4 e(4);
172 S5 g(5);
Alexey Bataevf29276e2014-06-18 04:14:57 +0000173 S3 m;
174 S6 n(2);
Alexey Bataeva9148882019-07-08 15:45:24 +0000175 int i, k;
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000176 int &j = i;
Alexey Bataevf29276e2014-06-18 04:14:57 +0000177#pragma omp parallel
178#pragma omp for firstprivate // expected-error {{expected '(' after 'firstprivate'}}
179 for (i = 0; i < argc; ++i)
180 foo();
181#pragma omp parallel
182#pragma omp for firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
183 for (i = 0; i < argc; ++i)
184 foo();
185#pragma omp parallel
186#pragma omp for firstprivate() // expected-error {{expected expression}}
187 for (i = 0; i < argc; ++i)
188 foo();
189#pragma omp parallel
190#pragma omp for firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
191 for (i = 0; i < argc; ++i)
192 foo();
193#pragma omp parallel
Alexey Bataevc5970622016-04-01 08:43:42 +0000194#pragma omp for firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
Alexey Bataevf29276e2014-06-18 04:14:57 +0000195 for (i = 0; i < argc; ++i)
196 foo();
197#pragma omp parallel
198#pragma omp for firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
199 for (i = 0; i < argc; ++i)
200 foo();
201#pragma omp parallel
202#pragma omp for firstprivate(argc)
203 for (i = 0; i < argc; ++i)
204 foo();
205#pragma omp parallel
206#pragma omp for firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
207 for (i = 0; i < argc; ++i)
208 foo();
209#pragma omp parallel
Alexey Bataeva9148882019-07-08 15:45:24 +0000210#pragma omp for firstprivate(a, b, c, d, f, k) // expected-error {{firstprivate variable with incomplete type 'S1'}} expected-error {{no matching constructor for initialization of 'S3'}}
Alexey Bataevf29276e2014-06-18 04:14:57 +0000211 for (i = 0; i < argc; ++i)
212 foo();
213#pragma omp parallel
214#pragma omp for firstprivate(argv[1]) // expected-error {{expected variable name}}
215 for (i = 0; i < argc; ++i)
216 foo();
217#pragma omp parallel
218#pragma omp for firstprivate(2 * 2) // expected-error {{expected variable name}}
219 for (i = 0; i < argc; ++i)
220 foo();
221#pragma omp parallel
222#pragma omp for firstprivate(ba) // OK
223 for (i = 0; i < argc; ++i)
224 foo();
225#pragma omp parallel
Alexey Bataev69c62a92015-04-15 04:52:20 +0000226#pragma omp for firstprivate(ca) // expected-error {{no matching constructor for initialization of 'S3'}}
Alexey Bataevf29276e2014-06-18 04:14:57 +0000227 for (i = 0; i < argc; ++i)
228 foo();
229#pragma omp parallel
230#pragma omp for firstprivate(da) // OK
231 for (i = 0; i < argc; ++i)
232 foo();
233 int xa;
234#pragma omp parallel
235#pragma omp for firstprivate(xa) // OK
236 for (i = 0; i < argc; ++i)
237 foo();
238#pragma omp parallel
239#pragma omp for firstprivate(S2::S2s) // OK
240 for (i = 0; i < argc; ++i)
241 foo();
242#pragma omp parallel
243#pragma omp for firstprivate(S2::S2sc) // OK
244 for (i = 0; i < argc; ++i)
245 foo();
246#pragma omp parallel
247#pragma omp for safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp for'}}
248 for (i = 0; i < argc; ++i)
249 foo();
250#pragma omp parallel
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000251#pragma omp for firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
Alexey Bataevf29276e2014-06-18 04:14:57 +0000252 for (i = 0; i < argc; ++i)
253 foo();
254#pragma omp parallel
255#pragma omp for firstprivate(m) // OK
256 for (i = 0; i < argc; ++i)
257 foo();
258#pragma omp parallel
259#pragma omp for firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
260 for (i = 0; i < argc; ++i)
261 foo();
262#pragma omp parallel
263#pragma omp for private(xa), firstprivate(xa) // expected-error {{private variable cannot be firstprivate}} expected-note {{defined as private}}
264 for (i = 0; i < argc; ++i)
265 foo();
266#pragma omp parallel
267#pragma omp for firstprivate(i) // expected-note {{defined as firstprivate}}
Alexey Bataev4acb8592014-07-07 13:01:15 +0000268 for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp for' directive may not be firstprivate, predetermined as private}}
Alexey Bataevf29276e2014-06-18 04:14:57 +0000269 foo();
270#pragma omp parallel shared(xa)
271#pragma omp for firstprivate(xa) // OK: may be firstprivate
272 for (i = 0; i < argc; ++i)
273 foo();
274#pragma omp parallel
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000275#pragma omp for firstprivate(j)
Alexey Bataevf29276e2014-06-18 04:14:57 +0000276 for (i = 0; i < argc; ++i)
277 foo();
278#pragma omp parallel
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000279#pragma omp for lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
Alexey Bataevf29276e2014-06-18 04:14:57 +0000280 for (i = 0; i < argc; ++i)
281 foo();
282#pragma omp parallel
283#pragma omp for lastprivate(n) firstprivate(n) // OK
284 for (i = 0; i < argc; ++i)
285 foo();
286#pragma omp parallel
287 {
288 int v = 0;
Alexey Bataev7ff55242014-06-19 09:13:45 +0000289 int i; // expected-note {{variable with automatic storage duration is predetermined as private; perhaps you forget to enclose 'omp for' directive into a parallel or another task region?}}
Alexey Bataevdffa93a2015-12-10 08:20:58 +0000290#pragma omp for firstprivate(i) // expected-error {{firstprivate variable must be shared}}
Alexey Bataevf29276e2014-06-18 04:14:57 +0000291 for (int k = 0; k < argc; ++k) {
292 i = k;
293 v += i;
294 }
295 }
296#pragma omp parallel private(i) // expected-note {{defined as private}}
297#pragma omp for firstprivate(i) // expected-error {{firstprivate variable must be shared}}
298 for (i = 0; i < argc; ++i)
299 foo();
300#pragma omp parallel reduction(+ : i) // expected-note {{defined as reduction}}
Alexey Bataev7ff55242014-06-19 09:13:45 +0000301#pragma omp for firstprivate(i) // expected-error {{firstprivate variable must be shared}}
Alexey Bataevf29276e2014-06-18 04:14:57 +0000302 for (i = 0; i < argc; ++i)
303 foo();
Alexey Bataev6ddfe1a2015-04-16 13:49:42 +0000304#pragma omp parallel
305#pragma omp for firstprivate(B::x) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
306 for (i = 0; i < argc; ++i)
307 foo();
Kelvin Li4eea8c62015-09-15 18:56:58 +0000308 static int si;
309#pragma omp for firstprivate(si) // OK
310 for (i = 0; i < argc; ++i)
311 si = i + 1;
Alexey Bataevf29276e2014-06-18 04:14:57 +0000312
313 return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}
314}
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000315