Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / sections_lastprivate_messages.cpp
blobc264a3db9fc058bcba52ee4c3dc9269a838425e6
1 // RUN: %clang_cc1 -verify=expected,omp45 -fopenmp-version=45 -fopenmp %s -Wuninitialized
2 // RUN: %clang_cc1 -verify=expected,omp51 -fopenmp %s -Wuninitialized
4 // RUN: %clang_cc1 -verify=expected,omp45 -fopenmp-version=45 -fopenmp-simd %s -Wuninitialized
5 // RUN: %clang_cc1 -verify=expected,omp51 -fopenmp-simd %s -Wuninitialized
7 extern int omp_default_mem_alloc;
8 void foo() {
11 bool foobool(int argc) {
12 return argc;
15 struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
16 extern S1 a;
17 class S2 {
18 mutable int a;
20 public:
21 S2() : a(0) {}
22 S2(S2 &s2) : a(s2.a) {}
23 const S2 &operator=(const S2 &) const;
24 static float S2s; // expected-note {{static data member is predetermined as shared}}
25 static const float S2sc; // expected-note {{'S2sc' declared here}}
27 const float S2::S2sc = 0;
28 const S2 b;
29 const S2 ba[5];
30 class S3 {
31 int a;
32 S3 &operator=(const S3 &s3); // expected-note 2 {{implicitly declared private here}}
34 public:
35 S3() : a(0) {}
36 S3(S3 &s3) : a(s3.a) {}
38 const S3 c; // expected-note {{'c' defined here}}
39 const S3 ca[5]; // expected-note {{'ca' defined here}}
40 extern const int f; // expected-note {{'f' declared here}}
41 class S4 {
42 int a;
43 S4(); // expected-note 3 {{implicitly declared private here}}
44 S4(const S4 &s4);
46 public:
47 S4(int v) : a(v) {}
49 class S5 {
50 int a;
51 S5() : a(0) {} // expected-note {{implicitly declared private here}}
53 public:
54 S5(const S5 &s5) : a(s5.a) {}
55 S5(int v) : a(v) {}
57 class S6 {
58 int a;
59 S6() : a(0) {} // omp45-note 2 {{implicitly declared private here}}
61 public:
62 S6(const S6 &s6) : a(s6.a) {}
63 S6(int v) : a(v) {}
66 S3 h;
67 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
69 template <class I, class C>
70 int foomain(int argc, char **argv) {
71 I e(4);
72 I g(5);
73 int i, k;
74 int &j = i;
75 S6 s(0); // omp51-note {{'s' defined here}}
76 #pragma omp parallel
77 #pragma omp sections lastprivate // expected-error {{expected '(' after 'lastprivate'}}
79 foo();
81 #pragma omp parallel
82 #pragma omp sections lastprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
84 foo();
86 #pragma omp parallel
87 #pragma omp sections lastprivate() // expected-error {{expected expression}}
89 foo();
91 #pragma omp parallel
92 #pragma omp sections lastprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
94 foo();
96 #pragma omp parallel
97 #pragma omp sections lastprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
99 foo();
101 #pragma omp parallel
102 #pragma omp sections lastprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
104 foo();
106 #pragma omp parallel
107 #pragma omp sections lastprivate(argc)
109 foo();
111 #pragma omp parallel
112 #pragma omp sections lastprivate(conditional: argc,s) lastprivate(conditional: // omp51-error {{expected expression}} omp45-error 2 {{use of undeclared identifier 'conditional'}} expected-error {{expected ')'}} expected-note {{to match this '('}} omp45-error 2 {{calling a private constructor of class 'S6'}} omp51-error {{expected list item of scalar type in 'lastprivate' clause with 'conditional' modifier}}}
114 foo();
116 #pragma omp parallel
117 #pragma omp sections lastprivate(foo:argc) // omp51-error {{expected 'conditional' in OpenMP clause 'lastprivate'}} omp45-error {{expected ',' or ')' in 'lastprivate' clause}} omp45-error {{expected ')'}} omp45-error {{expected variable name}} omp45-note {{to match this '('}}
119 foo();
121 #pragma omp parallel
122 #pragma omp sections lastprivate(S1) // expected-error {{'S1' does not refer to a value}}
124 foo();
126 #pragma omp parallel
127 #pragma omp sections lastprivate(a, b, k) // expected-error {{lastprivate variable with incomplete type 'S1'}}
129 foo();
131 #pragma omp parallel
132 #pragma omp sections lastprivate(argv[1]) // expected-error {{expected variable name}}
134 foo();
136 #pragma omp parallel
137 #pragma omp sections lastprivate(e, g) // expected-error 2 {{calling a private constructor of class 'S4'}}
139 foo();
141 #pragma omp parallel
142 #pragma omp sections lastprivate(h) // expected-error {{threadprivate or thread local variable cannot be lastprivate}}
144 foo();
146 #pragma omp parallel
147 #pragma omp sections linear(i) // expected-error {{unexpected OpenMP clause 'linear' in directive '#pragma omp sections'}}
149 foo();
151 #pragma omp parallel
153 int v = 0;
154 int i; // expected-note {{variable with automatic storage duration is predetermined as private; perhaps you forget to enclose 'omp sections' directive into a parallel or another task region?}}
155 #pragma omp sections lastprivate(i) // expected-error {{lastprivate variable must be shared}}
157 foo();
159 v += i;
161 #pragma omp parallel shared(i)
162 #pragma omp parallel private(i)
163 #pragma omp sections lastprivate(j)
165 foo();
167 #pragma omp parallel
168 #pragma omp sections lastprivate(i)
170 foo();
172 return 0;
175 namespace A {
176 double x;
177 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
179 namespace B {
180 using A::x;
183 int main(int argc, char **argv) {
184 const int d = 5; // expected-note {{'d' defined here}}
185 const int da[5] = {0}; // expected-note {{'da' defined here}}
186 S4 e(4);
187 S5 g(5);
188 S3 m;
189 S6 n(2);
190 int i, k;
191 int &j = i;
192 #pragma omp parallel
193 #pragma omp sections lastprivate // expected-error {{expected '(' after 'lastprivate'}}
195 foo();
197 #pragma omp parallel
198 #pragma omp sections lastprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
200 foo();
202 #pragma omp parallel
203 #pragma omp sections lastprivate() // expected-error {{expected expression}}
205 foo();
207 #pragma omp parallel
208 #pragma omp sections lastprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
210 foo();
212 #pragma omp parallel
213 #pragma omp sections lastprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
215 foo();
217 #pragma omp parallel
218 #pragma omp sections lastprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
220 foo();
222 #pragma omp parallel
223 #pragma omp sections lastprivate(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 '('}}
225 foo();
227 #pragma omp parallel
228 #pragma omp sections lastprivate(S1) // expected-error {{'S1' does not refer to a value}}
230 foo();
232 #pragma omp parallel
233 #pragma omp sections lastprivate(a, b, c, d, f) // expected-error {{lastprivate variable with incomplete type 'S1'}} expected-error 1 {{const-qualified variable without mutable fields cannot be lastprivate}} expected-error 2 {{const-qualified variable cannot be lastprivate}}
235 foo();
237 #pragma omp parallel
238 #pragma omp sections lastprivate(argv[1]) // expected-error {{expected variable name}}
240 foo();
242 #pragma omp parallel
243 #pragma omp sections lastprivate(2 * 2) // expected-error {{expected variable name}}
245 foo();
247 #pragma omp parallel
248 #pragma omp sections lastprivate(ba, k)
250 foo();
252 #pragma omp parallel
253 #pragma omp sections lastprivate(ca) // expected-error {{const-qualified variable without mutable fields cannot be lastprivate}}
255 foo();
257 #pragma omp parallel
258 #pragma omp sections lastprivate(da) // expected-error {{const-qualified variable cannot be lastprivate}}
260 foo();
262 int xa;
263 #pragma omp parallel
264 #pragma omp sections lastprivate(xa) // OK
266 foo();
268 #pragma omp parallel
269 #pragma omp sections lastprivate(S2::S2s) // expected-error {{shared variable cannot be lastprivate}}
271 foo();
273 #pragma omp parallel
274 #pragma omp sections lastprivate(S2::S2sc) // expected-error {{const-qualified variable cannot be lastprivate}}
276 foo();
278 #pragma omp parallel
279 #pragma omp sections safelen(5) // expected-error {{unexpected OpenMP clause 'safelen' in directive '#pragma omp sections'}}
281 foo();
283 #pragma omp parallel
284 #pragma omp sections lastprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
286 foo();
288 #pragma omp parallel
289 #pragma omp sections lastprivate(m) // expected-error {{'operator=' is a private member of 'S3'}}
291 foo();
293 #pragma omp parallel
294 #pragma omp sections lastprivate(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be lastprivate}}
296 foo();
298 #pragma omp parallel
299 #pragma omp sections private(xa), lastprivate(xa) // expected-error {{private variable cannot be lastprivate}} expected-note {{defined as private}}
301 foo();
303 #pragma omp parallel
304 #pragma omp sections lastprivate(i)
306 foo();
308 #pragma omp parallel private(xa) // expected-note {{defined as private}}
309 #pragma omp sections lastprivate(xa) // expected-error {{lastprivate variable must be shared}}
311 foo();
313 #pragma omp parallel reduction(+ : xa) // expected-note {{defined as reduction}}
314 #pragma omp sections lastprivate(xa) // expected-error {{lastprivate variable must be shared}}
316 foo();
318 #pragma omp parallel
319 #pragma omp sections lastprivate(j)
321 foo();
323 #pragma omp parallel
324 #pragma omp sections firstprivate(m) lastprivate(m) // expected-error {{'operator=' is a private member of 'S3'}}
326 foo();
328 #pragma omp parallel
329 #pragma omp sections lastprivate(n) firstprivate(n) // OK
331 foo();
333 static int r;
334 #pragma omp sections lastprivate(r) // OK
336 foo();
338 return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}