blob: 870dd158aeeba2c99588c47152836608ed1fc3fd [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
3void foo() {
4}
5
6bool foobool(int argc) {
7 return argc;
8}
9
10struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
11extern S1 a;
12class S2 {
13 mutable int a;
14
15public:
16 S2() : a(0) {}
17 S2(S2 &s2) : a(s2.a) {}
Alexey Bataev38e89532015-04-16 04:54:05 +000018 const S2 &operator=(const S2 &) const;
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000019 static float S2s; // expected-note {{static data member is predetermined as shared}}
20 static const float S2sc;
21};
22const float S2::S2sc = 0; // expected-note {{static data member is predetermined as shared}}
23const S2 b;
24const S2 ba[5];
Alexey Bataev38e89532015-04-16 04:54:05 +000025class S3 {
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000026 int a;
Alexey Bataev38e89532015-04-16 04:54:05 +000027 S3 &operator=(const S3 &s3); // expected-note 2 {{implicitly declared private here}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000028
29public:
30 S3() : a(0) {}
31 S3(S3 &s3) : a(s3.a) {}
32};
33const S3 c; // expected-note {{global variable is predetermined as shared}}
34const S3 ca[5]; // expected-note {{global variable is predetermined as shared}}
35extern const int f; // expected-note {{global variable is predetermined as shared}}
Alexey Bataev38e89532015-04-16 04:54:05 +000036class S4 {
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000037 int a;
Alexey Bataev38e89532015-04-16 04:54:05 +000038 S4(); // expected-note 3 {{implicitly declared private here}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000039 S4(const S4 &s4);
40
41public:
42 S4(int v) : a(v) {}
43};
Alexey Bataev38e89532015-04-16 04:54:05 +000044class S5 {
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000045 int a;
Alexey Bataev38e89532015-04-16 04:54:05 +000046 S5() : a(0) {} // expected-note {{implicitly declared private here}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000047
48public:
49 S5(const S5 &s5) : a(s5.a) {}
50 S5(int v) : a(v) {}
51};
52class S6 {
53 int a;
54 S6() : a(0) {}
55
56public:
57 S6(const S6 &s6) : a(s6.a) {}
58 S6(int v) : a(v) {}
59};
60
61S3 h;
62#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
63
64template <class I, class C>
65int foomain(int argc, char **argv) {
Alexey Bataev38e89532015-04-16 04:54:05 +000066 I e(4);
67 I g(5);
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000068 int i;
69 int &j = i; // expected-note {{'j' defined here}}
70#pragma omp parallel
71#pragma omp sections lastprivate // expected-error {{expected '(' after 'lastprivate'}}
72 {
73 foo();
74 }
75#pragma omp parallel
76#pragma omp sections lastprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
77 {
78 foo();
79 }
80#pragma omp parallel
81#pragma omp sections lastprivate() // expected-error {{expected expression}}
82 {
83 foo();
84 }
85#pragma omp parallel
86#pragma omp sections lastprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
87 {
88 foo();
89 }
90#pragma omp parallel
91#pragma omp sections lastprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
92 {
93 foo();
94 }
95#pragma omp parallel
96#pragma omp sections lastprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
97 {
98 foo();
99 }
100#pragma omp parallel
101#pragma omp sections lastprivate(argc)
102 {
103 foo();
104 }
105#pragma omp parallel
106#pragma omp sections lastprivate(S1) // expected-error {{'S1' does not refer to a value}}
107 {
108 foo();
109 }
110#pragma omp parallel
111#pragma omp sections lastprivate(a, b) // expected-error {{lastprivate variable with incomplete type 'S1'}}
112 {
113 foo();
114 }
115#pragma omp parallel
116#pragma omp sections lastprivate(argv[1]) // expected-error {{expected variable name}}
117 {
118 foo();
119 }
120#pragma omp parallel
Alexey Bataev38e89532015-04-16 04:54:05 +0000121#pragma omp sections lastprivate(e, g) // expected-error 2 {{calling a private constructor of class 'S4'}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000122 {
123 foo();
124 }
125#pragma omp parallel
126#pragma omp sections lastprivate(h) // expected-error {{threadprivate or thread local variable cannot be lastprivate}}
127 {
128 foo();
129 }
130#pragma omp parallel
131#pragma omp sections linear(i) // expected-error {{unexpected OpenMP clause 'linear' in directive '#pragma omp sections'}}
132 {
133 foo();
134 }
135#pragma omp parallel
136 {
137 int v = 0;
138 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?}}
139#pragma omp sections lastprivate(i) // expected-error {{lastprivate variable must be shared}}
140 {
141 foo();
142 }
143 v += i;
144 }
145#pragma omp parallel shared(i)
146#pragma omp parallel private(i)
147#pragma omp sections lastprivate(j) // expected-error {{arguments of OpenMP clause 'lastprivate' cannot be of reference type}}
148 {
149 foo();
150 }
151#pragma omp parallel
152#pragma omp sections lastprivate(i)
153 {
154 foo();
155 }
156 return 0;
157}
158
Alexey Bataev6ddfe1a2015-04-16 13:49:42 +0000159namespace A {
160double x;
161#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
162}
163namespace B {
164using A::x;
165}
166
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000167int main(int argc, char **argv) {
168 const int d = 5; // expected-note {{constant variable is predetermined as shared}}
169 const int da[5] = {0}; // expected-note {{constant variable is predetermined as shared}}
Alexey Bataev38e89532015-04-16 04:54:05 +0000170 S4 e(4);
171 S5 g(5);
172 S3 m;
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000173 S6 n(2);
174 int i;
175 int &j = i; // expected-note {{'j' defined here}}
176#pragma omp parallel
177#pragma omp sections lastprivate // expected-error {{expected '(' after 'lastprivate'}}
178 {
179 foo();
180 }
181#pragma omp parallel
182#pragma omp sections lastprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
183 {
184 foo();
185 }
186#pragma omp parallel
187#pragma omp sections lastprivate() // expected-error {{expected expression}}
188 {
189 foo();
190 }
191#pragma omp parallel
192#pragma omp sections lastprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
193 {
194 foo();
195 }
196#pragma omp parallel
197#pragma omp sections lastprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
198 {
199 foo();
200 }
201#pragma omp parallel
202#pragma omp sections lastprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
203 {
204 foo();
205 }
206#pragma omp parallel
207#pragma omp sections lastprivate(argc)
208 {
209 foo();
210 }
211#pragma omp parallel
212#pragma omp sections lastprivate(S1) // expected-error {{'S1' does not refer to a value}}
213 {
214 foo();
215 }
216#pragma omp parallel
217#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}}
218 {
219 foo();
220 }
221#pragma omp parallel
222#pragma omp sections lastprivate(argv[1]) // expected-error {{expected variable name}}
223 {
224 foo();
225 }
226#pragma omp parallel
227#pragma omp sections lastprivate(2 * 2) // expected-error {{expected variable name}}
228 {
229 foo();
230 }
231#pragma omp parallel
232#pragma omp sections lastprivate(ba)
233 {
234 foo();
235 }
236#pragma omp parallel
237#pragma omp sections lastprivate(ca) // expected-error {{shared variable cannot be lastprivate}}
238 {
239 foo();
240 }
241#pragma omp parallel
242#pragma omp sections lastprivate(da) // expected-error {{shared variable cannot be lastprivate}}
243 {
244 foo();
245 }
246 int xa;
247#pragma omp parallel
248#pragma omp sections lastprivate(xa) // OK
249 {
250 foo();
251 }
252#pragma omp parallel
253#pragma omp sections lastprivate(S2::S2s) // expected-error {{shared variable cannot be lastprivate}}
254 {
255 foo();
256 }
257#pragma omp parallel
258#pragma omp sections lastprivate(S2::S2sc) // expected-error {{shared variable cannot be lastprivate}}
259 {
260 foo();
261 }
262#pragma omp parallel
263#pragma omp sections safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp sections'}}
264 {
265 foo();
266 }
267#pragma omp parallel
Alexey Bataev38e89532015-04-16 04:54:05 +0000268#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 +0000269 {
270 foo();
271 }
272#pragma omp parallel
Alexey Bataev38e89532015-04-16 04:54:05 +0000273#pragma omp sections lastprivate(m) // expected-error {{'operator=' is a private member of 'S3'}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000274 {
275 foo();
276 }
277#pragma omp parallel
Alexey Bataev6ddfe1a2015-04-16 13:49:42 +0000278#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 +0000279 {
280 foo();
281 }
282#pragma omp parallel
283#pragma omp sections private(xa), lastprivate(xa) // expected-error {{private variable cannot be lastprivate}} expected-note {{defined as private}}
284 {
285 foo();
286 }
287#pragma omp parallel
288#pragma omp sections lastprivate(i)
289 {
290 foo();
291 }
292#pragma omp parallel private(xa) // expected-note {{defined as private}}
293#pragma omp sections lastprivate(xa) // expected-error {{lastprivate variable must be shared}}
294 {
295 foo();
296 }
297#pragma omp parallel reduction(+ : xa) // expected-note {{defined as reduction}}
298#pragma omp sections lastprivate(xa) // expected-error {{lastprivate variable must be shared}}
299 {
300 foo();
301 }
302#pragma omp parallel
303#pragma omp sections lastprivate(j) // expected-error {{arguments of OpenMP clause 'lastprivate' cannot be of reference type}}
304 {
305 foo();
306 }
307#pragma omp parallel
Alexey Bataev38e89532015-04-16 04:54:05 +0000308#pragma omp sections firstprivate(m) lastprivate(m) // expected-error {{'operator=' is a private member of 'S3'}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000309 {
310 foo();
311 }
312#pragma omp parallel
313#pragma omp sections lastprivate(n) firstprivate(n) // OK
314 {
315 foo();
316 }
317 return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}
318}