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