1*b8552abfSAlexey Bataev // RUN: %clang_cc1 -x c++ -std=c++11 -verify -fopenmp %s -Wuninitialized
2*b8552abfSAlexey Bataev 
3*b8552abfSAlexey Bataev // RUN: %clang_cc1 -x c++ -std=c++11 -verify -fopenmp-simd %s -Wuninitialized
4*b8552abfSAlexey Bataev 
5*b8552abfSAlexey Bataev struct B {
6*b8552abfSAlexey Bataev   static int ib[20]; // expected-note 0 {{'B::ib' declared here}}
7*b8552abfSAlexey Bataev   static constexpr int bfoo() { return 8; }
8*b8552abfSAlexey Bataev };
9*b8552abfSAlexey Bataev namespace X {
10*b8552abfSAlexey Bataev   B x; // expected-note {{'x' defined here}}
11*b8552abfSAlexey Bataev };
12*b8552abfSAlexey Bataev constexpr int bfoo() { return 4; }
13*b8552abfSAlexey Bataev 
14*b8552abfSAlexey Bataev int **z;
15*b8552abfSAlexey Bataev const int C1 = 1;
16*b8552abfSAlexey Bataev const int C2 = 2;
17*b8552abfSAlexey Bataev void test_aligned_colons(int *&rp)
18*b8552abfSAlexey Bataev {
19*b8552abfSAlexey Bataev   int *B = 0;
20*b8552abfSAlexey Bataev   #pragma omp master taskloop simd aligned(B:bfoo())
21*b8552abfSAlexey Bataev   for (int i = 0; i < 10; ++i) ;
22*b8552abfSAlexey Bataev   // expected-error@+1 {{unexpected ':' in nested name specifier; did you mean '::'}}
23*b8552abfSAlexey Bataev   #pragma omp master taskloop simd aligned(B::ib:B:bfoo())
24*b8552abfSAlexey Bataev   for (int i = 0; i < 10; ++i) ;
25*b8552abfSAlexey Bataev   #pragma omp master taskloop simd aligned(B:B::bfoo())
26*b8552abfSAlexey Bataev   for (int i = 0; i < 10; ++i) ;
27*b8552abfSAlexey Bataev   // expected-error@+1 {{unexpected ':' in nested name specifier; did you mean '::'?}}
28*b8552abfSAlexey Bataev   #pragma omp master taskloop simd aligned(z:B:bfoo())
29*b8552abfSAlexey Bataev   for (int i = 0; i < 10; ++i) ;
30*b8552abfSAlexey Bataev   #pragma omp master taskloop simd aligned(B:B::bfoo())
31*b8552abfSAlexey Bataev   for (int i = 0; i < 10; ++i) ;
32*b8552abfSAlexey Bataev   // expected-error@+2 {{integral constant expression must have integral or unscoped enumeration type, not 'int **'}}
33*b8552abfSAlexey Bataev   // expected-error@+1 {{argument of aligned clause should be array, pointer, reference to array or reference to pointer, not 'B'}}
34*b8552abfSAlexey Bataev   #pragma omp master taskloop simd aligned(X::x : ::z)
35*b8552abfSAlexey Bataev   for (int i = 0; i < 10; ++i) ;
36*b8552abfSAlexey Bataev   // expected-error@+1 {{integral constant expression must have integral or unscoped enumeration type, not 'B'}}
37*b8552abfSAlexey Bataev   #pragma omp master taskloop simd aligned(B,rp,::z: X::x)
38*b8552abfSAlexey Bataev   for (int i = 0; i < 10; ++i) ;
39*b8552abfSAlexey Bataev   #pragma omp master taskloop simd aligned(::z)
40*b8552abfSAlexey Bataev   for (int i = 0; i < 10; ++i) ;
41*b8552abfSAlexey Bataev   // expected-error@+1 {{expected variable name}}
42*b8552abfSAlexey Bataev   #pragma omp master taskloop simd aligned(B::bfoo())
43*b8552abfSAlexey Bataev   for (int i = 0; i < 10; ++i) ;
44*b8552abfSAlexey Bataev   // expected-warning@+1 {{aligned clause will be ignored because the requested alignment is not a power of 2}}
45*b8552abfSAlexey Bataev   #pragma omp master taskloop simd aligned(B::ib,B:C1+C2)
46*b8552abfSAlexey Bataev   for (int i = 0; i < 10; ++i) ;
47*b8552abfSAlexey Bataev }
48*b8552abfSAlexey Bataev 
49*b8552abfSAlexey Bataev // expected-note@+1 {{'num' defined here}}
50*b8552abfSAlexey Bataev template<int L, class T, class N> T test_template(T* arr, N num) {
51*b8552abfSAlexey Bataev   N i;
52*b8552abfSAlexey Bataev   T sum = (T)0;
53*b8552abfSAlexey Bataev   T ind2 = - num * L;
54*b8552abfSAlexey Bataev   // Negative number is passed as L.
55*b8552abfSAlexey Bataev   // expected-error@+1 {{argument to 'aligned' clause must be a strictly positive integer value}}
56*b8552abfSAlexey Bataev   #pragma omp master taskloop simd aligned(arr:L)
57*b8552abfSAlexey Bataev   for (i = 0; i < num; ++i) {
58*b8552abfSAlexey Bataev     T cur = arr[(int)ind2];
59*b8552abfSAlexey Bataev     ind2 += L;
60*b8552abfSAlexey Bataev     sum += cur;
61*b8552abfSAlexey Bataev   }
62*b8552abfSAlexey Bataev   // expected-error@+1 {{argument of aligned clause should be array, pointer, reference to array or reference to pointer, not 'int'}}
63*b8552abfSAlexey Bataev   #pragma omp master taskloop simd aligned(num:4)
64*b8552abfSAlexey Bataev   for (i = 0; i < num; ++i);
65*b8552abfSAlexey Bataev   return T();
66*b8552abfSAlexey Bataev }
67*b8552abfSAlexey Bataev 
68*b8552abfSAlexey Bataev template<int LEN> int test_warn() {
69*b8552abfSAlexey Bataev   int *ind2 = 0;
70*b8552abfSAlexey Bataev   // expected-error@+1 {{argument to 'aligned' clause must be a strictly positive integer value}}
71*b8552abfSAlexey Bataev   #pragma omp master taskloop simd aligned(ind2:LEN)
72*b8552abfSAlexey Bataev   for (int i = 0; i < 100; i++) {
73*b8552abfSAlexey Bataev     ind2 += LEN;
74*b8552abfSAlexey Bataev   }
75*b8552abfSAlexey Bataev   return 0;
76*b8552abfSAlexey Bataev }
77*b8552abfSAlexey Bataev 
78*b8552abfSAlexey Bataev struct S1; // expected-note 2 {{declared here}}
79*b8552abfSAlexey Bataev extern S1 a; // expected-note {{'a' declared here}}
80*b8552abfSAlexey Bataev class S2 {
81*b8552abfSAlexey Bataev   mutable int a;
82*b8552abfSAlexey Bataev public:
83*b8552abfSAlexey Bataev   S2():a(0) { }
84*b8552abfSAlexey Bataev };
85*b8552abfSAlexey Bataev const S2 b; // expected-note 1 {{'b' defined here}}
86*b8552abfSAlexey Bataev const S2 ba[5];
87*b8552abfSAlexey Bataev class S3 {
88*b8552abfSAlexey Bataev   int a;
89*b8552abfSAlexey Bataev public:
90*b8552abfSAlexey Bataev   S3():a(0) { }
91*b8552abfSAlexey Bataev };
92*b8552abfSAlexey Bataev const S3 ca[5];
93*b8552abfSAlexey Bataev class S4 {
94*b8552abfSAlexey Bataev   int a;
95*b8552abfSAlexey Bataev   S4();
96*b8552abfSAlexey Bataev public:
97*b8552abfSAlexey Bataev   S4(int v):a(v) { }
98*b8552abfSAlexey Bataev };
99*b8552abfSAlexey Bataev class S5 {
100*b8552abfSAlexey Bataev   int a;
101*b8552abfSAlexey Bataev   S5():a(0) {}
102*b8552abfSAlexey Bataev public:
103*b8552abfSAlexey Bataev   S5(int v):a(v) { }
104*b8552abfSAlexey Bataev };
105*b8552abfSAlexey Bataev 
106*b8552abfSAlexey Bataev S3 h; // expected-note 2 {{'h' defined here}}
107*b8552abfSAlexey Bataev #pragma omp threadprivate(h)
108*b8552abfSAlexey Bataev 
109*b8552abfSAlexey Bataev template<class I, class C> int foomain(I argc, C **argv) {
110*b8552abfSAlexey Bataev   I e(argc);
111*b8552abfSAlexey Bataev   I g(argc);
112*b8552abfSAlexey Bataev   int i; // expected-note {{'i' defined here}}
113*b8552abfSAlexey Bataev   // expected-note@+1 {{declared here}}
114*b8552abfSAlexey Bataev   int &j = i;
115*b8552abfSAlexey Bataev   #pragma omp master taskloop simd aligned // expected-error {{expected '(' after 'aligned'}}
116*b8552abfSAlexey Bataev   for (I k = 0; k < argc; ++k) ++k;
117*b8552abfSAlexey Bataev   #pragma omp master taskloop simd aligned ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
118*b8552abfSAlexey Bataev   for (I k = 0; k < argc; ++k) ++k;
119*b8552abfSAlexey Bataev   #pragma omp master taskloop simd aligned () // expected-error {{expected expression}}
120*b8552abfSAlexey Bataev   for (I k = 0; k < argc; ++k) ++k;
121*b8552abfSAlexey Bataev   #pragma omp master taskloop simd aligned (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
122*b8552abfSAlexey Bataev   for (I k = 0; k < argc; ++k) ++k;
123*b8552abfSAlexey Bataev   #pragma omp master taskloop simd aligned (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
124*b8552abfSAlexey Bataev   for (I k = 0; k < argc; ++k) ++k;
125*b8552abfSAlexey Bataev // FIXME: Should argc really be a pointer?
126*b8552abfSAlexey Bataev   #pragma omp master taskloop simd aligned (*argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
127*b8552abfSAlexey Bataev   for (I k = 0; k < argc; ++k) ++k;
128*b8552abfSAlexey Bataev   #pragma omp master taskloop simd aligned (argc : 5) // expected-warning {{aligned clause will be ignored because the requested alignment is not a power of 2}}
129*b8552abfSAlexey Bataev   for (I k = 0; k < argc; ++k) ++k;
130*b8552abfSAlexey Bataev   #pragma omp master taskloop simd aligned (S1) // expected-error {{'S1' does not refer to a value}}
131*b8552abfSAlexey Bataev   for (I k = 0; k < argc; ++k) ++k;
132*b8552abfSAlexey Bataev   #pragma omp master taskloop simd aligned (argv[1]) // expected-error {{expected variable name}}
133*b8552abfSAlexey Bataev   for (I k = 0; k < argc; ++k) ++k;
134*b8552abfSAlexey Bataev   #pragma omp master taskloop simd aligned(e, g)
135*b8552abfSAlexey Bataev   for (I k = 0; k < argc; ++k) ++k;
136*b8552abfSAlexey Bataev   // expected-error@+1 {{argument of aligned clause should be array, pointer, reference to array or reference to pointer, not 'S3'}}
137*b8552abfSAlexey Bataev   #pragma omp master taskloop simd aligned(h)
138*b8552abfSAlexey Bataev   for (I k = 0; k < argc; ++k) ++k;
139*b8552abfSAlexey Bataev   // expected-error@+1 {{argument of aligned clause should be array, pointer, reference to array or reference to pointer, not 'int'}}
140*b8552abfSAlexey Bataev   #pragma omp master taskloop simd aligned(i)
141*b8552abfSAlexey Bataev   for (I k = 0; k < argc; ++k) ++k;
142*b8552abfSAlexey Bataev   #pragma omp parallel
143*b8552abfSAlexey Bataev   {
144*b8552abfSAlexey Bataev     int *v = 0;
145*b8552abfSAlexey Bataev     I i;
146*b8552abfSAlexey Bataev     #pragma omp master taskloop simd aligned(v:16)
147*b8552abfSAlexey Bataev     for (I k = 0; k < argc; ++k) { i = k; v += 2; }
148*b8552abfSAlexey Bataev   }
149*b8552abfSAlexey Bataev   float *f;
150*b8552abfSAlexey Bataev   #pragma omp master taskloop simd aligned(f)
151*b8552abfSAlexey Bataev   for (I k = 0; k < argc; ++k) ++k;
152*b8552abfSAlexey Bataev   int v = 0;
153*b8552abfSAlexey Bataev   // expected-note@+2 {{initializer of 'j' is not a constant expression}}
154*b8552abfSAlexey Bataev   // expected-error@+1 {{expression is not an integral constant expression}}
155*b8552abfSAlexey Bataev   #pragma omp master taskloop simd aligned(f:j)
156*b8552abfSAlexey Bataev   for (I k = 0; k < argc; ++k) { ++k; v += j; }
157*b8552abfSAlexey Bataev   #pragma omp master taskloop simd aligned(f)
158*b8552abfSAlexey Bataev   for (I k = 0; k < argc; ++k) ++k;
159*b8552abfSAlexey Bataev   return 0;
160*b8552abfSAlexey Bataev }
161*b8552abfSAlexey Bataev 
162*b8552abfSAlexey Bataev // expected-note@+1 2 {{'argc' defined here}}
163*b8552abfSAlexey Bataev int main(int argc, char **argv) {
164*b8552abfSAlexey Bataev   double darr[100];
165*b8552abfSAlexey Bataev   // expected-note@+1 {{in instantiation of function template specialization 'test_template<-4, double, int>' requested here}}
166*b8552abfSAlexey Bataev   test_template<-4>(darr, 4);
167*b8552abfSAlexey Bataev   test_warn<4>(); // ok
168*b8552abfSAlexey Bataev   // expected-note@+1 {{in instantiation of function template specialization 'test_warn<0>' requested here}}
169*b8552abfSAlexey Bataev   test_warn<0>();
170*b8552abfSAlexey Bataev 
171*b8552abfSAlexey Bataev   int i;
172*b8552abfSAlexey Bataev   int &j = i;
173*b8552abfSAlexey Bataev   #pragma omp master taskloop simd aligned // expected-error {{expected '(' after 'aligned'}}
174*b8552abfSAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
175*b8552abfSAlexey Bataev   #pragma omp master taskloop simd aligned ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
176*b8552abfSAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
177*b8552abfSAlexey Bataev   #pragma omp master taskloop simd aligned () // expected-error {{expected expression}}
178*b8552abfSAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
179*b8552abfSAlexey Bataev   #pragma omp master taskloop simd aligned (argv // expected-error {{expected ')'}} expected-note {{to match this '('}}
180*b8552abfSAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
181*b8552abfSAlexey Bataev   // expected-error@+1 {{argument of aligned clause should be array, pointer, reference to array or reference to pointer, not 'int'}}
182*b8552abfSAlexey Bataev   #pragma omp master taskloop simd aligned (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
183*b8552abfSAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
184*b8552abfSAlexey Bataev   #pragma omp master taskloop simd aligned (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
185*b8552abfSAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
186*b8552abfSAlexey Bataev   // expected-error@+1 {{argument of aligned clause should be array, pointer, reference to array or reference to pointer, not 'int'}}
187*b8552abfSAlexey Bataev   #pragma omp master taskloop simd aligned (argc)
188*b8552abfSAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
189*b8552abfSAlexey Bataev   #pragma omp master taskloop simd aligned (S1) // expected-error {{'S1' does not refer to a value}}
190*b8552abfSAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
191*b8552abfSAlexey Bataev   // expected-error@+2 {{argument of aligned clause should be array, pointer, reference to array or reference to pointer, not 'S1'}}
192*b8552abfSAlexey Bataev   // expected-error@+1 {{argument of aligned clause should be array, pointer, reference to array or reference to pointer, not 'S2'}}
193*b8552abfSAlexey Bataev #pragma omp master taskloop simd aligned(a, b)
194*b8552abfSAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
195*b8552abfSAlexey Bataev   #pragma omp master taskloop simd aligned (argv[1]) // expected-error {{expected variable name}}
196*b8552abfSAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
197*b8552abfSAlexey Bataev   // expected-error@+1 {{argument of aligned clause should be array, pointer, reference to array or reference to pointer, not 'S3'}}
198*b8552abfSAlexey Bataev   #pragma omp master taskloop simd aligned(h)
199*b8552abfSAlexey Bataev   for (int k = 0; k < argc; ++k) ++k;
200*b8552abfSAlexey Bataev   int *pargc = &argc;
201*b8552abfSAlexey Bataev   // expected-note@+1 {{in instantiation of function template specialization 'foomain<int *, char>' requested here}}
202*b8552abfSAlexey Bataev   foomain<int*,char>(pargc,argv);
203*b8552abfSAlexey Bataev   return 0;
204*b8552abfSAlexey Bataev }
205*b8552abfSAlexey Bataev 
206