1 // RUN: %clang_cc1 -verify -fopenmp %s -Wuninitialized
2 
3 // RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized
4 
5 extern int omp_default_mem_alloc;
6 void foo() {
7 }
8 
9 bool foobool(int argc) {
10   return argc;
11 }
12 
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;
17 
18 public:
19   S2() : a(0) {}
20   S2(S2 &s2) : a(s2.a) {}
21   S2 &operator =(const S2&);
22   const S2 &operator =(const S2&) const;
23   static float S2s; // expected-note {{static data member is predetermined as shared}}
24   static const float S2sc; // expected-note {{'S2sc' declared here}}
25 };
26 const float S2::S2sc = 0;
27 const S2 b;
28 const S2 ba[5];
29 class S3 {
30   int a;
31   S3 &operator=(const S3 &s3); // expected-note 2 {{implicitly declared private here}}
32 
33 public:
34   S3() : a(0) {}
35   S3(S3 &s3) : a(s3.a) {}
36 };
37 const S3 c;         // expected-note {{'c' defined here}}
38 const S3 ca[5];     // expected-note {{'ca' defined here}}
39 extern const int f; // expected-note {{'f' declared here}}
40 class S4 {
41   int a;
42   S4();             // expected-note 3 {{implicitly declared private here}}
43   S4(const S4 &s4);
44 
45 public:
46   S4(int v) : a(v) {}
47 };
48 class S5 {
49   int a;
50   S5() : a(0) {} // expected-note {{implicitly declared private here}}
51 
52 public:
53   S5(const S5 &s5) : a(s5.a) {}
54   S5(int v) : a(v) {}
55 };
56 class S6 {
57   int a;
58   S6() : a(0) {}
59 
60 public:
61   S6(const S6 &s6) : a(s6.a) {}
62   S6(int v) : a(v) {}
63 };
64 
65 S3 h;
66 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
67 
68 template <class I, class C>
69 int foomain(int argc, char **argv) {
70   I e(4);
71   I g(5);
72   int i, z;
73   int &j = i;
74 #pragma omp parallel
75 #pragma omp for simd lastprivate // expected-error {{expected '(' after 'lastprivate'}}
76   for (int k = 0; k < argc; ++k)
77     ++k;
78 #pragma omp parallel
79 #pragma omp for simd lastprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
80   for (int k = 0; k < argc; ++k)
81     ++k;
82 #pragma omp parallel
83 #pragma omp for simd lastprivate() // expected-error {{expected expression}}
84   for (int k = 0; k < argc; ++k)
85     ++k;
86 #pragma omp parallel
87 #pragma omp for simd lastprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
88   for (int k = 0; k < argc; ++k)
89     ++k;
90 #pragma omp parallel
91 #pragma omp for simd lastprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
92   for (int k = 0; k < argc; ++k)
93     ++k;
94 #pragma omp parallel
95 #pragma omp for simd lastprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
96   for (int k = 0; k < argc; ++k)
97     ++k;
98 #pragma omp parallel
99 #pragma omp for simd 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 '('}}
100   for (int k = 0; k < argc; ++k)
101     ++k;
102 #pragma omp parallel
103 #pragma omp for simd lastprivate(S1) // expected-error {{'S1' does not refer to a value}}
104   for (int k = 0; k < argc; ++k)
105     ++k;
106 #pragma omp parallel
107 #pragma omp for simd lastprivate(z, a, b) // expected-error {{lastprivate variable with incomplete type 'S1'}}
108   for (int k = 0; k < argc; ++k)
109     ++k;
110 #pragma omp parallel
111 #pragma omp for simd lastprivate(argv[1]) // expected-error {{expected variable name}}
112   for (int k = 0; k < argc; ++k)
113     ++k;
114 #pragma omp parallel
115 #pragma omp for simd lastprivate(e, g) // expected-error 2 {{calling a private constructor of class 'S4'}}
116   for (int k = 0; k < argc; ++k)
117     ++k;
118 #pragma omp parallel
119 #pragma omp for simd lastprivate(h) // expected-error {{threadprivate or thread local variable cannot be lastprivate}}
120   for (int k = 0; k < argc; ++k)
121     ++k;
122 #pragma omp parallel
123 #pragma omp for simd
124   for (int k = 0; k < argc; ++k)
125     ++k;
126 #pragma omp parallel
127   {
128     int v = 0;
129     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?}}
130 #pragma omp for simd lastprivate(i) // expected-error {{lastprivate variable must be shared}}
131     for (int k = 0; k < argc; ++k) {
132       i = k;
133       v += i;
134     }
135   }
136 #pragma omp parallel shared(i)
137 #pragma omp parallel private(i)
138 #pragma omp for simd lastprivate(j)
139   for (int k = 0; k < argc; ++k)
140     ++k;
141 #pragma omp parallel
142 #pragma omp for simd lastprivate(i)
143   for (int k = 0; k < argc; ++k)
144     ++k;
145   return 0;
146 }
147 
148 namespace A {
149 double x;
150 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
151 }
152 namespace B {
153 using A::x;
154 }
155 
156 int main(int argc, char **argv) {
157   const int d = 5;       // expected-note {{'d' defined here}}
158   const int da[5] = {0}; // expected-note {{'da' defined here}}
159   S4 e(4);
160   S5 g(5);
161   S3 m;
162   S6 n(2);
163   int i, z;
164   int &j = i;
165 #pragma omp parallel
166 #pragma omp for simd lastprivate // expected-error {{expected '(' after 'lastprivate'}}
167   for (i = 0; i < argc; ++i)
168     foo();
169 #pragma omp parallel
170 #pragma omp for simd lastprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
171   for (i = 0; i < argc; ++i)
172     foo();
173 #pragma omp parallel
174 #pragma omp for simd lastprivate() // expected-error {{expected expression}}
175   for (i = 0; i < argc; ++i)
176     foo();
177 #pragma omp parallel
178 #pragma omp for simd lastprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
179   for (i = 0; i < argc; ++i)
180     foo();
181 #pragma omp parallel
182 #pragma omp for simd lastprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
183   for (i = 0; i < argc; ++i)
184     foo();
185 #pragma omp parallel
186 #pragma omp for simd lastprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
187   for (i = 0; i < argc; ++i)
188     foo();
189 #pragma omp parallel
190 #pragma omp for simd lastprivate(argc, z)
191   for (i = 0; i < argc; ++i)
192     foo();
193 #pragma omp parallel
194 #pragma omp for simd lastprivate(S1) // expected-error {{'S1' does not refer to a value}}
195   for (i = 0; i < argc; ++i)
196     foo();
197 #pragma omp parallel
198 #pragma omp for simd 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}}
199   for (i = 0; i < argc; ++i)
200     foo();
201 #pragma omp parallel
202 #pragma omp for simd lastprivate(argv[1]) // expected-error {{expected variable name}}
203   for (i = 0; i < argc; ++i)
204     foo();
205 #pragma omp parallel
206 #pragma omp for simd lastprivate(2 * 2) // expected-error {{expected variable name}}
207   for (i = 0; i < argc; ++i)
208     foo();
209 #pragma omp parallel
210 #pragma omp for simd lastprivate(ba)
211   for (i = 0; i < argc; ++i)
212     foo();
213 #pragma omp parallel
214 #pragma omp for simd lastprivate(ca) // expected-error {{const-qualified variable without mutable fields cannot be lastprivate}}
215   for (i = 0; i < argc; ++i)
216     foo();
217 #pragma omp parallel
218 #pragma omp for simd lastprivate(da) // expected-error {{const-qualified variable cannot be lastprivate}}
219   for (i = 0; i < argc; ++i)
220     foo();
221   int xa;
222 #pragma omp parallel
223 #pragma omp for simd lastprivate(xa) // OK
224   for (i = 0; i < argc; ++i)
225     foo();
226 #pragma omp parallel
227 #pragma omp for simd lastprivate(S2::S2s) // expected-error {{shared variable cannot be lastprivate}}
228   for (i = 0; i < argc; ++i)
229     foo();
230 #pragma omp parallel
231 #pragma omp for simd lastprivate(S2::S2sc) // expected-error {{const-qualified variable cannot be lastprivate}}
232   for (i = 0; i < argc; ++i)
233     foo();
234 #pragma omp parallel
235 #pragma omp for simd
236   for (i = 0; i < argc; ++i)
237     foo();
238 #pragma omp parallel
239 #pragma omp for simd lastprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
240   for (i = 0; i < argc; ++i)
241     foo();
242 #pragma omp parallel
243 #pragma omp for simd lastprivate(m) // expected-error {{'operator=' is a private member of 'S3'}}
244   for (i = 0; i < argc; ++i)
245     foo();
246 #pragma omp parallel
247 #pragma omp for simd lastprivate(h, B::x) // expected-error 2 {{threadprivate or thread local variable cannot be lastprivate}}
248   for (i = 0; i < argc; ++i)
249     foo();
250 #pragma omp parallel
251 #pragma omp for simd private(xa), lastprivate(xa) // expected-error {{private variable cannot be lastprivate}} expected-note {{defined as private}}
252   for (i = 0; i < argc; ++i)
253     foo();
254 #pragma omp parallel
255 #pragma omp for simd lastprivate(i) // expected-note {{defined as lastprivate}}
256   for (i = 0; i < argc; ++i) // expected-error {{loop iteration variable in the associated loop of 'omp for simd' directive may not be lastprivate, predetermined as linear}}
257     foo();
258 #pragma omp parallel private(xa) // expected-note {{defined as private}}
259 #pragma omp for simd lastprivate(xa)  // expected-error {{lastprivate variable must be shared}}
260   for (i = 0; i < argc; ++i)
261     foo();
262 #pragma omp parallel reduction(+ : xa) // expected-note {{defined as reduction}}
263 #pragma omp for simd lastprivate(xa)        // expected-error {{lastprivate variable must be shared}}
264   for (i = 0; i < argc; ++i)
265     foo();
266 #pragma omp parallel
267 #pragma omp for simd lastprivate(j)
268   for (i = 0; i < argc; ++i)
269     foo();
270 #pragma omp parallel
271 #pragma omp for simd firstprivate(m) lastprivate(m) // expected-error {{'operator=' is a private member of 'S3'}}
272   for (i = 0; i < argc; ++i)
273     foo();
274 #pragma omp parallel
275 #pragma omp for simd lastprivate(n) firstprivate(n) // OK
276   for (i = 0; i < argc; ++i)
277     foo();
278   static int si;
279 #pragma omp for simd lastprivate(si) // OK
280   for (i = 0; i < argc; ++i)
281     si = i + 1;
282   return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}
283 }
284