Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / for_simd_firstprivate_messages.cpp
blob6dba2f81be3dd276806da70040375cb3b9a2c1ba
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) {}
20 S2(const S2 &s2) : a(s2.a) {}
21 static float S2s;
22 static const float S2sc;
24 const float S2::S2sc = 0;
25 const S2 b;
26 const S2 ba[5];
27 class S3 {
28 int a;
29 S3 &operator=(const S3 &s3);
31 public:
32 S3() : a(0) {}
33 S3(const S3 &s3) : a(s3.a) {}
35 const S3 c;
36 const S3 ca[5];
37 extern const int f;
38 class S4 {
39 int a;
40 S4();
41 S4(const S4 &s4); // expected-note 2 {{implicitly declared private here}}
43 public:
44 S4(int v) : a(v) {}
46 class S5 {
47 int a;
48 S5(const S5 &s5) : a(s5.a) {} // expected-note 4 {{implicitly declared private here}}
50 public:
51 S5() : a(0) {}
52 S5(int v) : a(v) {}
54 class S6 {
55 int a;
56 S6() : a(0) {}
58 public:
59 S6(const S6 &s6) : a(s6.a) {}
60 S6(int v) : a(v) {}
63 S3 h;
64 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
66 template <class I, class C>
67 int foomain(int argc, char **argv) {
68 I e(4);
69 C g(5);
70 int i;
71 int &j = i;
72 #pragma omp parallel
73 #pragma omp for simd firstprivate // expected-error {{expected '(' after 'firstprivate'}}
74 for (int k = 0; k < argc; ++k)
75 ++k;
76 #pragma omp parallel
77 #pragma omp for simd firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
78 for (int k = 0; k < argc; ++k)
79 ++k;
80 #pragma omp parallel
81 #pragma omp for simd firstprivate() // expected-error {{expected expression}}
82 for (int k = 0; k < argc; ++k)
83 ++k;
84 #pragma omp parallel
85 #pragma omp for simd firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
86 for (int k = 0; k < argc; ++k)
87 ++k;
88 #pragma omp parallel
89 #pragma omp for simd firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
90 for (int k = 0; k < argc; ++k)
91 ++k;
92 #pragma omp parallel
93 #pragma omp for simd firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
94 for (int k = 0; k < argc; ++k)
95 ++k;
96 #pragma omp parallel
97 #pragma omp for simd firstprivate(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 '('}}
98 for (int k = 0; k < argc; ++k)
99 ++k;
100 #pragma omp parallel
101 #pragma omp for simd firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
102 for (int k = 0; k < argc; ++k)
103 ++k;
104 #pragma omp parallel
105 #pragma omp for simd firstprivate(a, b) // expected-error {{a firstprivate variable with incomplete type 'S1'}}
106 for (int k = 0; k < argc; ++k)
107 ++k;
108 #pragma omp parallel
109 #pragma omp for simd firstprivate(argv[1]) // expected-error {{expected variable name}}
110 for (int k = 0; k < argc; ++k)
111 ++k;
112 #pragma omp parallel
113 #pragma omp for simd firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
114 for (int k = 0; k < argc; ++k)
115 ++k;
116 #pragma omp parallel
117 #pragma omp for simd firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
118 for (int k = 0; k < argc; ++k)
119 ++k;
120 #pragma omp parallel
121 #pragma omp for simd linear(i)
122 for (int k = 0; k < argc; ++k)
123 ++k;
124 #pragma omp parallel
126 int v = 0;
127 int i; // expected-note {{variable with automatic storage duration is predetermined as private; perhaps you forget to enclose 'omp for simd' directive into a parallel or another task region?}}
128 #pragma omp for simd firstprivate(i) // expected-error {{firstprivate variable must be shared}}
129 for (int k = 0; k < argc; ++k) {
130 i = k;
131 v += i;
134 #pragma omp parallel shared(i)
135 #pragma omp parallel private(i)
136 #pragma omp for simd firstprivate(j)
137 for (int k = 0; k < argc; ++k)
138 ++k;
139 #pragma omp parallel
140 #pragma omp for simd firstprivate(i)
141 for (int k = 0; k < argc; ++k)
142 ++k;
143 #pragma omp parallel
144 #pragma omp for simd lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
145 for (i = 0; i < argc; ++i)
146 foo();
147 #pragma omp parallel private(i) // expected-note {{defined as private}}
148 #pragma omp for simd firstprivate(i) // expected-error {{firstprivate variable must be shared}}
149 for (i = 0; i < argc; ++i)
150 foo();
151 #pragma omp parallel reduction(+ : i) // expected-note {{defined as reduction}}
152 #pragma omp for simd firstprivate(i) // expected-error {{firstprivate variable must be shared}}
153 for (int k = 0; k < argc; ++k)
154 foo();
155 return 0;
158 namespace A {
159 double x;
160 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
162 namespace B {
163 using A::x;
166 int main(int argc, char **argv) {
167 const int d = 5;
168 const int da[5] = {0};
169 S4 e(4);
170 S5 g(5);
171 S3 m;
172 S6 n(2);
173 int i;
174 int &j = i;
175 #pragma omp parallel
176 #pragma omp for simd firstprivate // expected-error {{expected '(' after 'firstprivate'}}
177 for (i = 0; i < argc; ++i)
178 foo();
179 #pragma omp parallel
180 #pragma omp for simd firstprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
181 for (i = 0; i < argc; ++i)
182 foo();
183 #pragma omp parallel
184 #pragma omp for simd firstprivate() // expected-error {{expected expression}}
185 for (i = 0; i < argc; ++i)
186 foo();
187 #pragma omp parallel
188 #pragma omp for simd firstprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
189 for (i = 0; i < argc; ++i)
190 foo();
191 #pragma omp parallel
192 #pragma omp for simd firstprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
193 for (i = 0; i < argc; ++i)
194 foo();
195 #pragma omp parallel
196 #pragma omp for simd firstprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
197 for (i = 0; i < argc; ++i)
198 foo();
199 #pragma omp parallel
200 #pragma omp for simd firstprivate(argc)
201 for (i = 0; i < argc; ++i)
202 foo();
203 #pragma omp parallel
204 #pragma omp for simd firstprivate(S1) // expected-error {{'S1' does not refer to a value}}
205 for (i = 0; i < argc; ++i)
206 foo();
207 #pragma omp parallel
208 #pragma omp for simd firstprivate(a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}}
209 for (i = 0; i < argc; ++i)
210 foo();
211 #pragma omp parallel
212 #pragma omp for simd firstprivate(argv[1]) // expected-error {{expected variable name}}
213 for (i = 0; i < argc; ++i)
214 foo();
215 #pragma omp parallel
216 #pragma omp for simd firstprivate(2 * 2) // expected-error {{expected variable name}}
217 for (i = 0; i < argc; ++i)
218 foo();
219 #pragma omp parallel
220 #pragma omp for simd firstprivate(ba) // OK
221 for (i = 0; i < argc; ++i)
222 foo();
223 #pragma omp parallel
224 #pragma omp for simd firstprivate(ca) // OK
225 for (i = 0; i < argc; ++i)
226 foo();
227 #pragma omp parallel
228 #pragma omp for simd firstprivate(da) // OK
229 for (i = 0; i < argc; ++i)
230 foo();
231 int xa;
232 #pragma omp parallel
233 #pragma omp for simd firstprivate(xa) // OK
234 for (i = 0; i < argc; ++i)
235 foo();
236 #pragma omp parallel
237 #pragma omp for simd firstprivate(S2::S2s) // OK
238 for (i = 0; i < argc; ++i)
239 foo();
240 #pragma omp parallel
241 #pragma omp for simd firstprivate(S2::S2sc) // OK
242 for (i = 0; i < argc; ++i)
243 foo();
244 #pragma omp parallel
245 #pragma omp for simd safelen(5)
246 for (i = 0; i < argc; ++i)
247 foo();
248 #pragma omp parallel
249 #pragma omp for simd firstprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
250 for (i = 0; i < argc; ++i)
251 foo();
252 #pragma omp parallel
253 #pragma omp for simd firstprivate(m) // OK
254 for (i = 0; i < argc; ++i)
255 foo();
256 #pragma omp parallel
257 #pragma omp for simd firstprivate(h) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
258 for (i = 0; i < argc; ++i)
259 foo();
260 #pragma omp parallel
261 #pragma omp for simd firstprivate(B::x) // expected-error {{threadprivate or thread local variable cannot be firstprivate}}
262 for (i = 0; i < argc; ++i)
263 foo();
264 #pragma omp parallel
265 #pragma omp for simd private(xa), firstprivate(xa) // expected-error {{private variable cannot be firstprivate}} expected-note {{defined as private}}
266 for (i = 0; i < argc; ++i)
267 foo();
268 #pragma omp parallel
269 #pragma omp for simd firstprivate(i) // expected-note {{defined as firstprivate}}
270 for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp for simd' directive may not be firstprivate, predetermined as linear}}
271 foo();
272 #pragma omp parallel shared(xa)
273 #pragma omp for simd firstprivate(xa) // OK: may be firstprivate
274 for (i = 0; i < argc; ++i)
275 foo();
276 #pragma omp parallel
277 #pragma omp for simd firstprivate(j)
278 for (i = 0; i < argc; ++i)
279 foo();
280 #pragma omp parallel
281 #pragma omp for simd lastprivate(g) firstprivate(g) // expected-error {{calling a private constructor of class 'S5'}}
282 for (i = 0; i < argc; ++i)
283 foo();
284 #pragma omp parallel
285 #pragma omp for simd lastprivate(n) firstprivate(n) // OK
286 for (i = 0; i < argc; ++i)
287 foo();
288 #pragma omp parallel
290 int v = 0;
291 int i; // expected-note {{variable with automatic storage duration is predetermined as private; perhaps you forget to enclose 'omp for simd' directive into a parallel or another task region?}}
292 #pragma omp for simd firstprivate(i) // expected-error {{firstprivate variable must be shared}}
293 for (int k = 0; k < argc; ++k) {
294 i = k;
295 v += i;
298 #pragma omp parallel private(i) // expected-note {{defined as private}}
299 #pragma omp for simd firstprivate(i) // expected-error {{firstprivate variable must be shared}}
300 for (i = 0; i < argc; ++i)
301 foo();
302 #pragma omp parallel reduction(+ : i) // expected-note {{defined as reduction}}
303 #pragma omp for simd firstprivate(i) // expected-error {{firstprivate variable must be shared}}
304 for (i = 0; i < argc; ++i)
305 foo();
306 static int si;
307 #pragma omp for simd firstprivate(si)
308 for (i = 0; i < argc; ++i)
309 si = i + 1;
311 return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}