1 // RUN: %clang_cc1 -verify -fopenmp %s
2 
3 // RUN: %clang_cc1 -verify -fopenmp-simd %s
4 
5 void foo() {
6 }
7 
8 bool foobool(int argc) {
9   return argc;
10 }
11 
12 struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
13 extern S1 a;
14 class S2 {
15   mutable int a;
16 
17 public:
18   S2() : a(0) {}
19   S2(S2 &s2) : a(s2.a) {}
20   const S2 &operator=(const S2 &) const;
21   static float S2s; // expected-note {{static data member is predetermined as shared}}
22   static const float S2sc; // expected-note {{static data member is predetermined as shared}}
23 };
24 const float S2::S2sc = 0;
25 const S2 b;
26 const S2 ba[5];
27 class S3 {
28   int a;
29   S3 &operator=(const S3 &s3); // expected-note 2 {{implicitly declared private here}}
30 
31 public:
32   S3() : a(0) {}
33   S3(S3 &s3) : a(s3.a) {}
34 };
35 const S3 c;         // expected-note {{global variable is predetermined as shared}}
36 const S3 ca[5];     // expected-note {{global variable is predetermined as shared}}
37 extern const int f; // expected-note {{global variable is predetermined as shared}}
38 class S4 {
39   int a;
40   S4();          // expected-note 3 {{implicitly declared private here}}
41   S4(const S4 &s4);
42 
43 public:
44   S4(int v) : a(v) {}
45 };
46 class S5 {
47   int a;
48   S5() : a(0) {} // expected-note {{implicitly declared private here}}
49 
50 public:
51   S5(const S5 &s5) : a(s5.a) {}
52   S5(int v) : a(v) {}
53 };
54 class S6 {
55   int a;
56   S6() : a(0) {}
57 
58 public:
59   S6(const S6 &s6) : a(s6.a) {}
60   S6(int v) : a(v) {}
61 };
62 
63 S3 h;
64 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
65 
66 template <class I, class C>
67 int foomain(int argc, char **argv) {
68   I e(4);
69   I g(5);
70   int i;
71   int &j = i;
72 #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
93 #pragma omp sections lastprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
94   {
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
123 #pragma omp sections lastprivate(e, g) // expected-error 2 {{calling a private constructor of class 'S4'}}
124   {
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)
149 #pragma omp sections lastprivate(j)
150   {
151     foo();
152   }
153 #pragma omp parallel
154 #pragma omp sections lastprivate(i)
155   {
156     foo();
157   }
158   return 0;
159 }
160 
161 namespace A {
162 double x;
163 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
164 }
165 namespace B {
166 using A::x;
167 }
168 
169 int 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}}
172   S4 e(4);
173   S5 g(5);
174   S3 m;
175   S6 n(2);
176   int i;
177   int &j = i;
178 #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
199 #pragma omp sections lastprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
200   {
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
270 #pragma omp sections lastprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
271   {
272     foo();
273   }
274 #pragma omp parallel
275 #pragma omp sections lastprivate(m) // expected-error {{'operator=' is a private member of 'S3'}}
276   {
277     foo();
278   }
279 #pragma omp parallel
280 #pragma omp sections lastprivate(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be lastprivate}}
281   {
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
305 #pragma omp sections lastprivate(j)
306   {
307     foo();
308   }
309 #pragma omp parallel
310 #pragma omp sections firstprivate(m) lastprivate(m) // expected-error {{'operator=' is a private member of 'S3'}}
311   {
312     foo();
313   }
314 #pragma omp parallel
315 #pragma omp sections lastprivate(n) firstprivate(n) // OK
316   {
317     foo();
318   }
319   static int r;
320 #pragma omp sections lastprivate(r) // OK
321   {
322     foo();
323   }
324   return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}
325 }
326