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