blob: f7e0d1acf0e91dd0cdd9a669e2028e29bf8f433c [file] [log] [blame]
Alexey Bataevdb390212015-05-20 04:24:19 +00001// RUN: %clang_cc1 -verify -fopenmp %s
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00002
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00003// RUN: %clang_cc1 -verify -fopenmp-simd %s
4
Alexey Bataeve04483e2019-03-27 14:14:31 +00005extern int omp_default_mem_alloc;
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006void foo() {
7}
8
9bool foobool(int argc) {
10 return argc;
11}
12
13struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
14extern S1 a;
15class S2 {
16 mutable int a;
17
18public:
19 S2() : a(0) {}
20 S2(S2 &s2) : a(s2.a) {}
Alexey Bataev38e89532015-04-16 04:54:05 +000021 const S2 &operator=(const S2 &) const;
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000022 static float S2s; // expected-note {{static data member is predetermined as shared}}
Joel E. Dennye6234d1422019-01-04 22:11:31 +000023 static const float S2sc; // expected-note {{'S2sc' declared here}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000024};
Alexey Bataev4d4624c2017-07-20 16:47:47 +000025const float S2::S2sc = 0;
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000026const S2 b;
27const S2 ba[5];
Alexey Bataev38e89532015-04-16 04:54:05 +000028class S3 {
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000029 int a;
Alexey Bataev38e89532015-04-16 04:54:05 +000030 S3 &operator=(const S3 &s3); // expected-note 2 {{implicitly declared private here}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000031
32public:
33 S3() : a(0) {}
34 S3(S3 &s3) : a(s3.a) {}
35};
Joel E. Dennye6234d1422019-01-04 22:11:31 +000036const S3 c; // expected-note {{'c' defined here}}
37const S3 ca[5]; // expected-note {{'ca' defined here}}
38extern const int f; // expected-note {{'f' declared here}}
Alexey Bataev38e89532015-04-16 04:54:05 +000039class S4 {
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000040 int a;
Alexey Bataev38e89532015-04-16 04:54:05 +000041 S4(); // expected-note 3 {{implicitly declared private here}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000042 S4(const S4 &s4);
43
44public:
45 S4(int v) : a(v) {}
46};
Alexey Bataev38e89532015-04-16 04:54:05 +000047class S5 {
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000048 int a;
Alexey Bataev38e89532015-04-16 04:54:05 +000049 S5() : a(0) {} // expected-note {{implicitly declared private here}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000050
51public:
52 S5(const S5 &s5) : a(s5.a) {}
53 S5(int v) : a(v) {}
54};
55class S6 {
56 int a;
57 S6() : a(0) {}
58
59public:
60 S6(const S6 &s6) : a(s6.a) {}
61 S6(int v) : a(v) {}
62};
63
64S3 h;
65#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
66
67template <class I, class C>
68int foomain(int argc, char **argv) {
Alexey Bataev38e89532015-04-16 04:54:05 +000069 I e(4);
70 I g(5);
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000071 int i;
Alexey Bataevbd9fec12015-08-18 06:47:21 +000072 int &j = i;
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000073#pragma omp parallel
74#pragma omp sections lastprivate // expected-error {{expected '(' after 'lastprivate'}}
75 {
76 foo();
77 }
78#pragma omp parallel
79#pragma omp sections lastprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
80 {
81 foo();
82 }
83#pragma omp parallel
84#pragma omp sections lastprivate() // expected-error {{expected expression}}
85 {
86 foo();
87 }
88#pragma omp parallel
89#pragma omp sections lastprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
90 {
91 foo();
92 }
93#pragma omp parallel
Alexey Bataevc5970622016-04-01 08:43:42 +000094#pragma omp sections lastprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000095 {
96 foo();
97 }
98#pragma omp parallel
99#pragma omp sections lastprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
100 {
101 foo();
102 }
103#pragma omp parallel
104#pragma omp sections lastprivate(argc)
105 {
106 foo();
107 }
108#pragma omp parallel
109#pragma omp sections lastprivate(S1) // expected-error {{'S1' does not refer to a value}}
110 {
111 foo();
112 }
113#pragma omp parallel
114#pragma omp sections lastprivate(a, b) // expected-error {{lastprivate variable with incomplete type 'S1'}}
115 {
116 foo();
117 }
118#pragma omp parallel
119#pragma omp sections lastprivate(argv[1]) // expected-error {{expected variable name}}
120 {
121 foo();
122 }
123#pragma omp parallel
Alexey Bataev38e89532015-04-16 04:54:05 +0000124#pragma omp sections lastprivate(e, g) // expected-error 2 {{calling a private constructor of class 'S4'}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000125 {
126 foo();
127 }
128#pragma omp parallel
129#pragma omp sections lastprivate(h) // expected-error {{threadprivate or thread local variable cannot be lastprivate}}
130 {
131 foo();
132 }
133#pragma omp parallel
134#pragma omp sections linear(i) // expected-error {{unexpected OpenMP clause 'linear' in directive '#pragma omp sections'}}
135 {
136 foo();
137 }
138#pragma omp parallel
139 {
140 int v = 0;
141 int i; // expected-note {{variable with automatic storage duration is predetermined as private; perhaps you forget to enclose 'omp sections' directive into a parallel or another task region?}}
142#pragma omp sections lastprivate(i) // expected-error {{lastprivate variable must be shared}}
143 {
144 foo();
145 }
146 v += i;
147 }
148#pragma omp parallel shared(i)
149#pragma omp parallel private(i)
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000150#pragma omp sections lastprivate(j)
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000151 {
152 foo();
153 }
154#pragma omp parallel
155#pragma omp sections lastprivate(i)
156 {
157 foo();
158 }
159 return 0;
160}
161
Alexey Bataev6ddfe1a2015-04-16 13:49:42 +0000162namespace A {
163double x;
164#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
165}
166namespace B {
167using A::x;
168}
169
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000170int main(int argc, char **argv) {
Joel E. Dennye6234d1422019-01-04 22:11:31 +0000171 const int d = 5; // expected-note {{'d' defined here}}
172 const int da[5] = {0}; // expected-note {{'da' defined here}}
Alexey Bataev38e89532015-04-16 04:54:05 +0000173 S4 e(4);
174 S5 g(5);
175 S3 m;
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000176 S6 n(2);
177 int i;
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000178 int &j = i;
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000179#pragma omp parallel
180#pragma omp sections lastprivate // expected-error {{expected '(' after 'lastprivate'}}
181 {
182 foo();
183 }
184#pragma omp parallel
185#pragma omp sections lastprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
186 {
187 foo();
188 }
189#pragma omp parallel
190#pragma omp sections lastprivate() // expected-error {{expected expression}}
191 {
192 foo();
193 }
194#pragma omp parallel
195#pragma omp sections lastprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
196 {
197 foo();
198 }
199#pragma omp parallel
Alexey Bataevc5970622016-04-01 08:43:42 +0000200#pragma omp sections lastprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000201 {
202 foo();
203 }
204#pragma omp parallel
205#pragma omp sections lastprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
206 {
207 foo();
208 }
209#pragma omp parallel
Alexey Bataeve04483e2019-03-27 14:14:31 +0000210#pragma omp sections lastprivate(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 Bataevd3f8dd22014-06-25 11:44:49 +0000211 {
212 foo();
213 }
214#pragma omp parallel
215#pragma omp sections lastprivate(S1) // expected-error {{'S1' does not refer to a value}}
216 {
217 foo();
218 }
219#pragma omp parallel
Joel E. Dennye6234d1422019-01-04 22:11:31 +0000220#pragma omp sections lastprivate(a, b, c, d, f) // expected-error {{lastprivate variable with incomplete type 'S1'}} expected-error 1 {{const-qualified variable without mutable fields cannot be lastprivate}} expected-error 2 {{const-qualified variable cannot be lastprivate}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000221 {
222 foo();
223 }
224#pragma omp parallel
225#pragma omp sections lastprivate(argv[1]) // expected-error {{expected variable name}}
226 {
227 foo();
228 }
229#pragma omp parallel
230#pragma omp sections lastprivate(2 * 2) // expected-error {{expected variable name}}
231 {
232 foo();
233 }
234#pragma omp parallel
235#pragma omp sections lastprivate(ba)
236 {
237 foo();
238 }
239#pragma omp parallel
Joel E. Dennye6234d1422019-01-04 22:11:31 +0000240#pragma omp sections lastprivate(ca) // expected-error {{const-qualified variable without mutable fields cannot be lastprivate}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000241 {
242 foo();
243 }
244#pragma omp parallel
Joel E. Dennye6234d1422019-01-04 22:11:31 +0000245#pragma omp sections lastprivate(da) // expected-error {{const-qualified variable cannot be lastprivate}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000246 {
247 foo();
248 }
249 int xa;
250#pragma omp parallel
251#pragma omp sections lastprivate(xa) // OK
252 {
253 foo();
254 }
255#pragma omp parallel
256#pragma omp sections lastprivate(S2::S2s) // expected-error {{shared variable cannot be lastprivate}}
257 {
258 foo();
259 }
260#pragma omp parallel
Joel E. Dennye6234d1422019-01-04 22:11:31 +0000261#pragma omp sections lastprivate(S2::S2sc) // expected-error {{const-qualified variable cannot be lastprivate}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000262 {
263 foo();
264 }
265#pragma omp parallel
266#pragma omp sections safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp sections'}}
267 {
268 foo();
269 }
270#pragma omp parallel
Alexey Bataev38e89532015-04-16 04:54:05 +0000271#pragma omp sections lastprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000272 {
273 foo();
274 }
275#pragma omp parallel
Alexey Bataev38e89532015-04-16 04:54:05 +0000276#pragma omp sections lastprivate(m) // expected-error {{'operator=' is a private member of 'S3'}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000277 {
278 foo();
279 }
280#pragma omp parallel
Alexey Bataev6ddfe1a2015-04-16 13:49:42 +0000281#pragma omp sections lastprivate(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be lastprivate}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000282 {
283 foo();
284 }
285#pragma omp parallel
286#pragma omp sections private(xa), lastprivate(xa) // expected-error {{private variable cannot be lastprivate}} expected-note {{defined as private}}
287 {
288 foo();
289 }
290#pragma omp parallel
291#pragma omp sections lastprivate(i)
292 {
293 foo();
294 }
295#pragma omp parallel private(xa) // expected-note {{defined as private}}
296#pragma omp sections lastprivate(xa) // expected-error {{lastprivate variable must be shared}}
297 {
298 foo();
299 }
300#pragma omp parallel reduction(+ : xa) // expected-note {{defined as reduction}}
301#pragma omp sections lastprivate(xa) // expected-error {{lastprivate variable must be shared}}
302 {
303 foo();
304 }
305#pragma omp parallel
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000306#pragma omp sections lastprivate(j)
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000307 {
308 foo();
309 }
310#pragma omp parallel
Alexey Bataev38e89532015-04-16 04:54:05 +0000311#pragma omp sections firstprivate(m) lastprivate(m) // expected-error {{'operator=' is a private member of 'S3'}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000312 {
313 foo();
314 }
315#pragma omp parallel
316#pragma omp sections lastprivate(n) firstprivate(n) // OK
317 {
318 foo();
319 }
Kelvin Li4eea8c62015-09-15 18:56:58 +0000320 static int r;
321#pragma omp sections lastprivate(r) // OK
322 {
323 foo();
324 }
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000325 return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}
326}