blob: 3548590b0f4fc6983e1f676b49ffcd2788080e72 [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 Bataeve04483e2019-03-27 14:14:31 +00005extern int omp_default_mem_alloc;
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006void foo() {
7}
8
9bool foobool(int argc) {
10 return argc;
11}
12
13struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
14extern S1 a;
15class S2 {
16 mutable int a;
17
18public:
19 S2() : a(0) {}
20};
21const S2 b;
22const S2 ba[5];
23class S3 {
24 int a;
25
26public:
27 S3() : a(0) {}
28};
29const S3 ca[5];
Alexey Bataev03b340a2014-10-21 03:16:40 +000030class S4 {
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000031 int a;
Alexey Bataev03b340a2014-10-21 03:16:40 +000032 S4(); // expected-note {{implicitly declared private here}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000033
34public:
Alexey Bataev48c0bfb2016-01-20 09:07:54 +000035 S4(int v) : a(v) {
36#pragma omp sections private(a) private(this->a)
37 {
38 for (int k = 0; k < v; ++k)
39 ++this->a;
40 }
41 }
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000042};
Alexey Bataev03b340a2014-10-21 03:16:40 +000043class S5 {
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000044 int a;
Alexey Bataev03b340a2014-10-21 03:16:40 +000045 S5() : a(0) {} // expected-note {{implicitly declared private here}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000046
47public:
48 S5(int v) : a(v) {}
Alexey Bataev48c0bfb2016-01-20 09:07:54 +000049 S5 &operator=(S5 &s) {
50#pragma omp sections private(a) private(this->a) private(s.a) // expected-error {{expected variable name or data member of current class}}
51 {
52 for (int k = 0; k < s.a; ++k)
53 ++s.a;
54 }
55 return *this;
56 }
57};
58
59template <typename T>
60class S6 {
61public:
62 T a;
63
64 S6() : a(0) {}
65 S6(T v) : a(v) {
66#pragma omp sections private(a) private(this->a)
67 {
68 for (int k = 0; k < v; ++k)
69 ++this->a;
70 }
71 }
72 S6 &operator=(S6 &s) {
73#pragma omp sections private(a) private(this->a) private(s.a) // expected-error {{expected variable name or data member of current class}}
74 {
75 for (int k = 0; k < s.a; ++k)
76 ++s.a;
77 }
78 return *this;
79 }
80};
81
82template <typename T>
83class S7 : public T {
84 T a;
85 S7() : a(0) {}
86
87public:
88 S7(T v) : a(v) {
89#pragma omp sections private(a) private(this->a) private(T::a)
90 {
91 for (int k = 0; k < a.a; ++k)
92 ++this->a.a;
93 }
94 }
95 S7 &operator=(S7 &s) {
96#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}}
97 {
98 for (int k = 0; k < s.a.a; ++k)
99 ++s.a.a;
100 }
101 return *this;
102 }
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000103};
104
105S3 h;
106#pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
107
108template <class I, class C>
109int foomain(I argc, C **argv) {
110 I e(4);
111 I g(5);
112 int i;
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000113 int &j = i;
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000114#pragma omp sections private // expected-error {{expected '(' after 'private'}}
115 {
116 foo();
117 }
118#pragma omp sections private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
119 {
120 foo();
121 }
122#pragma omp sections private() // expected-error {{expected expression}}
123 {
124 foo();
125 }
126#pragma omp sections private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
127 {
128 foo();
129 }
Alexey Bataevc5970622016-04-01 08:43:42 +0000130#pragma omp sections private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000131 {
132 foo();
133 }
134#pragma omp sections private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
135 {
136 foo();
137 }
Alexey Bataeve04483e2019-03-27 14:14:31 +0000138#pragma omp sections private(argc) allocate , allocate(, allocate(omp_default , allocate(omp_default_mem_alloc, allocate(omp_default_mem_alloc:, allocate(omp_default_mem_alloc: argc, allocate(omp_default_mem_alloc: argv), allocate(argv) // expected-error {{expected '(' after 'allocate'}} expected-error 2 {{expected expression}} expected-error 2 {{expected ')'}} expected-error {{use of undeclared identifier 'omp_default'}} expected-note 2 {{to match this '('}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000139 {
140 foo();
141 }
142#pragma omp sections private(S1) // expected-error {{'S1' does not refer to a value}}
143 {
144 foo();
145 }
146#pragma omp sections private(a, b) // expected-error {{private variable with incomplete type 'S1'}}
147 {
148 foo();
149 }
150#pragma omp sections private(argv[1]) // expected-error {{expected variable name}}
151 {
152 foo();
153 }
154#pragma omp sections private(e, g)
155 {
156 foo();
157 }
158#pragma omp sections private(h) // expected-error {{threadprivate or thread local variable cannot be private}}
159 {
160 foo();
161 }
162#pragma omp sections shared(i) // expected-error {{unexpected OpenMP clause 'shared' in directive '#pragma omp sections'}}
163 {
164 foo();
165 }
166#pragma omp parallel
167 {
168 int v = 0;
169 int i;
170#pragma omp sections private(i)
171 {
172 foo();
173 }
174 v += i;
175 }
176#pragma omp parallel shared(i)
177#pragma omp parallel private(i)
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000178#pragma omp sections private(j)
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000179 {
180 foo();
181 }
182#pragma omp sections private(i)
183 {
184 foo();
185 }
186 return 0;
187}
188
Alexey Bataev6ddfe1a2015-04-16 13:49:42 +0000189namespace A {
190double x;
191#pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
192}
193namespace B {
194using A::x;
195}
196
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000197int main(int argc, char **argv) {
Alexey Bataev03b340a2014-10-21 03:16:40 +0000198 S4 e(4);
199 S5 g(5);
Alexey Bataev48c0bfb2016-01-20 09:07:54 +0000200 S6<float> s6(0.0) , s6_0(1.0);
201 S7<S6<float> > s7(0.0) , s7_0(1.0);
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000202 int i;
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000203 int &j = i;
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000204#pragma omp sections private // expected-error {{expected '(' after 'private'}}
205 {
206 foo();
207 }
208#pragma omp sections private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
209 {
210 foo();
211 }
212#pragma omp sections private() // expected-error {{expected expression}}
213 {
214 foo();
215 }
216#pragma omp sections private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
217 {
218 foo();
219 }
Alexey Bataevc5970622016-04-01 08:43:42 +0000220#pragma omp sections private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000221 {
222 foo();
223 }
224#pragma omp sections private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
225 {
226 foo();
227 }
228#pragma omp sections private(argc)
229 {
230 foo();
231 }
232#pragma omp sections private(S1) // expected-error {{'S1' does not refer to a value}}
233 {
234 foo();
235 }
236#pragma omp sections private(a, b) // expected-error {{private variable with incomplete type 'S1'}}
237 {
238 foo();
239 }
240#pragma omp sections private(argv[1]) // expected-error {{expected variable name}}
241 {
242 foo();
243 }
Alexey Bataev03b340a2014-10-21 03:16:40 +0000244#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 +0000245 {
246 foo();
247 }
Alexey Bataev6ddfe1a2015-04-16 13:49:42 +0000248#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 +0000249 {
250 foo();
251 }
252#pragma omp sections shared(i) // expected-error {{unexpected OpenMP clause 'shared' in directive '#pragma omp sections'}}
253 {
254 foo();
255 }
256#pragma omp parallel
257 {
258 int i;
259#pragma omp sections private(i)
260 {
261 foo();
262 }
263 }
264#pragma omp parallel shared(i)
265#pragma omp parallel private(i)
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000266#pragma omp sections private(j)
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000267 {
268 foo();
269 }
270#pragma omp sections private(i)
271 {
272 foo();
273 }
Kelvin Li4eea8c62015-09-15 18:56:58 +0000274 static int m;
275#pragma omp sections private(m)
276 {
277 foo();
278 }
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000279
Alexey Bataev48c0bfb2016-01-20 09:07:54 +0000280 s6 = s6_0; // expected-note {{in instantiation of member function 'S6<float>::operator=' requested here}}
281 s7 = s7_0; // expected-note {{in instantiation of member function 'S7<S6<float> >::operator=' requested here}}
282 return foomain(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000283}
284