Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / for_simd_linear_messages.cpp
bloba760675dcf34c311da384674e2ce1e2e6c740b7c
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 for simd linear(i, 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()
32 int B = 0;
33 #pragma omp for simd linear(B:bfoo())
34 for (int i = 0; i < 10; ++i) ;
35 // expected-error@+1 {{unexpected ':' in nested name specifier; did you mean '::'}}
36 #pragma omp for simd linear(B::ib:B:bfoo())
37 for (int i = 0; i < 10; ++i) ;
38 // expected-error@+1 {{use of undeclared identifier 'ib'; did you mean 'B::ib'}}
39 #pragma omp for simd linear(B:ib)
40 for (int i = 0; i < 10; ++i) ;
41 // expected-error@+1 {{unexpected ':' in nested name specifier; did you mean '::'?}}
42 #pragma omp for simd linear(z:B:ib)
43 for (int i = 0; i < 10; ++i) ;
44 #pragma omp for simd linear(B:B::bfoo())
45 for (int i = 0; i < 10; ++i) ;
46 #pragma omp for simd linear(X::x : ::z)
47 for (int i = 0; i < 10; ++i) ;
48 #pragma omp for simd linear(B,::z, X::x)
49 for (int i = 0; i < 10; ++i) ;
50 #pragma omp for simd linear(::z)
51 for (int i = 0; i < 10; ++i) ;
52 // expected-error@+1 {{expected variable name}}
53 #pragma omp for simd linear(B::bfoo())
54 for (int i = 0; i < 10; ++i) ;
55 #pragma omp for simd linear(B::ib,B:C1+C2)
56 for (int i = 0; i < 10; ++i) ;
59 template<int L, class T, class N> 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 for simd linear(ind2:L)
65 for (i = 0; i < num; ++i) {
66 T cur = arr[(int)ind2];
67 ind2 += L;
68 sum += cur;
70 return T();
73 template<int LEN> int test_warn() {
74 int ind2 = 0;
75 // expected-warning@+1 {{zero linear step (ind2 should probably be const)}}
76 #pragma omp for simd linear(ind2:LEN)
77 for (int i = 0; i < 100; i++) {
78 ind2 += LEN;
80 return ind2;
83 struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
84 extern S1 a;
85 class S2 {
86 mutable int a;
87 public:
88 S2():a(0) { }
90 const S2 b; // expected-note 2 {{'b' defined here}}
91 const S2 ba[5];
92 class S3 {
93 int a;
94 public:
95 S3():a(0) { }
97 const S3 ca[5];
98 class S4 {
99 int a;
100 S4();
101 public:
102 S4(int v):a(v) { }
104 class S5 {
105 int a;
106 S5():a(0) {}
107 public:
108 S5(int v):a(v) { }
111 S3 h;
112 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
114 template<class I, class C> int foomain(I argc, C **argv) {
115 I e(4);
116 I g(5);
117 int i;
118 int &j = i;
119 #pragma omp for simd linear // expected-error {{expected '(' after 'linear'}}
120 for (int k = 0; k < argc; ++k) ++k;
121 #pragma omp for simd linear ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
122 for (int k = 0; k < argc; ++k) ++k;
123 #pragma omp for simd linear () // expected-error {{expected expression}}
124 for (int k = 0; k < argc; ++k) ++k;
125 #pragma omp for simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
126 for (int k = 0; k < argc; ++k) ++k;
127 #pragma omp for simd linear (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
128 for (int k = 0; k < argc; ++k) ++k;
129 #pragma omp for simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
130 for (int k = 0; k < argc; ++k) ++k;
131 #pragma omp for 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 '('}}
132 for (int k = 0; k < argc; ++k) ++k;
133 #pragma omp for simd linear (S1) // expected-error {{'S1' does not refer to a value}}
134 for (int k = 0; k < argc; ++k) ++k;
135 // expected-error@+2 {{linear variable with incomplete type 'S1'}}
136 // expected-error@+1 {{argument of a linear clause should be of integral or pointer type, not 'S2'}}
137 #pragma omp for simd linear (a, b:B::ib)
138 for (int k = 0; k < argc; ++k) ++k;
139 #pragma omp for simd linear (argv[1]) // expected-error {{expected variable name}}
140 for (int k = 0; k < argc; ++k) ++k;
141 #pragma omp for simd linear(e, g)
142 for (int k = 0; k < argc; ++k) ++k;
143 #pragma omp for simd linear(h) // expected-error {{threadprivate or thread local variable cannot be linear}}
144 for (int k = 0; k < argc; ++k) ++k;
145 #pragma omp for simd linear(i)
146 for (int k = 0; k < argc; ++k) ++k;
147 #pragma omp parallel
149 int v = 0;
150 long z;
151 int i;
152 #pragma omp for simd linear(z, v:i)
153 for (int k = 0; k < argc; ++k) { i = k; v += i; }
155 #pragma omp for simd linear(j)
156 for (int k = 0; k < argc; ++k) ++k;
157 int v = 0;
158 #pragma omp for simd linear(v:j)
159 for (int k = 0; k < argc; ++k) { ++k; v += j; }
160 #pragma omp for simd linear(i)
161 for (int k = 0; k < argc; ++k) ++k;
162 return 0;
165 namespace A {
166 double x;
167 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
169 namespace C {
170 using A::x;
173 int main(int argc, char **argv) {
174 double darr[100];
175 // expected-note@+1 {{in instantiation of function template specialization 'test_template<-4, double, int>' requested here}}
176 test_template<-4>(darr, 4);
177 // expected-note@+1 {{in instantiation of function template specialization 'test_warn<0>' requested here}}
178 test_warn<0>();
180 S4 e(4); // expected-note {{'e' defined here}}
181 S5 g(5); // expected-note {{'g' defined here}}
182 int i;
183 int &j = i;
184 #pragma omp for simd linear // expected-error {{expected '(' after 'linear'}}
185 for (int k = 0; k < argc; ++k) ++k;
186 #pragma omp for simd linear ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
187 for (int k = 0; k < argc; ++k) ++k;
188 #pragma omp for simd linear () // expected-error {{expected expression}}
189 for (int k = 0; k < argc; ++k) ++k;
190 #pragma omp for simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
191 for (int k = 0; k < argc; ++k) ++k;
192 #pragma omp for simd linear (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
193 for (int k = 0; k < argc; ++k) ++k;
194 #pragma omp for simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
195 for (int k = 0; k < argc; ++k) ++k;
196 #pragma omp for simd linear (argc)
197 for (int k = 0; k < argc; ++k) ++k;
198 #pragma omp for simd linear (S1) // expected-error {{'S1' does not refer to a value}}
199 for (int k = 0; k < argc; ++k) ++k;
200 // expected-error@+2 {{linear variable with incomplete type 'S1'}}
201 // expected-error@+1 {{argument of a linear clause should be of integral or pointer type, not 'S2'}}
202 #pragma omp for simd linear(a, b)
203 for (int k = 0; k < argc; ++k) ++k;
204 #pragma omp for simd linear (argv[1]) // expected-error {{expected variable name}}
205 for (int k = 0; k < argc; ++k) ++k;
206 // expected-error@+2 {{argument of a linear clause should be of integral or pointer type, not 'S4'}}
207 // expected-error@+1 {{argument of a linear clause should be of integral or pointer type, not 'S5'}}
208 #pragma omp for simd linear(e, g)
209 for (int k = 0; k < argc; ++k) ++k;
210 #pragma omp for simd linear(h, C::x) // expected-error 2 {{threadprivate or thread local variable cannot be linear}}
211 for (int k = 0; k < argc; ++k) ++k;
212 #pragma omp parallel
214 int i;
215 #pragma omp for simd linear(i)
216 for (int k = 0; k < argc; ++k) ++k;
217 #ifdef OMP52
218 #pragma omp for simd linear(i : step(4))
219 #else
220 #pragma omp for simd linear(i : 4)
221 #endif
222 for (int k = 0; k < argc; ++k) { ++k; i += 4; }
224 #ifdef OMP52
225 #pragma omp for simd linear(j: step() //omp52-error 2 {{expected expression}} omp52-error{{expected ')'}} omp52-note{{to match this '('}}
226 #else
227 #pragma omp for simd linear(j)
228 #endif
229 for (int k = 0; k < argc; ++k) ++k;
230 #ifdef OMP52
231 #pragma omp for simd linear(i: step(1), step(2)) // omp52-error {{multiple 'step size' found in linear clause}}
232 #else
233 #pragma omp for simd linear(i)
234 #endif
235 for (int k = 0; k < argc; ++k) ++k;
236 #ifdef OMP52
237 #pragma omp for simd linear(j: step()) // omp52-error 2 {{expected expression}}
238 for (int k = 0; k < argc; ++k) ++k;
239 #pragma omp for simd linear(j: pval) // omp52-error {{use of undeclared identifier 'pval'}}
240 for (int k = 0; k < argc; ++k) ++k;
241 #pragma omp for simd linear(i: val, step(2 // omp52-error 3 {{expected ')'}} omp52-note 2 {{to match this '('}}
242 for (int k = 0; k < argc; ++k) ++k;
243 #endif
245 foomain<int,char>(argc,argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}}
246 return 0;