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 
foo()15 void foo() {
16 }
17 
foobool(int argc)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:
S2()28   S2() : a(0) {}
S2(S2 & s2)29   S2(S2 &s2) : a(s2.a) {}
30   const S2 &operator =(const S2&) const;
31   S2 &operator =(const S2&);
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 {{implicitly declared private here}}
41 
42 public:
S3()43   S3() : a(0) {}
S3(S3 & s3)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:
S4(int v)55   S4(int v) : a(v) {}
56 };
57 class S5 {
58   int a;
S5()59   S5() : a(0) {} // expected-note {{implicitly declared private here}}
60 
61 public:
S5(const S5 & s5)62   S5(const S5 &s5) : a(s5.a) {}
S5(int v)63   S5(int v) : a(v) {}
64 };
65 class S6 {
66   int a;
S6()67   S6() : a(0) {} // expected-note {{implicitly declared private here}}
68 
69 public:
S6(const S6 & s6)70   S6(const S6 &s6) : a(s6.a) {}
S6(int v)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>
foomain(int argc,char ** argv)78 int foomain(int argc, char **argv) {
79   I e(4);
80   I g(5);
81   int i;
82   int &j = i;
83 #pragma omp target teams distribute parallel for lastprivate // expected-error {{expected '(' after 'lastprivate'}}
84   for (int k = 0; k < argc; ++k) ++k;
85 
86 #pragma omp target teams distribute parallel for lastprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
87   for (int k = 0; k < argc; ++k) ++k;
88 
89 #pragma omp target teams distribute parallel for lastprivate() // expected-error {{expected expression}}
90   for (int k = 0; k < argc; ++k) ++k;
91 
92 #pragma omp target teams distribute parallel for lastprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
93   for (int k = 0; k < argc; ++k) ++k;
94 
95 #pragma omp target teams distribute parallel for lastprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
96   for (int k = 0; k < argc; ++k) ++k;
97 
98 #pragma omp target teams distribute parallel for lastprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
99   for (int k = 0; k < argc; ++k) ++k;
100 
101 #pragma omp target teams distribute parallel for 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 '('}}
102   for (int k = 0; k < argc; ++k) ++k;
103 
104 #pragma omp target teams distribute parallel for lastprivate(S1) // expected-error {{'S1' does not refer to a value}}
105   for (int k = 0; k < argc; ++k) ++k;
106 
107 #pragma omp target teams distribute parallel for lastprivate(a, b) // expected-error {{lastprivate variable with incomplete type 'S1'}}
108   for (int k = 0; k < argc; ++k) ++k;
109 
110 #pragma omp target teams distribute parallel for lastprivate(argv[1]) // expected-error {{expected variable name}}
111   for (int k = 0; k < argc; ++k) ++k;
112 
113 #pragma omp target teams distribute parallel for lastprivate(e, g) // expected-error 2 {{calling a private constructor of class 'S4'}}
114   for (int k = 0; k < argc; ++k) ++k;
115 
116 #pragma omp target teams distribute parallel for lastprivate(h) // expected-error {{threadprivate or thread local variable cannot be lastprivate}}
117   for (int k = 0; k < argc; ++k) ++k;
118 
119   int v = 0;
120 #pragma omp target teams distribute parallel for allocate(omp_thread_mem_alloc: i) lastprivate(i) // expected-warning {{allocator with the 'thread' trait access has unspecified behavior on 'target teams distribute parallel for' directive}}
121   for (int k = 0; k < argc; ++k) {
122     i = k;
123     v += i;
124   }
125 
126 #pragma omp target teams distribute parallel for lastprivate(j) private(i)
127   for (int k = 0; k < argc; ++k) ++k;
128 
129 #pragma omp target teams distribute parallel for lastprivate(i)
130   for (int k = 0; k < argc; ++k) ++k;
131 
132   return 0;
133 }
134 
bar(S4 a[2])135 void bar(S4 a[2]) {
136 #pragma omp target teams distribute parallel for lastprivate(a)
137   for (int i = 0; i < 2; ++i) foo();
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 
main(int argc,char ** argv)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;
156   int &j = i;
157   float k;
158 #pragma omp target teams distribute parallel for lastprivate // expected-error {{expected '(' after 'lastprivate'}}
159   for (i = 0; i < argc; ++i) foo();
160 
161 #pragma omp target teams distribute parallel for lastprivate( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
162   for (i = 0; i < argc; ++i) foo();
163 
164 #pragma omp target teams distribute parallel for lastprivate() // expected-error {{expected expression}}
165   for (i = 0; i < argc; ++i) foo();
166 
167 #pragma omp target teams distribute parallel for lastprivate(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
168   for (i = 0; i < argc; ++i) foo();
169 
170 #pragma omp target teams distribute parallel for lastprivate(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
171   for (i = 0; i < argc; ++i) foo();
172 
173 #pragma omp target teams distribute parallel for lastprivate(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
174   for (i = 0; i < argc; ++i) foo();
175 
176 #pragma omp target teams distribute parallel for lastprivate(argc)
177   for (i = 0; i < argc; ++i) foo();
178 
179 #pragma omp target teams distribute parallel for lastprivate(S1) // expected-error {{'S1' does not refer to a value}}
180   for (i = 0; i < argc; ++i) foo();
181 
182 #pragma omp target teams distribute parallel for 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}}
183   for (i = 0; i < argc; ++i) foo();
184 
185 #pragma omp target teams distribute parallel for lastprivate(argv[1]) // expected-error {{expected variable name}}
186   for (i = 0; i < argc; ++i) foo();
187 
188 #pragma omp target teams distribute parallel for lastprivate(2 * 2) // expected-error {{expected variable name}}
189   for (i = 0; i < argc; ++i) foo();
190 
191 #pragma omp target teams distribute parallel for lastprivate(ba)
192   for (i = 0; i < argc; ++i) foo();
193 
194 #pragma omp target teams distribute parallel for lastprivate(ca) // expected-error {{const-qualified variable without mutable fields cannot be lastprivate}}
195   for (i = 0; i < argc; ++i) foo();
196 
197 #pragma omp target teams distribute parallel for lastprivate(da) // expected-error {{const-qualified variable cannot be lastprivate}}
198   for (i = 0; i < argc; ++i) foo();
199 
200   int xa;
201 #pragma omp target teams distribute parallel for lastprivate(xa) // OK
202   for (i = 0; i < argc; ++i) foo();
203 
204 #pragma omp target teams distribute parallel for lastprivate(S2::S2s) // expected-error {{shared variable cannot be lastprivate}}
205   for (i = 0; i < argc; ++i) foo();
206 
207 #pragma omp target teams distribute parallel for lastprivate(S2::S2sc) // expected-error {{const-qualified variable cannot be lastprivate}}
208   for (i = 0; i < argc; ++i) foo();
209 
210 #pragma omp target teams distribute parallel for lastprivate(e, g) // expected-error {{calling a private constructor of class 'S4'}} expected-error {{calling a private constructor of class 'S5'}}
211   for (i = 0; i < argc; ++i) foo();
212 
213 #pragma omp target teams distribute parallel for lastprivate(m) // expected-error {{'operator=' is a private member of 'S3'}}
214   for (i = 0; i < argc; ++i) foo();
215 
216 #pragma omp target teams distribute parallel for lastprivate(h) // expected-error {{threadprivate or thread local variable cannot be lastprivate}}
217   for (i = 0; i < argc; ++i) foo();
218 
219 #pragma omp target teams distribute parallel for lastprivate(B::x) // expected-error {{threadprivate or thread local variable cannot be lastprivate}}
220   for (i = 0; i < argc; ++i) foo();
221 
222 #pragma omp target teams distribute parallel for private(xa), lastprivate(xa) // expected-error {{private variable cannot be lastprivate}} expected-note {{defined as private}}
223   for (i = 0; i < argc; ++i) foo();
224 
225 #pragma omp target teams distribute parallel for lastprivate(xa)
226   for (i = 0; i < argc; ++i) foo();
227 
228 #pragma omp target teams distribute parallel for lastprivate(j)
229   for (i = 0; i < argc; ++i) foo();
230 
231 // expected-error@+1 {{firstprivate variable cannot be lastprivate}} expected-note@+1 {{defined as firstprivate}}
232 #pragma omp target teams distribute parallel for firstprivate(m) lastprivate(m)
233   for (i = 0; i < argc; ++i) foo();
234 
235 // expected-error@+1 {{lastprivate variable cannot be firstprivate}} expected-note@+1 {{defined as lastprivate}}
236 #pragma omp target teams distribute parallel for lastprivate(n) firstprivate(n) // expected-error {{calling a private constructor of class 'S6'}}
237   for (i = 0; i < argc; ++i) foo();
238 
239   static int si;
240 #pragma omp target teams distribute parallel for lastprivate(si) // OK
241   for (i = 0; i < argc; ++i) si = i + 1;
242 
243 #pragma omp target teams distribute parallel for lastprivate(k) map(k) // expected-error {{lastprivate variable cannot be in a map clause in '#pragma omp target teams distribute parallel for' directive}} expected-note {{defined as lastprivate}}
244   for (i = 0; i < argc; ++i) foo();
245 
246   return foomain<S4, S5>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<S4, S5>' requested here}}
247 }
248