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