Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / parallel_for_linear_messages.cpp
blob4e863de79fe0e4629f0dc44afa6853a69d9c7b28
1 // RUN: %clang_cc1 -verify -fopenmp %s -Wuninitialized
2 // RUN: %clang_cc1 -verify=expected,omp52 -fopenmp -fopenmp-version=52 -DOMP52 %s -Wuninitialized
4 // RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized
5 // RUN: %clang_cc1 -verify=expected,omp52 -fopenmp-simd -fopenmp-version=52 -DOMP52 %s -Wuninitialized
7 extern int omp_default_mem_alloc;
9 void xxx(int argc) {
10 int i, lin, step_sz; // expected-note {{initialize the variable 'lin' to silence this warning}} expected-note {{initialize the variable 'step_sz' to silence this warning}}
11 #pragma omp parallel for linear(lin : step_sz) // expected-warning {{variable 'lin' is uninitialized when used here}} expected-warning {{variable 'step_sz' is uninitialized when used here}}
12 for (i = 0; i < 10; ++i)
16 namespace X {
17 int x;
20 struct B {
21 static int ib; // expected-note {{'B::ib' declared here}}
22 static int bfoo() { return 8; }
25 int bfoo() { return 4; }
27 int z;
28 const int C1 = 1;
29 const int C2 = 2;
30 void test_linear_colons() {
31 int B = 0;
32 #pragma omp parallel for linear(B : bfoo())
33 for (int i = 0; i < 10; ++i)
35 // expected-error@+1 {{unexpected ':' in nested name specifier; did you mean '::'}}
36 #pragma omp parallel for linear(B::ib : B : bfoo())
37 for (int i = 0; i < 10; ++i)
39 // expected-error@+1 {{use of undeclared identifier 'ib'; did you mean 'B::ib'}}
40 #pragma omp parallel for linear(B : ib)
41 for (int i = 0; i < 10; ++i)
43 // expected-error@+1 {{unexpected ':' in nested name specifier; did you mean '::'?}}
44 #pragma omp parallel for linear(z : B : ib)
45 for (int i = 0; i < 10; ++i)
47 #pragma omp parallel for linear(B : B::bfoo())
48 for (int i = 0; i < 10; ++i)
50 #pragma omp parallel for linear(X::x : ::z)
51 for (int i = 0; i < 10; ++i)
53 #pragma omp parallel for linear(B, ::z, X::x)
54 for (int i = 0; i < 10; ++i)
56 #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 '('}}
57 for (int i = 0; i < 10; ++i)
59 // expected-error@+1 {{expected variable name}}
60 #pragma omp parallel for linear(B::bfoo())
61 for (int i = 0; i < 10; ++i)
63 #pragma omp parallel for linear(B::ib, B : C1 + C2)
64 for (int i = 0; i < 10; ++i)
68 template <int L, class T, class N>
69 T test_template(T *arr, N num) {
70 N i;
71 T sum = (T)0;
72 T ind2 = -num * L; // expected-note {{'ind2' defined here}}
73 // expected-error@+1 {{argument of a linear clause should be of integral or pointer type}}
74 #pragma omp parallel for linear(ind2 : L)
75 for (i = 0; i < num; ++i) {
76 T cur = arr[(int)ind2];
77 ind2 += L;
78 sum += cur;
80 return T();
83 template <int LEN>
84 int test_warn() {
85 int ind2 = 0;
86 // expected-warning@+1 {{zero linear step (ind2 should probably be const)}}
87 #pragma omp parallel for linear(ind2 : LEN)
88 for (int i = 0; i < 100; i++) {
89 ind2 += LEN;
91 return ind2;
94 struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
95 extern S1 a;
96 class S2 {
97 mutable int a;
99 public:
100 S2() : a(0) {}
102 const S2 b; // expected-note 2 {{'b' defined here}}
103 const S2 ba[5];
104 class S3 {
105 int a;
107 public:
108 S3() : a(0) {}
110 const S3 ca[5];
111 class S4 {
112 int a;
113 S4();
115 public:
116 S4(int v) : a(v) {}
118 class S5 {
119 int a;
120 S5() : a(0) {}
122 public:
123 S5(int v) : a(v) {}
126 S3 h;
127 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
129 template <class I, class C>
130 int foomain(I argc, C **argv) {
131 I e(4);
132 I g(5);
133 int i, z;
134 int &j = i;
135 #pragma omp parallel for linear // expected-error {{expected '(' after 'linear'}}
136 for (int k = 0; k < argc; ++k)
137 ++k;
138 #pragma omp parallel for linear( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
139 for (int k = 0; k < argc; ++k)
140 ++k;
141 #pragma omp parallel for linear() // expected-error {{expected expression}}
142 for (int k = 0; k < argc; ++k)
143 ++k;
144 #pragma omp parallel for linear(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
145 for (int k = 0; k < argc; ++k)
146 ++k;
147 #pragma omp parallel for linear(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
148 for (int k = 0; k < argc; ++k)
149 ++k;
150 #pragma omp parallel for linear(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
151 for (int k = 0; k < argc; ++k)
152 ++k;
153 #pragma omp parallel for linear(argc, z : 5)
154 for (int k = 0; k < argc; ++k)
155 ++k;
156 #pragma omp parallel for linear(S1) // expected-error {{'S1' does not refer to a value}}
157 for (int k = 0; k < argc; ++k)
158 ++k;
159 // expected-error@+2 {{linear variable with incomplete type 'S1'}}
160 // expected-error@+1 {{argument of a linear clause should be of integral or pointer type, not 'S2'}}
161 #pragma omp parallel for linear(a, b : B::ib)
162 for (int k = 0; k < argc; ++k)
163 ++k;
164 #pragma omp parallel for linear(argv[1]) // expected-error {{expected variable name}}
165 for (int k = 0; k < argc; ++k)
166 ++k;
167 #pragma omp parallel for linear(e, g)
168 for (int k = 0; k < argc; ++k)
169 ++k;
170 #pragma omp parallel for linear(h) // expected-error {{threadprivate or thread local variable cannot be linear}}
171 for (int k = 0; k < argc; ++k)
172 ++k;
173 #pragma omp parallel for linear(i)
174 for (int k = 0; k < argc; ++k)
175 ++k;
176 #pragma omp parallel
178 int v = 0;
179 int i;
180 #pragma omp parallel for linear(v : i)
181 for (int k = 0; k < argc; ++k) {
182 i = k;
183 v += i;
186 #pragma omp parallel for linear(j)
187 for (int k = 0; k < argc; ++k)
188 ++k;
189 int v = 0;
190 #pragma omp parallel for linear(v : j)
191 for (int k = 0; k < argc; ++k) {
192 ++k;
193 v += j;
195 #pragma omp parallel for linear(i)
196 for (int k = 0; k < argc; ++k)
197 ++k;
198 return 0;
201 namespace A {
202 double x;
203 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
205 namespace C {
206 using A::x;
209 int main(int argc, char **argv) {
210 double darr[100];
211 // expected-note@+1 {{in instantiation of function template specialization 'test_template<-4, double, int>' requested here}}
212 test_template<-4>(darr, 4);
213 // expected-note@+1 {{in instantiation of function template specialization 'test_warn<0>' requested here}}
214 test_warn<0>();
216 S4 e(4); // expected-note {{'e' defined here}}
217 S5 g(5); // expected-note {{'g' defined here}}
218 int i, z;
219 int &j = i;
220 #pragma omp parallel for linear // expected-error {{expected '(' after 'linear'}}
221 for (int k = 0; k < argc; ++k)
222 ++k;
223 #pragma omp parallel for linear( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
224 for (int k = 0; k < argc; ++k)
225 ++k;
226 #pragma omp parallel for linear() // expected-error {{expected expression}}
227 for (int k = 0; k < argc; ++k)
228 ++k;
229 #pragma omp parallel for linear(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
230 for (int k = 0; k < argc; ++k)
231 ++k;
232 #pragma omp parallel for linear(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
233 for (int k = 0; k < argc; ++k)
234 ++k;
235 #pragma omp parallel for linear(argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
236 for (int k = 0; k < argc; ++k)
237 ++k;
238 #pragma omp parallel for linear(argc, z)
239 for (int k = 0; k < argc; ++k)
240 ++k;
241 #pragma omp parallel for linear(S1) // expected-error {{'S1' does not refer to a value}}
242 for (int k = 0; k < argc; ++k)
243 ++k;
244 // expected-error@+2 {{linear variable with incomplete type 'S1'}}
245 // expected-error@+1 {{argument of a linear clause should be of integral or pointer type, not 'S2'}}
246 #pragma omp parallel for linear(a, b)
247 for (int k = 0; k < argc; ++k)
248 ++k;
249 #pragma omp parallel for linear(argv[1]) // expected-error {{expected variable name}}
250 for (int k = 0; k < argc; ++k)
251 ++k;
252 // expected-error@+2 {{argument of a linear clause should be of integral or pointer type, not 'S4'}}
253 // expected-error@+1 {{argument of a linear clause should be of integral or pointer type, not 'S5'}}
254 #pragma omp parallel for linear(e, g)
255 for (int k = 0; k < argc; ++k)
256 ++k;
257 #pragma omp parallel for linear(h, C::x) // expected-error 2 {{threadprivate or thread local variable cannot be linear}}
258 for (int k = 0; k < argc; ++k)
259 ++k;
260 #pragma omp parallel
262 int i;
263 #pragma omp parallel for linear(i)
264 for (int k = 0; k < argc; ++k)
265 ++k;
266 #ifdef OMP52
267 #pragma omp parallel for linear(i : step(4))
268 #else
269 #pragma omp parallel for linear(i : 4)
270 #endif
271 for (int k = 0; k < argc; ++k) {
272 ++k;
273 i += 4;
276 #ifdef OMP52
277 #pragma omp for linear(j: step() //omp52-error 2 {{expected expression}} omp52-error{{expected ')'}} omp52-note{{to match this '('}}
278 #else
279 #pragma omp for linear(j)
280 #endif
281 for (int k = 0; k < argc; ++k)
282 ++k;
283 #ifdef OMP52
284 #pragma omp for linear(i: step(1), step(2)) // omp52-error {{multiple 'step size' found in linear clause}}
285 #else
286 #pragma omp for linear(i)
287 #endif
288 for (int k = 0; k < argc; ++k)
289 ++k;
291 foomain<int, char>(argc, argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}}
292 return 0;