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