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