[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / OpenMP / parallel_masked_private_messages.cpp
blobcb26cfee7ba1869346ff7588850ebe014877ca94
1 // RUN: %clang_cc1 -verify -fopenmp %s -Wuninitialized
3 // RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized
5 extern int omp_default_mem_alloc;
6 void foo() {
9 bool foobool(int argc) {
10 return argc;
13 struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
14 extern S1 a;
15 class S2 {
16 mutable int a;
18 public:
19 S2() : a(0) {}
21 const S2 b;
22 const S2 ba[5];
23 class S3 {
24 int a;
26 public:
27 S3() : a(0) {}
29 const S3 ca[5];
30 class S4 {
31 int a;
32 S4(); // expected-note {{implicitly declared private here}}
34 public:
35 S4(int v) : a(v) {
36 #pragma omp parallel masked private(a) private(this->a)
38 for (int k = 0; k < v; ++k)
39 ++this->a;
43 class S5 {
44 int a;
45 S5() : a(0) {} // expected-note {{implicitly declared private here}}
47 public:
48 S5(int v) : a(v) {}
49 S5 &operator=(S5 &s) {
50 #pragma omp parallel masked private(a) private(this->a) private(s.a) // expected-error {{expected variable name or data member of current class}}
52 for (int k = 0; k < s.a; ++k)
53 ++s.a;
55 return *this;
59 template <typename T>
60 class S6 {
61 public:
62 T a;
64 S6() : a(0) {}
65 S6(T v) : a(v) {
66 #pragma omp parallel masked private(a) private(this->a)
68 for (int k = 0; k < v; ++k)
69 ++this->a;
72 S6 &operator=(S6 &s) {
73 #pragma omp parallel masked private(a) private(this->a) private(s.a) // expected-error {{expected variable name or data member of current class}}
75 for (int k = 0; k < s.a; ++k)
76 ++s.a;
78 return *this;
82 template <typename T>
83 class S7 : public T {
84 T a;
85 S7() : a(0) {}
87 public:
88 S7(T v) : a(v) {
89 #pragma omp parallel masked private(a) private(this->a) private(T::a)
91 for (int k = 0; k < a.a; ++k)
92 ++this->a.a;
95 S7 &operator=(S7 &s) {
96 #pragma omp parallel masked private(a) private(this->a) private(s.a) private(s.T::a) // expected-error 2 {{expected variable name or data member of current class}}
98 for (int k = 0; k < s.a.a; ++k)
99 ++s.a.a;
101 return *this;
105 S3 h;
106 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
108 template <class I, class C>
109 int foomain(I argc, C **argv) {
110 I e(4);
111 I g(5);
112 int i, z;
113 int &j = i;
114 #pragma omp parallel masked private // expected-error {{expected '(' after 'private'}}
116 foo();
118 #pragma omp parallel masked private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
120 foo();
122 #pragma omp parallel masked private() // expected-error {{expected expression}}
124 foo();
126 #pragma omp parallel masked private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
128 foo();
130 #pragma omp parallel masked private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
132 foo();
134 #pragma omp parallel masked private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
136 foo();
138 #pragma omp parallel masked 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 '('}}
140 foo();
142 #pragma omp parallel masked private(S1) // expected-error {{'S1' does not refer to a value}}
144 foo();
146 #pragma omp parallel masked private(a, b) // expected-error {{private variable with incomplete type 'S1'}}
148 foo();
150 #pragma omp parallel masked private(argv[1]) // expected-error {{expected variable name}}
152 foo();
154 #pragma omp parallel masked private(e, g, z)
156 foo();
158 #pragma omp parallel masked private(h) // expected-error {{threadprivate or thread local variable cannot be private}}
160 foo();
162 #pragma omp parallel masked copyprivate(h) // expected-error {{unexpected OpenMP clause 'copyprivate' in directive '#pragma omp parallel masked'}}
164 foo();
166 #pragma omp parallel
168 int v = 0;
169 int i;
170 #pragma omp parallel masked private(i)
172 foo();
174 v += i;
176 #pragma omp parallel shared(i)
177 #pragma omp parallel private(i)
178 #pragma omp parallel masked private(j)
180 foo();
182 #pragma omp parallel masked private(i)
184 foo();
186 return 0;
189 namespace A {
190 double x;
191 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
193 namespace B {
194 using A::x;
197 int main(int argc, char **argv) {
198 S4 e(4);
199 S5 g(5);
200 S6<float> s6(0.0) , s6_0(1.0);
201 S7<S6<float> > s7(0.0) , s7_0(1.0);
202 int i, z;
203 int &j = i;
204 #pragma omp parallel masked private // expected-error {{expected '(' after 'private'}}
206 foo();
208 #pragma omp parallel masked private( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
210 foo();
212 #pragma omp parallel masked private() // expected-error {{expected expression}}
214 foo();
216 #pragma omp parallel masked private(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
218 foo();
220 #pragma omp parallel masked private(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
222 foo();
224 #pragma omp parallel masked private(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
226 foo();
228 #pragma omp parallel masked private(argc, z)
230 foo();
232 #pragma omp parallel masked private(S1) // expected-error {{'S1' does not refer to a value}}
234 foo();
236 #pragma omp parallel masked private(a, b) // expected-error {{private variable with incomplete type 'S1'}}
238 foo();
240 #pragma omp parallel masked private(argv[1]) // expected-error {{expected variable name}}
242 foo();
244 #pragma omp parallel masked private(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
246 foo();
248 #pragma omp parallel masked private(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be private}}
250 foo();
252 #pragma omp parallel masked copyprivate(h) // expected-error {{unexpected OpenMP clause 'copyprivate' in directive '#pragma omp parallel masked'}}
254 foo();
256 #pragma omp parallel
258 int i;
259 #pragma omp parallel masked private(i)
261 foo();
264 #pragma omp parallel shared(i)
265 #pragma omp parallel private(i)
266 #pragma omp parallel masked private(j)
268 foo();
270 #pragma omp parallel masked private(i)
272 foo();
274 static int m;
275 #pragma omp parallel masked private(m)
277 foo();
280 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}}