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(const S2 &s2) : a(s2.a) {}
20   static float S2s;
21   static const float S2sc;
22 };
23 const float S2::S2sc = 0;
24 const S2 b;
25 const S2 ba[5];
26 class S3 {
27   int a;
28   S3 &operator=(const S3 &s3);
29 
30 public:
31   S3() : a(0) {}
32   S3(const S3 &s3) : a(s3.a) {}
33 };
34 const S3 c;
35 const S3 ca[5];
36 extern const int f;
37 class S4 {
38   int a;
39   S4();
40   S4(const S4 &s4); // expected-note 2 {{implicitly declared private here}}
41 
42 public:
43   S4(int v) : a(v) {}
44 };
45 class S5 {
46   int a;
47   S5(const S5 &s5) : a(s5.a) {} // expected-note 4 {{implicitly declared private here}}
48 
49 public:
50   S5() : a(0) {}
51   S5(int v) : a(v) {}
52 };
53 class S6 {
54   int a;
55   S6() : a(0) {}
56 
57 public:
58   S6(const S6 &s6) : a(s6.a) {}
59   S6(int v) : a(v) {}
60 };
61 
62 S3 h;
63 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
64 
65 template <class I, class C>
66 int foomain(int argc, char **argv) {
67   I e(4);
68   C g(5);
69   int i;
70   int &j = i;
71 #pragma omp parallel sections firstprivate // expected-error {{expected '(' after 'firstprivate'}}
72   {
73     foo();
74   }
75 #pragma omp parallel sections firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
76   {
77     foo();
78   }
79 #pragma omp parallel sections firstprivate() // expected-error {{expected expression}}
80   {
81     foo();
82   }
83 #pragma omp parallel sections firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
84   {
85     foo();
86   }
87 #pragma omp parallel sections firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
88   {
89     foo();
90   }
91 #pragma omp parallel sections firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
92   {
93     foo();
94   }
95 #pragma omp parallel sections firstprivate(argc)
96   {
97     foo();
98   }
99 #pragma omp parallel sections firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
100   {
101     foo();
102   }
103 #pragma omp parallel sections firstprivate(a, b) // expected-error {{firstprivate variable with incomplete type 'S1'}}
104   {
105     foo();
106   }
107 #pragma omp parallel sections firstprivate(argv[1]) // expected-error {{expected variable name}}
108   {
109     foo();
110   }
111 #pragma omp parallel sections firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
112   {
113     foo();
114   }
115 #pragma omp parallel sections firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
116   {
117     foo();
118   }
119 #pragma omp parallel sections linear(i) // expected-error {{unexpected OpenMP clause 'linear' in directive '#pragma omp parallel sections'}}
120   {
121     foo();
122   }
123 #pragma omp parallel
124   {
125     int v = 0;
126     int i;
127 #pragma omp parallel sections firstprivate(i)
128     {
129       foo();
130     }
131     v += i;
132   }
133 #pragma omp parallel shared(i)
134 #pragma omp parallel private(i)
135 #pragma omp parallel sections firstprivate(j)
136   {
137     foo();
138   }
139 #pragma omp parallel sections firstprivate(i)
140   {
141     foo();
142   }
143 #pragma omp parallel sections lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
144   {
145     foo();
146   }
147 #pragma omp parallel private(i)
148 #pragma omp parallel sections firstprivate(i)
149   {
150     foo();
151   }
152 #pragma omp parallel reduction(+ : i)
153 #pragma omp parallel sections firstprivate(i)
154   {
155     foo();
156   }
157   return 0;
158 }
159 
160 namespace A {
161 double x;
162 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
163 }
164 namespace B {
165 using A::x;
166 }
167 
168 int main(int argc, char **argv) {
169   const int d = 5;
170   const int da[5] = {0};
171   S4 e(4);
172   S5 g(5);
173   S3 m;
174   S6 n(2);
175   int i;
176   int &j = i;
177 #pragma omp parallel sections firstprivate // expected-error {{expected '(' after 'firstprivate'}}
178   {
179     foo();
180   }
181 #pragma omp parallel sections firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
182   {
183     foo();
184   }
185 #pragma omp parallel sections firstprivate() // expected-error {{expected expression}}
186   {
187     foo();
188   }
189 #pragma omp parallel sections firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
190   {
191     foo();
192   }
193 #pragma omp parallel sections firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
194   {
195     foo();
196   }
197 #pragma omp parallel sections firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
198   {
199     foo();
200   }
201 #pragma omp parallel sections firstprivate(argc)
202   {
203     foo();
204   }
205 #pragma omp parallel sections firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
206   {
207     foo();
208   }
209 #pragma omp parallel sections firstprivate(a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}}
210   {
211     foo();
212   }
213 #pragma omp parallel sections firstprivate(argv[1]) // expected-error {{expected variable name}}
214   {
215     foo();
216   }
217 #pragma omp parallel sections firstprivate(2 * 2) // expected-error {{expected variable name}}
218   {
219     foo();
220   }
221 #pragma omp parallel sections firstprivate(ba) // OK
222   {
223     foo();
224   }
225 #pragma omp parallel sections firstprivate(ca) // OK
226   {
227     foo();
228   }
229 #pragma omp parallel sections firstprivate(da) // OK
230   {
231     foo();
232   }
233   int xa;
234 #pragma omp parallel sections firstprivate(xa) // OK
235   {
236     foo();
237   }
238 #pragma omp parallel sections firstprivate(S2::S2s) // OK
239   {
240     foo();
241   }
242 #pragma omp parallel sections firstprivate(S2::S2sc) // OK
243   {
244     foo();
245   }
246 #pragma omp parallel sections safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp parallel sections'}}
247   {
248     foo();
249   }
250 #pragma omp parallel sections firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
251   {
252     foo();
253   }
254 #pragma omp parallel sections firstprivate(m) // OK
255   {
256     foo();
257   }
258 #pragma omp parallel sections firstprivate(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be firstprivate}}
259   {
260     foo();
261   }
262 #pragma omp parallel sections private(xa), firstprivate(xa) // expected-error {{private variable cannot be firstprivate}} expected-note {{defined as private}}
263   {
264     foo();
265   }
266 #pragma omp parallel shared(xa)
267 #pragma omp parallel sections firstprivate(xa) // OK: may be firstprivate
268   {
269     foo();
270   }
271 #pragma omp parallel sections firstprivate(j)
272   {
273     foo();
274   }
275 #pragma omp parallel sections lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
276   {
277     foo();
278   }
279 #pragma omp parallel sections lastprivate(n) firstprivate(n) // OK
280   {
281     foo();
282   }
283 #pragma omp parallel
284   {
285     int v = 0;
286     int i;
287 #pragma omp parallel sections firstprivate(i)
288     {
289       foo();
290     }
291     v += i;
292   }
293 #pragma omp parallel private(i)
294 #pragma omp parallel sections firstprivate(i)
295   {
296     foo();
297   }
298 #pragma omp parallel reduction(+ : i)
299 #pragma omp parallel sections firstprivate(i)
300   {
301     foo();
302   }
303   static int r;
304 #pragma omp parallel sections firstprivate(r) // OK
305   {
306     foo();
307   }
308 
309   return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}
310 }
311