blob: af3c5e2a575ba57160cdb4df7ca4810a922e99f2 [file] [log] [blame]
Alexey Bataevdb390212015-05-20 04:24:19 +00001// RUN: %clang_cc1 -verify -fopenmp %s
Alexey Bataev84d0b3e2014-07-08 08:12:03 +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 Bataevdffa93a2015-12-10 08:20:58 +000019 static float S2s; // expected-note {{static data member is predetermined as shared}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +000020 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 Bataev84d0b3e2014-07-08 08:12:03 +000026 int a;
Alexey Bataev38e89532015-04-16 04:54:05 +000027 S3 &operator=(const S3 &s3); // expected-note 2 {{implicitly declared private here}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +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 Bataev84d0b3e2014-07-08 08:12:03 +000037 int a;
Alexey Bataev38e89532015-04-16 04:54:05 +000038 S4(); // expected-note 3 {{implicitly declared private here}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +000039 S4(const S4 &s4);
40
41public:
42 S4(int v) : a(v) {}
43};
Alexey Bataev38e89532015-04-16 04:54:05 +000044class S5 {
Alexey Bataev84d0b3e2014-07-08 08:12:03 +000045 int a;
Alexey Bataev38e89532015-04-16 04:54:05 +000046 S5() : a(0) {} // expected-note {{implicitly declared private here}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +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 Bataev84d0b3e2014-07-08 08:12:03 +000068 int i;
Alexey Bataevbd9fec12015-08-18 06:47:21 +000069 int &j = i;
Alexey Bataev84d0b3e2014-07-08 08:12:03 +000070#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 }
Alexey Bataev38e89532015-04-16 04:54:05 +0000110#pragma omp parallel sections lastprivate(e, g) // expected-error 2 {{calling a private constructor of class 'S4'}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000111 {
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)
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000134#pragma omp parallel sections lastprivate(j)
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000135 {
136 foo();
137 }
138#pragma omp parallel sections lastprivate(i)
139 {
140 foo();
141 }
142 return 0;
143}
144
Alexey Bataev6ddfe1a2015-04-16 13:49:42 +0000145namespace A {
146double x;
147#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
148}
149namespace B {
150using A::x;
151}
152
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000153int 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}}
Alexey Bataev38e89532015-04-16 04:54:05 +0000156 S4 e(4);
157 S5 g(5);
158 S3 m;
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000159 S6 n(2);
160 int i;
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000161 int &j = i;
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000162#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 }
Alexey Bataevdffa93a2015-12-10 08:20:58 +0000223#pragma omp parallel sections lastprivate(S2::S2s) // expected-error {{shared variable cannot be lastprivate}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000224 {
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 }
Alexey Bataev38e89532015-04-16 04:54:05 +0000235#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'}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000236 {
237 foo();
238 }
Alexey Bataev38e89532015-04-16 04:54:05 +0000239#pragma omp parallel sections lastprivate(m) // expected-error {{'operator=' is a private member of 'S3'}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000240 {
241 foo();
242 }
Alexey Bataev6ddfe1a2015-04-16 13:49:42 +0000243#pragma omp parallel sections lastprivate(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be lastprivate}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000244 {
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 }
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000265#pragma omp parallel sections lastprivate(j)
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000266 {
267 foo();
268 }
Alexey Bataev38e89532015-04-16 04:54:05 +0000269#pragma omp parallel sections firstprivate(m) lastprivate(m) // expected-error {{'operator=' is a private member of 'S3'}}
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000270 {
271 foo();
272 }
273#pragma omp parallel sections lastprivate(n) firstprivate(n) // OK
274 {
275 foo();
276 }
Kelvin Li4eea8c62015-09-15 18:56:58 +0000277 static int r;
278#pragma omp parallel sections lastprivate(r) // OK
279 {
280 foo();
281 }
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000282 return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}
283}