blob: 27bb3136e72019a5ba8cbaa52fe366ec9febc121 [file] [log] [blame]
Alexey Bataevdb390212015-05-20 04:24:19 +00001// RUN: %clang_cc1 -verify -fopenmp %s
Alexey Bataevd3f8dd22014-06-25 11:44:49 +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};
18const S2 b;
19const S2 ba[5];
20class S3 {
21 int a;
22
23public:
24 S3() : a(0) {}
25};
26const S3 ca[5];
Alexey Bataev03b340a2014-10-21 03:16:40 +000027class S4 {
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000028 int a;
Alexey Bataev03b340a2014-10-21 03:16:40 +000029 S4(); // expected-note {{implicitly declared private here}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000030
31public:
Alexey Bataev48c0bfb2016-01-20 09:07:54 +000032 S4(int v) : a(v) {
33#pragma omp sections private(a) private(this->a)
34 {
35 for (int k = 0; k < v; ++k)
36 ++this->a;
37 }
38 }
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000039};
Alexey Bataev03b340a2014-10-21 03:16:40 +000040class S5 {
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000041 int a;
Alexey Bataev03b340a2014-10-21 03:16:40 +000042 S5() : a(0) {} // expected-note {{implicitly declared private here}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000043
44public:
45 S5(int v) : a(v) {}
Alexey Bataev48c0bfb2016-01-20 09:07:54 +000046 S5 &operator=(S5 &s) {
47#pragma omp sections private(a) private(this->a) private(s.a) // expected-error {{expected variable name or data member of current class}}
48 {
49 for (int k = 0; k < s.a; ++k)
50 ++s.a;
51 }
52 return *this;
53 }
54};
55
56template <typename T>
57class S6 {
58public:
59 T a;
60
61 S6() : a(0) {}
62 S6(T v) : a(v) {
63#pragma omp sections private(a) private(this->a)
64 {
65 for (int k = 0; k < v; ++k)
66 ++this->a;
67 }
68 }
69 S6 &operator=(S6 &s) {
70#pragma omp sections private(a) private(this->a) private(s.a) // expected-error {{expected variable name or data member of current class}}
71 {
72 for (int k = 0; k < s.a; ++k)
73 ++s.a;
74 }
75 return *this;
76 }
77};
78
79template <typename T>
80class S7 : public T {
81 T a;
82 S7() : a(0) {}
83
84public:
85 S7(T v) : a(v) {
86#pragma omp sections private(a) private(this->a) private(T::a)
87 {
88 for (int k = 0; k < a.a; ++k)
89 ++this->a.a;
90 }
91 }
92 S7 &operator=(S7 &s) {
93#pragma omp 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}}
94 {
95 for (int k = 0; k < s.a.a; ++k)
96 ++s.a.a;
97 }
98 return *this;
99 }
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000100};
101
102S3 h;
103#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
104
105template <class I, class C>
106int foomain(I argc, C **argv) {
107 I e(4);
108 I g(5);
109 int i;
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000110 int &j = i;
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000111#pragma omp sections private // expected-error {{expected '(' after 'private'}}
112 {
113 foo();
114 }
115#pragma omp sections private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
116 {
117 foo();
118 }
119#pragma omp sections private() // expected-error {{expected expression}}
120 {
121 foo();
122 }
123#pragma omp sections private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
124 {
125 foo();
126 }
Alexey Bataevc5970622016-04-01 08:43:42 +0000127#pragma omp sections private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000128 {
129 foo();
130 }
131#pragma omp sections private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
132 {
133 foo();
134 }
135#pragma omp sections private(argc)
136 {
137 foo();
138 }
139#pragma omp sections private(S1) // expected-error {{'S1' does not refer to a value}}
140 {
141 foo();
142 }
143#pragma omp sections private(a, b) // expected-error {{private variable with incomplete type 'S1'}}
144 {
145 foo();
146 }
147#pragma omp sections private(argv[1]) // expected-error {{expected variable name}}
148 {
149 foo();
150 }
151#pragma omp sections private(e, g)
152 {
153 foo();
154 }
155#pragma omp sections private(h) // expected-error {{threadprivate or thread local variable cannot be private}}
156 {
157 foo();
158 }
159#pragma omp sections shared(i) // expected-error {{unexpected OpenMP clause 'shared' in directive '#pragma omp sections'}}
160 {
161 foo();
162 }
163#pragma omp parallel
164 {
165 int v = 0;
166 int i;
167#pragma omp sections private(i)
168 {
169 foo();
170 }
171 v += i;
172 }
173#pragma omp parallel shared(i)
174#pragma omp parallel private(i)
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000175#pragma omp sections private(j)
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000176 {
177 foo();
178 }
179#pragma omp sections private(i)
180 {
181 foo();
182 }
183 return 0;
184}
185
Alexey Bataev6ddfe1a2015-04-16 13:49:42 +0000186namespace A {
187double x;
188#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
189}
190namespace B {
191using A::x;
192}
193
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000194int main(int argc, char **argv) {
Alexey Bataev03b340a2014-10-21 03:16:40 +0000195 S4 e(4);
196 S5 g(5);
Alexey Bataev48c0bfb2016-01-20 09:07:54 +0000197 S6<float> s6(0.0) , s6_0(1.0);
198 S7<S6<float> > s7(0.0) , s7_0(1.0);
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000199 int i;
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000200 int &j = i;
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000201#pragma omp sections private // expected-error {{expected '(' after 'private'}}
202 {
203 foo();
204 }
205#pragma omp sections private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
206 {
207 foo();
208 }
209#pragma omp sections private() // expected-error {{expected expression}}
210 {
211 foo();
212 }
213#pragma omp sections private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
214 {
215 foo();
216 }
Alexey Bataevc5970622016-04-01 08:43:42 +0000217#pragma omp sections private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000218 {
219 foo();
220 }
221#pragma omp sections private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
222 {
223 foo();
224 }
225#pragma omp sections private(argc)
226 {
227 foo();
228 }
229#pragma omp sections private(S1) // expected-error {{'S1' does not refer to a value}}
230 {
231 foo();
232 }
233#pragma omp sections private(a, b) // expected-error {{private variable with incomplete type 'S1'}}
234 {
235 foo();
236 }
237#pragma omp sections private(argv[1]) // expected-error {{expected variable name}}
238 {
239 foo();
240 }
Alexey Bataev03b340a2014-10-21 03:16:40 +0000241#pragma omp sections private(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000242 {
243 foo();
244 }
Alexey Bataev6ddfe1a2015-04-16 13:49:42 +0000245#pragma omp sections private(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be private}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000246 {
247 foo();
248 }
249#pragma omp sections shared(i) // expected-error {{unexpected OpenMP clause 'shared' in directive '#pragma omp sections'}}
250 {
251 foo();
252 }
253#pragma omp parallel
254 {
255 int i;
256#pragma omp sections private(i)
257 {
258 foo();
259 }
260 }
261#pragma omp parallel shared(i)
262#pragma omp parallel private(i)
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000263#pragma omp sections private(j)
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000264 {
265 foo();
266 }
267#pragma omp sections private(i)
268 {
269 foo();
270 }
Kelvin Li4eea8c62015-09-15 18:56:58 +0000271 static int m;
272#pragma omp sections private(m)
273 {
274 foo();
275 }
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000276
Alexey Bataev48c0bfb2016-01-20 09:07:54 +0000277 s6 = s6_0; // expected-note {{in instantiation of member function 'S6<float>::operator=' requested here}}
278 s7 = s7_0; // expected-note {{in instantiation of member function 'S7<S6<float> >::operator=' requested here}}
279 return foomain(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000280}
281