1 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=50 %s -Wuninitialized
2
3 // RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=50 %s -Wuninitialized
4
5 typedef void **omp_allocator_handle_t;
6 extern const omp_allocator_handle_t omp_null_allocator;
7 extern const omp_allocator_handle_t omp_default_mem_alloc;
8 extern const omp_allocator_handle_t omp_large_cap_mem_alloc;
9 extern const omp_allocator_handle_t omp_const_mem_alloc;
10 extern const omp_allocator_handle_t omp_high_bw_mem_alloc;
11 extern const omp_allocator_handle_t omp_low_lat_mem_alloc;
12 extern const omp_allocator_handle_t omp_cgroup_mem_alloc;
13 extern const omp_allocator_handle_t omp_pteam_mem_alloc;
14 extern const omp_allocator_handle_t omp_thread_mem_alloc;
15
xxx(int argc)16 void xxx(int argc) {
17 int i, lin, step; // expected-note {{initialize the variable 'lin' to silence this warning}} expected-note {{initialize the variable 'step' to silence this warning}}
18 #pragma omp target parallel for linear(lin : step) // expected-warning {{variable 'lin' is uninitialized when used here}} expected-warning {{variable 'step' is uninitialized when used here}}
19 for (i = 0; i < 10; ++i)
20 ;
21 }
22
23 namespace X {
24 int x;
25 };
26
27 struct B {
28 static int ib; // expected-note {{'B::ib' declared here}}
bfooB29 static int bfoo() { return 8; }
30 };
31
bfoo()32 int bfoo() { return 4; }
33
34 int z;
35 const int C1 = 1;
36 const int C2 = 2;
test_linear_colons()37 void test_linear_colons() {
38 int B = 0;
39 #pragma omp target parallel for linear(B : bfoo())
40 for (int i = 0; i < 10; ++i)
41 ;
42 // expected-error@+1 {{unexpected ':' in nested name specifier; did you mean '::'}}
43 #pragma omp target parallel for linear(B::ib : B : bfoo())
44 for (int i = 0; i < 10; ++i)
45 ;
46 // expected-error@+1 {{use of undeclared identifier 'ib'; did you mean 'B::ib'}}
47 #pragma omp target parallel for linear(B : ib)
48 for (int i = 0; i < 10; ++i)
49 ;
50 // expected-error@+1 {{unexpected ':' in nested name specifier; did you mean '::'?}}
51 #pragma omp target parallel for linear(z : B : ib)
52 for (int i = 0; i < 10; ++i)
53 ;
54 #pragma omp target parallel for linear(B : B::bfoo())
55 for (int i = 0; i < 10; ++i)
56 ;
57 #pragma omp target parallel for linear(X::x : ::z)
58 for (int i = 0; i < 10; ++i)
59 ;
60 #pragma omp target parallel for linear(B, ::z, X::x)
61 for (int i = 0; i < 10; ++i)
62 ;
63 #pragma omp target parallel for linear(::z)
64 for (int i = 0; i < 10; ++i)
65 ;
66 // expected-error@+1 {{expected variable name}}
67 #pragma omp target parallel for linear(B::bfoo())
68 for (int i = 0; i < 10; ++i)
69 ;
70 #pragma omp target parallel for linear(B::ib, B : C1 + C2)
71 for (int i = 0; i < 10; ++i)
72 ;
73 }
74
75 template <int L, class T, class N>
test_template(T * arr,N num)76 T test_template(T *arr, N num) {
77 N i;
78 T sum = (T)0;
79 T ind2 = -num * L; // expected-note {{'ind2' defined here}}
80 // expected-error@+1 {{argument of a linear clause should be of integral or pointer type}}
81 #pragma omp target parallel for linear(ind2 : L)
82 for (i = 0; i < num; ++i) {
83 T cur = arr[(int)ind2];
84 ind2 += L;
85 sum += cur;
86 }
87 return T();
88 }
89
90 template <int LEN>
test_warn()91 int test_warn() {
92 int ind2 = 0;
93 // expected-warning@+1 {{zero linear step (ind2 should probably be const)}}
94 #pragma omp target parallel for linear(ind2 : LEN)
95 for (int i = 0; i < 100; i++) {
96 ind2 += LEN;
97 }
98 return ind2;
99 }
100
101 struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
102 extern S1 a;
103 class S2 {
104 mutable int a;
105
106 public:
S2()107 S2() : a(0) {}
108 };
109 const S2 b; // expected-note 2 {{'b' defined here}}
110 const S2 ba[5];
111 class S3 {
112 int a;
113
114 public:
S3()115 S3() : a(0) {}
116 };
117 const S3 ca[5];
118 class S4 {
119 int a;
120 S4();
121
122 public:
S4(int v)123 S4(int v) : a(v) {}
124 };
125 class S5 {
126 int a;
S5()127 S5() : a(0) {}
128
129 public:
S5(int v)130 S5(int v) : a(v) {}
131 };
132
133 S3 h;
134 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
135
136 template <class I, class C>
foomain(I argc,C ** argv)137 int foomain(I argc, C **argv) {
138 I e(4);
139 I g(5);
140 int i, z;
141 int &j = i;
142 #pragma omp target parallel for linear // expected-error {{expected '(' after 'linear'}}
143 for (int k = 0; k < argc; ++k)
144 ++k;
145 #pragma omp target parallel for linear( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
146 for (int k = 0; k < argc; ++k)
147 ++k;
148 #pragma omp target parallel for linear() // expected-error {{expected expression}}
149 for (int k = 0; k < argc; ++k)
150 ++k;
151 #pragma omp target parallel for linear(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
152 for (int k = 0; k < argc; ++k)
153 ++k;
154 #pragma omp target parallel for linear(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
155 for (int k = 0; k < argc; ++k)
156 ++k;
157 #pragma omp target parallel for linear(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
158 for (int k = 0; k < argc; ++k)
159 ++k;
160 #pragma omp target parallel for linear(argc : 5) 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 '('}}
161 for (int k = 0; k < argc; ++k)
162 ++k;
163 #pragma omp target parallel for linear(S1) // expected-error {{'S1' does not refer to a value}}
164 for (int k = 0; k < argc; ++k)
165 ++k;
166 // expected-error@+2 {{linear variable with incomplete type 'S1'}}
167 // expected-error@+1 {{argument of a linear clause should be of integral or pointer type, not 'S2'}}
168 #pragma omp target parallel for linear(a, b : B::ib)
169 for (int k = 0; k < argc; ++k)
170 ++k;
171 #pragma omp target parallel for linear(argv[1]) // expected-error {{expected variable name}}
172 for (int k = 0; k < argc; ++k)
173 ++k;
174 #pragma omp target parallel for allocate(omp_thread_mem_alloc: e) linear(e, g) // expected-warning {{allocator with the 'thread' trait access has unspecified behavior on 'target parallel for' directive}} expected-error {{allocator must be specified in the 'uses_allocators' clause}}
175 for (int k = 0; k < argc; ++k)
176 ++k;
177 #pragma omp target parallel for linear(z, h) // expected-error {{threadprivate or thread local variable cannot be linear}}
178 for (int k = 0; k < argc; ++k)
179 ++k;
180 #pragma omp target parallel for linear(i)
181 for (int k = 0; k < argc; ++k)
182 ++k;
183 #pragma omp parallel
184 {
185 int v = 0;
186 int i;
187 #pragma omp target parallel for linear(v : i)
188 for (int k = 0; k < argc; ++k) {
189 i = k;
190 v += i;
191 }
192 }
193 #pragma omp target parallel for linear(j)
194 for (int k = 0; k < argc; ++k)
195 ++k;
196 int v = 0;
197 #pragma omp target parallel for linear(v : j)
198 for (int k = 0; k < argc; ++k) {
199 ++k;
200 v += j;
201 }
202 #pragma omp target parallel for linear(i)
203 for (int k = 0; k < argc; ++k)
204 ++k;
205 return 0;
206 }
207
208 namespace A {
209 double x;
210 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
211 }
212 namespace C {
213 using A::x;
214 }
215
main(int argc,char ** argv)216 int main(int argc, char **argv) {
217 double darr[100];
218 // expected-note@+1 {{in instantiation of function template specialization 'test_template<-4, double, int>' requested here}}
219 test_template<-4>(darr, 4);
220 // expected-note@+1 {{in instantiation of function template specialization 'test_warn<0>' requested here}}
221 test_warn<0>();
222
223 S4 e(4); // expected-note {{'e' defined here}}
224 S5 g(5); // expected-note {{'g' defined here}}
225 int i, z;
226 int &j = i;
227 #pragma omp target parallel for linear // expected-error {{expected '(' after 'linear'}}
228 for (int k = 0; k < argc; ++k)
229 ++k;
230 #pragma omp target parallel for linear( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
231 for (int k = 0; k < argc; ++k)
232 ++k;
233 #pragma omp target parallel for linear() // expected-error {{expected expression}}
234 for (int k = 0; k < argc; ++k)
235 ++k;
236 #pragma omp target parallel for linear(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
237 for (int k = 0; k < argc; ++k)
238 ++k;
239 #pragma omp target parallel for linear(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
240 for (int k = 0; k < argc; ++k)
241 ++k;
242 #pragma omp target parallel for linear(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
243 for (int k = 0; k < argc; ++k)
244 ++k;
245 #pragma omp target parallel for linear(argc, z)
246 for (int k = 0; k < argc; ++k)
247 ++k;
248 #pragma omp target parallel for linear(S1) // expected-error {{'S1' does not refer to a value}}
249 for (int k = 0; k < argc; ++k)
250 ++k;
251 // expected-error@+2 {{linear variable with incomplete type 'S1'}}
252 // expected-error@+1 {{argument of a linear clause should be of integral or pointer type, not 'S2'}}
253 #pragma omp target parallel for linear(a, b)
254 for (int k = 0; k < argc; ++k)
255 ++k;
256 #pragma omp target parallel for linear(argv[1]) // expected-error {{expected variable name}}
257 for (int k = 0; k < argc; ++k)
258 ++k;
259 // expected-error@+2 {{argument of a linear clause should be of integral or pointer type, not 'S4'}}
260 // expected-error@+1 {{argument of a linear clause should be of integral or pointer type, not 'S5'}}
261 #pragma omp target parallel for linear(e, g)
262 for (int k = 0; k < argc; ++k)
263 ++k;
264 #pragma omp target parallel for linear(h, C::x) // expected-error 2 {{threadprivate or thread local variable cannot be linear}}
265 for (int k = 0; k < argc; ++k)
266 ++k;
267 #pragma omp parallel
268 {
269 int i;
270 #pragma omp target parallel for linear(i)
271 for (int k = 0; k < argc; ++k)
272 ++k;
273 #pragma omp target parallel for linear(i : 4)
274 for (int k = 0; k < argc; ++k) {
275 ++k;
276 i += 4;
277 }
278 }
279 #pragma omp target parallel for linear(j)
280 for (int k = 0; k < argc; ++k)
281 ++k;
282 #pragma omp target parallel for linear(i)
283 for (int k = 0; k < argc; ++k)
284 ++k;
285
286 foomain<int, char>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}}
287 return 0;
288 }
289
290