blob: 81e3eb4779b9a42e475d0e978ce7e323b22cec53 [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
Alexey Bataeva8a9153a2017-12-29 18:07:07 +00003// RUN: %clang_cc1 -verify -fopenmp-simd %s
4
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00005void foo() {
6}
7
8bool foobool(int argc) {
9 return argc;
10}
11
12struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
13extern S1 a;
14class S2 {
15 mutable int a;
16
17public:
18 S2() : a(0) {}
19};
20const S2 b;
21const S2 ba[5];
22class S3 {
23 int a;
24
25public:
26 S3() : a(0) {}
27};
28const S3 ca[5];
Alexey Bataev03b340a2014-10-21 03:16:40 +000029class S4 {
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000030 int a;
Alexey Bataev03b340a2014-10-21 03:16:40 +000031 S4(); // expected-note {{implicitly declared private here}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000032
33public:
Alexey Bataev48c0bfb2016-01-20 09:07:54 +000034 S4(int v) : a(v) {
35#pragma omp sections private(a) private(this->a)
36 {
37 for (int k = 0; k < v; ++k)
38 ++this->a;
39 }
40 }
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000041};
Alexey Bataev03b340a2014-10-21 03:16:40 +000042class S5 {
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000043 int a;
Alexey Bataev03b340a2014-10-21 03:16:40 +000044 S5() : a(0) {} // expected-note {{implicitly declared private here}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000045
46public:
47 S5(int v) : a(v) {}
Alexey Bataev48c0bfb2016-01-20 09:07:54 +000048 S5 &operator=(S5 &s) {
49#pragma omp 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
58template <typename T>
59class S6 {
60public:
61 T a;
62
63 S6() : a(0) {}
64 S6(T v) : a(v) {
65#pragma omp 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 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
81template <typename T>
82class S7 : public T {
83 T a;
84 S7() : a(0) {}
85
86public:
87 S7(T v) : a(v) {
88#pragma omp 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 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 }
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000102};
103
104S3 h;
105#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
106
107template <class I, class C>
108int foomain(I argc, C **argv) {
109 I e(4);
110 I g(5);
111 int i;
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000112 int &j = i;
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000113#pragma omp sections private // expected-error {{expected '(' after 'private'}}
114 {
115 foo();
116 }
117#pragma omp sections private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
118 {
119 foo();
120 }
121#pragma omp sections private() // expected-error {{expected expression}}
122 {
123 foo();
124 }
125#pragma omp sections private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
126 {
127 foo();
128 }
Alexey Bataevc5970622016-04-01 08:43:42 +0000129#pragma omp sections private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000130 {
131 foo();
132 }
133#pragma omp sections private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
134 {
135 foo();
136 }
137#pragma omp sections private(argc)
138 {
139 foo();
140 }
141#pragma omp sections private(S1) // expected-error {{'S1' does not refer to a value}}
142 {
143 foo();
144 }
145#pragma omp sections private(a, b) // expected-error {{private variable with incomplete type 'S1'}}
146 {
147 foo();
148 }
149#pragma omp sections private(argv[1]) // expected-error {{expected variable name}}
150 {
151 foo();
152 }
153#pragma omp sections private(e, g)
154 {
155 foo();
156 }
157#pragma omp sections private(h) // expected-error {{threadprivate or thread local variable cannot be private}}
158 {
159 foo();
160 }
161#pragma omp sections shared(i) // expected-error {{unexpected OpenMP clause 'shared' in directive '#pragma omp sections'}}
162 {
163 foo();
164 }
165#pragma omp parallel
166 {
167 int v = 0;
168 int i;
169#pragma omp sections private(i)
170 {
171 foo();
172 }
173 v += i;
174 }
175#pragma omp parallel shared(i)
176#pragma omp parallel private(i)
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000177#pragma omp sections private(j)
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000178 {
179 foo();
180 }
181#pragma omp sections private(i)
182 {
183 foo();
184 }
185 return 0;
186}
187
Alexey Bataev6ddfe1a2015-04-16 13:49:42 +0000188namespace A {
189double x;
190#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
191}
192namespace B {
193using A::x;
194}
195
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000196int main(int argc, char **argv) {
Alexey Bataev03b340a2014-10-21 03:16:40 +0000197 S4 e(4);
198 S5 g(5);
Alexey Bataev48c0bfb2016-01-20 09:07:54 +0000199 S6<float> s6(0.0) , s6_0(1.0);
200 S7<S6<float> > s7(0.0) , s7_0(1.0);
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000201 int i;
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000202 int &j = i;
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000203#pragma omp sections private // expected-error {{expected '(' after 'private'}}
204 {
205 foo();
206 }
207#pragma omp sections private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
208 {
209 foo();
210 }
211#pragma omp sections private() // expected-error {{expected expression}}
212 {
213 foo();
214 }
215#pragma omp sections private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
216 {
217 foo();
218 }
Alexey Bataevc5970622016-04-01 08:43:42 +0000219#pragma omp sections private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000220 {
221 foo();
222 }
223#pragma omp sections private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
224 {
225 foo();
226 }
227#pragma omp sections private(argc)
228 {
229 foo();
230 }
231#pragma omp sections private(S1) // expected-error {{'S1' does not refer to a value}}
232 {
233 foo();
234 }
235#pragma omp sections private(a, b) // expected-error {{private variable with incomplete type 'S1'}}
236 {
237 foo();
238 }
239#pragma omp sections private(argv[1]) // expected-error {{expected variable name}}
240 {
241 foo();
242 }
Alexey Bataev03b340a2014-10-21 03:16:40 +0000243#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 +0000244 {
245 foo();
246 }
Alexey Bataev6ddfe1a2015-04-16 13:49:42 +0000247#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 +0000248 {
249 foo();
250 }
251#pragma omp sections shared(i) // expected-error {{unexpected OpenMP clause 'shared' in directive '#pragma omp sections'}}
252 {
253 foo();
254 }
255#pragma omp parallel
256 {
257 int i;
258#pragma omp sections private(i)
259 {
260 foo();
261 }
262 }
263#pragma omp parallel shared(i)
264#pragma omp parallel private(i)
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000265#pragma omp sections private(j)
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000266 {
267 foo();
268 }
269#pragma omp sections private(i)
270 {
271 foo();
272 }
Kelvin Li4eea8c62015-09-15 18:56:58 +0000273 static int m;
274#pragma omp sections private(m)
275 {
276 foo();
277 }
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000278
Alexey Bataev48c0bfb2016-01-20 09:07:54 +0000279 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}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000282}
283