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