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