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