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