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