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