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