blob: e24b58fa29bc91e85ff69e02e16dfe6f65339f70 [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 Bataevd3f8dd22014-06-25 11:44:49 +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) {}
19 S2(S2 &s2) : a(s2.a) {}
Alexey Bataev38e89532015-04-16 04:54:05 +000020 const S2 &operator=(const S2 &) const;
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000021 static float S2s; // expected-note {{static data member is predetermined as shared}}
Alexey Bataev4d4624c2017-07-20 16:47:47 +000022 static const float S2sc; // expected-note {{static data member is predetermined as shared}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000023};
Alexey Bataev4d4624c2017-07-20 16:47:47 +000024const float S2::S2sc = 0;
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000025const S2 b;
26const S2 ba[5];
Alexey Bataev38e89532015-04-16 04:54:05 +000027class S3 {
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000028 int a;
Alexey Bataev38e89532015-04-16 04:54:05 +000029 S3 &operator=(const S3 &s3); // expected-note 2 {{implicitly declared private here}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000030
31public:
32 S3() : a(0) {}
33 S3(S3 &s3) : a(s3.a) {}
34};
35const S3 c; // expected-note {{global variable is predetermined as shared}}
36const S3 ca[5]; // expected-note {{global variable is predetermined as shared}}
37extern const int f; // expected-note {{global variable is predetermined as shared}}
Alexey Bataev38e89532015-04-16 04:54:05 +000038class S4 {
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000039 int a;
Alexey Bataev38e89532015-04-16 04:54:05 +000040 S4(); // expected-note 3 {{implicitly declared private here}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000041 S4(const S4 &s4);
42
43public:
44 S4(int v) : a(v) {}
45};
Alexey Bataev38e89532015-04-16 04:54:05 +000046class S5 {
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000047 int a;
Alexey Bataev38e89532015-04-16 04:54:05 +000048 S5() : a(0) {} // expected-note {{implicitly declared private here}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000049
50public:
51 S5(const S5 &s5) : a(s5.a) {}
52 S5(int v) : a(v) {}
53};
54class S6 {
55 int a;
56 S6() : a(0) {}
57
58public:
59 S6(const S6 &s6) : a(s6.a) {}
60 S6(int v) : a(v) {}
61};
62
63S3 h;
64#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
65
66template <class I, class C>
67int foomain(int argc, char **argv) {
Alexey Bataev38e89532015-04-16 04:54:05 +000068 I e(4);
69 I g(5);
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000070 int i;
Alexey Bataevbd9fec12015-08-18 06:47:21 +000071 int &j = i;
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000072#pragma omp parallel
73#pragma omp sections lastprivate // expected-error {{expected '(' after 'lastprivate'}}
74 {
75 foo();
76 }
77#pragma omp parallel
78#pragma omp sections lastprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
79 {
80 foo();
81 }
82#pragma omp parallel
83#pragma omp sections lastprivate() // expected-error {{expected expression}}
84 {
85 foo();
86 }
87#pragma omp parallel
88#pragma omp sections lastprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
89 {
90 foo();
91 }
92#pragma omp parallel
Alexey Bataevc5970622016-04-01 08:43:42 +000093#pragma omp sections lastprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000094 {
95 foo();
96 }
97#pragma omp parallel
98#pragma omp sections lastprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
99 {
100 foo();
101 }
102#pragma omp parallel
103#pragma omp sections lastprivate(argc)
104 {
105 foo();
106 }
107#pragma omp parallel
108#pragma omp sections lastprivate(S1) // expected-error {{'S1' does not refer to a value}}
109 {
110 foo();
111 }
112#pragma omp parallel
113#pragma omp sections lastprivate(a, b) // expected-error {{lastprivate variable with incomplete type 'S1'}}
114 {
115 foo();
116 }
117#pragma omp parallel
118#pragma omp sections lastprivate(argv[1]) // expected-error {{expected variable name}}
119 {
120 foo();
121 }
122#pragma omp parallel
Alexey Bataev38e89532015-04-16 04:54:05 +0000123#pragma omp sections lastprivate(e, g) // expected-error 2 {{calling a private constructor of class 'S4'}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000124 {
125 foo();
126 }
127#pragma omp parallel
128#pragma omp sections lastprivate(h) // expected-error {{threadprivate or thread local variable cannot be lastprivate}}
129 {
130 foo();
131 }
132#pragma omp parallel
133#pragma omp sections linear(i) // expected-error {{unexpected OpenMP clause 'linear' in directive '#pragma omp sections'}}
134 {
135 foo();
136 }
137#pragma omp parallel
138 {
139 int v = 0;
140 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?}}
141#pragma omp sections lastprivate(i) // expected-error {{lastprivate variable must be shared}}
142 {
143 foo();
144 }
145 v += i;
146 }
147#pragma omp parallel shared(i)
148#pragma omp parallel private(i)
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000149#pragma omp sections lastprivate(j)
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000150 {
151 foo();
152 }
153#pragma omp parallel
154#pragma omp sections lastprivate(i)
155 {
156 foo();
157 }
158 return 0;
159}
160
Alexey Bataev6ddfe1a2015-04-16 13:49:42 +0000161namespace A {
162double x;
163#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
164}
165namespace B {
166using A::x;
167}
168
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000169int main(int argc, char **argv) {
170 const int d = 5; // expected-note {{constant variable is predetermined as shared}}
171 const int da[5] = {0}; // expected-note {{constant variable is predetermined as shared}}
Alexey Bataev38e89532015-04-16 04:54:05 +0000172 S4 e(4);
173 S5 g(5);
174 S3 m;
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000175 S6 n(2);
176 int i;
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000177 int &j = i;
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000178#pragma omp parallel
179#pragma omp sections lastprivate // expected-error {{expected '(' after 'lastprivate'}}
180 {
181 foo();
182 }
183#pragma omp parallel
184#pragma omp sections lastprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
185 {
186 foo();
187 }
188#pragma omp parallel
189#pragma omp sections lastprivate() // expected-error {{expected expression}}
190 {
191 foo();
192 }
193#pragma omp parallel
194#pragma omp sections lastprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
195 {
196 foo();
197 }
198#pragma omp parallel
Alexey Bataevc5970622016-04-01 08:43:42 +0000199#pragma omp sections lastprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000200 {
201 foo();
202 }
203#pragma omp parallel
204#pragma omp sections lastprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
205 {
206 foo();
207 }
208#pragma omp parallel
209#pragma omp sections lastprivate(argc)
210 {
211 foo();
212 }
213#pragma omp parallel
214#pragma omp sections lastprivate(S1) // expected-error {{'S1' does not refer to a value}}
215 {
216 foo();
217 }
218#pragma omp parallel
219#pragma omp sections lastprivate(a, b, c, d, f) // expected-error {{lastprivate variable with incomplete type 'S1'}} expected-error 3 {{shared variable cannot be lastprivate}}
220 {
221 foo();
222 }
223#pragma omp parallel
224#pragma omp sections lastprivate(argv[1]) // expected-error {{expected variable name}}
225 {
226 foo();
227 }
228#pragma omp parallel
229#pragma omp sections lastprivate(2 * 2) // expected-error {{expected variable name}}
230 {
231 foo();
232 }
233#pragma omp parallel
234#pragma omp sections lastprivate(ba)
235 {
236 foo();
237 }
238#pragma omp parallel
239#pragma omp sections lastprivate(ca) // expected-error {{shared variable cannot be lastprivate}}
240 {
241 foo();
242 }
243#pragma omp parallel
244#pragma omp sections lastprivate(da) // expected-error {{shared variable cannot be lastprivate}}
245 {
246 foo();
247 }
248 int xa;
249#pragma omp parallel
250#pragma omp sections lastprivate(xa) // OK
251 {
252 foo();
253 }
254#pragma omp parallel
255#pragma omp sections lastprivate(S2::S2s) // expected-error {{shared variable cannot be lastprivate}}
256 {
257 foo();
258 }
259#pragma omp parallel
260#pragma omp sections lastprivate(S2::S2sc) // expected-error {{shared variable cannot be lastprivate}}
261 {
262 foo();
263 }
264#pragma omp parallel
265#pragma omp sections safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp sections'}}
266 {
267 foo();
268 }
269#pragma omp parallel
Alexey Bataev38e89532015-04-16 04:54:05 +0000270#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 +0000271 {
272 foo();
273 }
274#pragma omp parallel
Alexey Bataev38e89532015-04-16 04:54:05 +0000275#pragma omp sections lastprivate(m) // expected-error {{'operator=' is a private member of 'S3'}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000276 {
277 foo();
278 }
279#pragma omp parallel
Alexey Bataev6ddfe1a2015-04-16 13:49:42 +0000280#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 +0000281 {
282 foo();
283 }
284#pragma omp parallel
285#pragma omp sections private(xa), lastprivate(xa) // expected-error {{private variable cannot be lastprivate}} expected-note {{defined as private}}
286 {
287 foo();
288 }
289#pragma omp parallel
290#pragma omp sections lastprivate(i)
291 {
292 foo();
293 }
294#pragma omp parallel private(xa) // expected-note {{defined as private}}
295#pragma omp sections lastprivate(xa) // expected-error {{lastprivate variable must be shared}}
296 {
297 foo();
298 }
299#pragma omp parallel reduction(+ : xa) // expected-note {{defined as reduction}}
300#pragma omp sections lastprivate(xa) // expected-error {{lastprivate variable must be shared}}
301 {
302 foo();
303 }
304#pragma omp parallel
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000305#pragma omp sections lastprivate(j)
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000306 {
307 foo();
308 }
309#pragma omp parallel
Alexey Bataev38e89532015-04-16 04:54:05 +0000310#pragma omp sections firstprivate(m) lastprivate(m) // expected-error {{'operator=' is a private member of 'S3'}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000311 {
312 foo();
313 }
314#pragma omp parallel
315#pragma omp sections lastprivate(n) firstprivate(n) // OK
316 {
317 foo();
318 }
Kelvin Li4eea8c62015-09-15 18:56:58 +0000319 static int r;
320#pragma omp sections lastprivate(r) // OK
321 {
322 foo();
323 }
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000324 return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}
325}