Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / parallel_for_simd_linear_messages.cpp
blobab682e29cd93c1a0b937432e9dafe95731b6d837
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;
8 void xxx(int argc) {
9 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}}
10 #pragma omp parallel 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}}
11 for (i = 0; i < 10; ++i)
15 namespace X {
16 int x;
19 struct B {
20 static int ib; // expected-note {{'B::ib' declared here}}
21 static int bfoo() { return 8; }
24 int bfoo() { return 4; }
26 int z;
27 const int C1 = 1;
28 const int C2 = 2;
29 void test_linear_colons()
31 int B = 0;
32 #pragma omp parallel for 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 parallel for 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 parallel for 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 parallel for simd linear(z:B:ib)
42 for (int i = 0; i < 10; ++i) ;
43 #pragma omp parallel for simd linear(B:B::bfoo())
44 for (int i = 0; i < 10; ++i) ;
45 #pragma omp parallel for simd linear(X::x : ::z)
46 for (int i = 0; i < 10; ++i) ;
47 #pragma omp parallel for simd linear(B,::z, X::x)
48 for (int i = 0; i < 10; ++i) ;
49 #pragma omp parallel for simd linear(::z)
50 for (int i = 0; i < 10; ++i) ;
51 // expected-error@+1 {{expected variable name}}
52 #pragma omp parallel for simd linear(B::bfoo())
53 for (int i = 0; i < 10; ++i) ;
54 #pragma omp parallel for simd linear(B::ib,B:C1+C2)
55 for (int i = 0; i < 10; ++i) ;
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 parallel for simd linear(ind2:L)
64 for (i = 0; i < num; ++i) {
65 T cur = arr[(int)ind2];
66 ind2 += L;
67 sum += cur;
69 return T();
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 parallel for simd linear(ind2:LEN)
76 for (int i = 0; i < 100; i++) {
77 ind2 += LEN;
79 return ind2;
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) { }
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) { }
96 const S3 ca[5];
97 class S4 {
98 int a;
99 S4();
100 public:
101 S4(int v):a(v) { }
103 class S5 {
104 int a;
105 S5():a(0) {}
106 public:
107 S5(int v):a(v) { }
110 S3 h;
111 #pragma omp threadprivate(h) // expected-note 2 {{defined as threadprivate or thread local}}
113 template<class I, class C> int foomain(I argc, C **argv) {
114 I e(4);
115 I g(5);
116 int i, z;
117 int &j = i;
118 #pragma omp parallel for simd linear // expected-error {{expected '(' after 'linear'}}
119 for (int k = 0; k < argc; ++k) ++k;
120 #pragma omp parallel for 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 parallel for simd linear () // expected-error {{expected expression}}
123 for (int k = 0; k < argc; ++k) ++k;
124 #pragma omp parallel for simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
125 for (int k = 0; k < argc; ++k) ++k;
126 #pragma omp parallel for simd linear (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
127 for (int k = 0; k < argc; ++k) ++k;
128 #pragma omp parallel for simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
129 for (int k = 0; k < argc; ++k) ++k;
130 #pragma omp parallel 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 '('}}
131 for (int k = 0; k < argc; ++k) ++k;
132 #pragma omp parallel for simd linear (S1) // expected-error {{'S1' does not refer to a value}}
133 for (int k = 0; k < argc; ++k) ++k;
134 // expected-error@+2 {{linear variable with incomplete type 'S1'}}
135 // expected-error@+1 {{argument of a linear clause should be of integral or pointer type, not 'S2'}}
136 #pragma omp parallel for simd linear (a, b:B::ib)
137 for (int k = 0; k < argc; ++k) ++k;
138 #pragma omp parallel for simd linear (argv[1]) // expected-error {{expected variable name}}
139 for (int k = 0; k < argc; ++k) ++k;
140 #pragma omp parallel for simd linear(e, g)
141 for (int k = 0; k < argc; ++k) ++k;
142 #pragma omp parallel for simd linear(h) // expected-error {{threadprivate or thread local variable cannot be linear}}
143 for (int k = 0; k < argc; ++k) ++k;
144 #pragma omp parallel for simd linear(i, z)
145 for (int k = 0; k < argc; ++k) ++k;
146 #pragma omp parallel
148 int v = 0;
149 int i;
150 #pragma omp parallel for simd linear(v:i)
151 for (int k = 0; k < argc; ++k) { i = k; v += i; }
153 #pragma omp parallel for simd linear(j)
154 for (int k = 0; k < argc; ++k) ++k;
155 int v = 0;
156 #pragma omp parallel for simd linear(v:j)
157 for (int k = 0; k < argc; ++k) { ++k; v += j; }
158 #pragma omp parallel for simd linear(i)
159 for (int k = 0; k < argc; ++k) ++k;
160 return 0;
163 namespace A {
164 double x;
165 #pragma omp threadprivate(x) // expected-note {{defined as threadprivate or thread local}}
167 namespace C {
168 using A::x;
171 int main(int argc, char **argv) {
172 double darr[100];
173 // expected-note@+1 {{in instantiation of function template specialization 'test_template<-4, double, int>' requested here}}
174 test_template<-4>(darr, 4);
175 // expected-note@+1 {{in instantiation of function template specialization 'test_warn<0>' requested here}}
176 test_warn<0>();
178 S4 e(4); // expected-note {{'e' defined here}}
179 S5 g(5); // expected-note {{'g' defined here}}
180 int i, z;
181 int &j = i;
182 #pragma omp parallel for simd linear // expected-error {{expected '(' after 'linear'}}
183 for (int k = 0; k < argc; ++k) ++k;
184 #pragma omp parallel for simd linear ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
185 for (int k = 0; k < argc; ++k) ++k;
186 #pragma omp parallel for simd linear () // expected-error {{expected expression}}
187 for (int k = 0; k < argc; ++k) ++k;
188 #pragma omp parallel for simd linear (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
189 for (int k = 0; k < argc; ++k) ++k;
190 #pragma omp parallel for simd linear (argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
191 for (int k = 0; k < argc; ++k) ++k;
192 #pragma omp parallel for simd linear (argc > 0 ? argv[1] : argv[2]) // expected-error {{expected variable name}}
193 for (int k = 0; k < argc; ++k) ++k;
194 #pragma omp parallel for simd linear (argc, z)
195 for (int k = 0; k < argc; ++k) ++k;
196 #pragma omp parallel for simd linear (S1) // expected-error {{'S1' does not refer to a value}}
197 for (int k = 0; k < argc; ++k) ++k;
198 // expected-error@+2 {{linear variable with incomplete type 'S1'}}
199 // expected-error@+1 {{argument of a linear clause should be of integral or pointer type, not 'S2'}}
200 #pragma omp parallel for simd linear (a, b)
201 for (int k = 0; k < argc; ++k) ++k;
202 #pragma omp parallel for simd linear (argv[1]) // expected-error {{expected variable name}}
203 for (int k = 0; k < argc; ++k) ++k;
204 // expected-error@+2 {{argument of a linear clause should be of integral or pointer type, not 'S4'}}
205 // expected-error@+1 {{argument of a linear clause should be of integral or pointer type, not 'S5'}}
206 #pragma omp parallel for simd linear(e, g)
207 for (int k = 0; k < argc; ++k) ++k;
208 #pragma omp parallel for simd linear(h, C::x) // expected-error 2 {{threadprivate or thread local variable cannot be linear}}
209 for (int k = 0; k < argc; ++k) ++k;
210 #pragma omp parallel
212 int i;
213 #pragma omp parallel for simd linear(i)
214 for (int k = 0; k < argc; ++k) ++k;
215 #ifdef OMP52
216 #pragma omp parallel for simd linear(i : step(4))
217 #else
218 #pragma omp parallel for simd linear(i : 4)
219 #endif
220 for (int k = 0; k < argc; ++k) { ++k; i += 4; }
222 #ifdef OMP52
223 #pragma omp for linear(j: step() //omp52-error 2 {{expected expression}} omp52-error{{expected ')'}} omp52-note{{to match this '('}}
224 #else
225 #pragma omp parallel for simd linear(j)
226 #endif
227 for (int k = 0; k < argc; ++k) ++k;
228 #ifdef OMP52
229 #pragma omp for linear(i: step(1), step(2)) // omp52-error {{multiple 'step size' found in linear clause}}
230 #else
231 #pragma omp parallel for simd linear(i)
232 #endif
233 for (int k = 0; k < argc; ++k) ++k;
235 foomain<int,char>(argc,argv); // expected-note {{in instantiation of function template specialization 'foomain<int, char>' requested here}}
236 return 0;