Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / for_ast_print.cpp
blobabc27caa9ae8d4f6284a8e42619a815a0ed332b3
1 // RUN: %clang_cc1 -verify -fopenmp -ast-print %s -Wsign-conversion | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
2 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s
3 // RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
4 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=51 -ast-print %s -Wsign-conversion -DOMP51 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51
5 // RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -x c++ -std=c++11 -emit-pch -o %t %s -DOMP51
6 // RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -DOMP51 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51
7 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=52 -ast-print %s -Wsign-conversion -DOMP52 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP52
8 // RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -x c++ -std=c++11 -emit-pch -o %t %s -DOMP52
9 // RUN: %clang_cc1 -fopenmp -fopenmp-version=52 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -DOMP52 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP52
11 // RUN: %clang_cc1 -verify -fopenmp-simd -ast-print %s -Wsign-conversion | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
12 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -emit-pch -o %t %s
13 // RUN: %clang_cc1 -fopenmp-simd -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
14 // RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=51 -ast-print %s -Wsign-conversion -DOMP51 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51
15 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=51 -x c++ -std=c++11 -emit-pch -o %t %s -DOMP51
16 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=51 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -DOMP51 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP51
17 // RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=52 -ast-print %s -Wsign-conversion -DOMP52 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP52
18 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -x c++ -std=c++11 -emit-pch -o %t %s -DOMP52
19 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=52 -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print -DOMP52 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP52
20 // expected-no-diagnostics
22 #ifndef HEADER
23 #define HEADER
25 void foo() {}
27 struct S {
28 S(): a(0) {}
29 S(int v) : a(v) {}
30 int a;
31 typedef int type;
34 template <typename T>
35 class S7 : public T {
36 protected:
37 T a;
38 T &b;
39 typename T::type c:12;
40 typename T::type &d;
41 S7() : a(0), b(a), c(0), d(a.a) {}
43 public:
44 S7(typename T::type v) : a(v), b(a), c(v), d(a.a) {
45 #pragma omp for private(a) private(this->a) private(T::a)
46 for (int k = 0; k < a.a; ++k)
47 ++this->a.a;
48 #pragma omp for lastprivate(a) lastprivate(this->a) lastprivate(T::a)
49 for (int k = 0; k < a.a; ++k)
50 ++this->a.a;
51 #if defined(OMP52)
52 #pragma omp for linear(c: val)
53 #else
54 #pragma omp for linear(val(c))
55 #endif
56 for (int k = 0; k < a.a; ++k)
57 ++this->a.a;
59 S7 &operator=(S7 &s) {
60 #pragma omp for private(a) private(this->a)
61 for (int k = 0; k < s.a.a; ++k)
62 ++s.a.a;
63 #pragma omp for lastprivate(a) lastprivate(this->a)
64 for (int k = 0; k < s.a.a; ++k)
65 ++s.a.a;
66 #if defined(OMP52)
67 #pragma omp for linear(this->b: uval)
68 #else
69 #pragma omp for linear(uval(this->b))
70 #endif
71 for (int k = 0; k < s.a.a; ++k)
72 ++s.a.a;
73 return *this;
77 // CHECK: #pragma omp for private(this->a) private(this->a) private(T::a)
78 // CHECK: #pragma omp for lastprivate(this->a) lastprivate(this->a) lastprivate(T::a)
79 // CHECK: #pragma omp for linear(this->c: val)
80 // CHECK: #pragma omp for private(this->a) private(this->a)
81 // CHECK: #pragma omp for lastprivate(this->a) lastprivate(this->a)
82 // CHECK: #pragma omp for linear(this->b: uval)
83 // CHECK: #pragma omp for private(this->a) private(this->a) private(this->S::a)
84 // CHECK: #pragma omp for lastprivate(this->a) lastprivate(this->a) lastprivate(this->S::a)
85 // CHECK: #pragma omp for linear(this->c: val)
87 class S8 : public S7<S> {
88 S8() {}
90 public:
91 S8(int v) : S7<S>(v){
92 #pragma omp for private(a) private(this->a) private(S7<S>::a)
93 for (int k = 0; k < a.a; ++k)
94 ++this->a.a;
95 #pragma omp for lastprivate(a) lastprivate(this->a) lastprivate(S7<S>::a)
96 for (int k = 0; k < a.a; ++k)
97 ++this->a.a;
98 #if defined(OMP52)
99 #pragma omp for linear(S7<S>::d: ref)
100 #else
101 #pragma omp for linear(ref(S7<S>::d))
102 #endif
103 for (int k = 0; k < a.a; ++k)
104 ++this->a.a;
106 S8 &operator=(S8 &s) {
107 #pragma omp for private(a) private(this->a)
108 for (int k = 0; k < s.a.a; ++k)
109 ++s.a.a;
110 #pragma omp for lastprivate(a) lastprivate(this->a)
111 for (int k = 0; k < s.a.a; ++k)
112 ++s.a.a;
113 #pragma omp for linear(this->c)
114 for (int k = 0; k < s.a.a; ++k)
115 ++s.a.a;
116 return *this;
120 // CHECK: #pragma omp for private(this->a) private(this->a) private(this->S7<S>::a)
121 // CHECK: #pragma omp for lastprivate(this->a) lastprivate(this->a) lastprivate(this->S7<S>::a)
122 // CHECK: #pragma omp for linear(this->S7<S>::d: ref)
123 // CHECK: #pragma omp for private(this->a) private(this->a)
124 // CHECK: #pragma omp for lastprivate(this->a) lastprivate(this->a)
125 // CHECK: #pragma omp for linear(this->c)
127 template <class T, int N>
128 T tmain(T argc) {
129 T b = argc, c, d, e, f, g;
130 T arr[N];
131 static T a;
132 // CHECK: static T a;
133 #pragma omp for schedule(dynamic) linear(a) allocate(a)
134 // CHECK-NEXT: #pragma omp for schedule(dynamic) linear(a) allocate(a)
135 for (int i = 0; i < 2; ++i)
136 a = 2;
137 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
138 // CHECK-NEXT: a = 2;
139 #pragma omp for schedule(nonmonotonic: dynamic)
140 // CHECK-NEXT: #pragma omp for schedule(nonmonotonic: dynamic)
141 for (int i = 0; i < 2; ++i)
142 a = 2;
143 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
144 // CHECK-NEXT: a = 2;
145 #pragma omp for schedule(monotonic : dynamic)
146 // CHECK-NEXT: #pragma omp for schedule(monotonic: dynamic)
147 for (int i = 0; i < 2; ++i)
148 a = 2;
149 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
150 // CHECK-NEXT: a = 2;
151 #pragma omp for schedule(nonmonotonic : guided)
152 // CHECK-NEXT: #pragma omp for schedule(nonmonotonic: guided)
153 for (int i = 0; i < 2; ++i)
154 a = 2;
155 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
156 // CHECK-NEXT: a = 2;
157 #pragma omp for schedule(monotonic : guided)
158 // CHECK-NEXT: #pragma omp for schedule(monotonic: guided)
159 for (int i = 0; i < 2; ++i)
160 a = 2;
161 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
162 // CHECK-NEXT: a = 2;
163 #pragma omp for schedule(nonmonotonic : static)
164 // CHECK-NEXT: #pragma omp for schedule(nonmonotonic: static)
165 for (int i = 0; i < 2; ++i)
166 a = 2;
167 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
168 // CHECK-NEXT: a = 2;
169 #pragma omp for schedule(monotonic :static)
170 // CHECK-NEXT: #pragma omp for schedule(monotonic: static)
171 for (int i = 0; i < 2; ++i)
172 a = 2;
173 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
174 // CHECK-NEXT: a = 2;
175 #pragma omp for schedule(nonmonotonic : auto)
176 // CHECK-NEXT: #pragma omp for schedule(nonmonotonic: auto)
177 for (int i = 0; i < 2; ++i)
178 a = 2;
179 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
180 // CHECK-NEXT: a = 2;
181 #pragma omp for schedule(monotonic : auto)
182 // CHECK-NEXT: #pragma omp for schedule(monotonic: auto)
183 for (int i = 0; i < 2; ++i)
184 a = 2;
185 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
186 // CHECK-NEXT: a = 2;
187 #pragma omp for schedule(nonmonotonic : runtime)
188 // CHECK-NEXT: #pragma omp for schedule(nonmonotonic: runtime)
189 for (int i = 0; i < 2; ++i)
190 a = 2;
191 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
192 // CHECK-NEXT: a = 2;
193 #pragma omp for schedule(monotonic : runtime)
194 // CHECK-NEXT: #pragma omp for schedule(monotonic: runtime)
195 for (int i = 0; i < 2; ++i)
196 a = 2;
197 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
198 // CHECK-NEXT: a = 2;
199 #pragma omp parallel
200 #pragma omp for allocate(argc) private(argc, b), firstprivate(c, d), lastprivate(d, f) collapse(N) schedule(static, N) ordered(N) nowait
201 for (auto &x : arr) {
202 int j, hhh = 0;
203 for (int i = 0; i < 2; ++i) {
204 int j, hhh = 0;
205 for (int j = 0; j < 2; ++j)
206 for (int j = 0; j < 2; ++j)
207 for (int j = 0; j < 2; ++j)
208 for (int j = 0; j < 2; ++j)
209 for (int i = 0; i < 2; ++i)
210 for (int j = 0; j < 2; ++j)
211 for (int j = 0; j < 2; ++j)
212 for (int j = 0; j < 2; ++j)
213 for (int j = 0; j < 2; ++j)
214 foo();
215 ++hhh;
217 ++hhh;
219 // CHECK-NEXT: #pragma omp parallel
220 // CHECK-NEXT: #pragma omp for allocate(argc) private(argc,b) firstprivate(c,d) lastprivate(d,f) collapse(N) schedule(static, N) ordered(N) nowait
221 // CHECK-NEXT: for (auto &x : arr) {
222 // CHECK-NEXT: int j, hhh = 0;
223 // CHECK-NEXT: for (int i = 0; i < 2; ++i) {
224 // CHECK-NEXT: int j, hhh = 0;
225 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
226 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
227 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
228 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
229 // CHECK-NEXT: for (int i = 0; i < 2; ++i)
230 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
231 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
232 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
233 // CHECK-NEXT: for (int j = 0; j < 2; ++j)
234 // CHECK-NEXT: foo();
235 // CHECK-NEXT: ++hhh;
236 // CHECK-NEXT: }
237 // CHECK-NEXT: ++hhh;
238 // CHECK-NEXT: }
239 return T();
242 int main(int argc, char **argv) {
243 // CHECK: int main(int argc, char **argv) {
244 int b = argc, c, d, e, f, g;
245 float arr[20];
246 static int a;
247 // CHECK: static int a;
248 #ifdef OMP52
249 #pragma omp for schedule(guided, argc) reduction(+:argv[0][:1]) order(unconstrained:concurrent)
250 #elif OMP51
251 #pragma omp for schedule(guided, argc) reduction(+:argv[0][:1]) order(unconstrained:concurrent)
252 #else
253 #pragma omp for schedule(guided, argc) reduction(+:argv[0][:1]) order(concurrent)
254 #endif // OMP51
255 // OMP50: #pragma omp for schedule(guided, argc) reduction(+: argv[0][:1]) order(concurrent)
256 // OMP51: #pragma omp for schedule(guided, argc) reduction(+: argv[0][:1]) order(unconstrained: concurrent)
257 // OMP52: #pragma omp for schedule(guided, argc) reduction(+: argv[0][:1]) order(unconstrained: concurrent)
258 for (int i = argc; i < c; ++i)
259 a = 2;
260 // CHECK-NEXT: for (int i = argc; i < c; ++i)
261 // CHECK-NEXT: a = 2;
262 #pragma omp parallel
263 #ifdef OMP52
264 #pragma omp for private(argc, b), firstprivate(argv, c), lastprivate(d, f) collapse(3) schedule(auto) ordered nowait linear(g: step(-1)) reduction(task, +:e)
265 #else
266 #pragma omp for private(argc, b), firstprivate(argv, c), lastprivate(d, f) collapse(3) schedule(auto) ordered nowait linear(g:-1) reduction(task, +:e)
267 #endif
268 for (int i = 0; i < 10; ++i)
269 for (int j = 0; j < 10; ++j)
270 for (auto x : arr)
271 foo(), (void)x;
272 // CHECK-NEXT: #pragma omp parallel
273 // CHECK-NEXT: #pragma omp for private(argc,b) firstprivate(argv,c) lastprivate(d,f) collapse(3) schedule(auto) ordered nowait linear(g: step(-1)) reduction(task, +: e)
274 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
275 // CHECK-NEXT: for (int j = 0; j < 10; ++j)
276 // CHECK-NEXT: for (auto x : arr)
277 // CHECK-NEXT: foo() , (void)x;
278 char buf[9] = "01234567";
279 char *p, *q;
280 #pragma omp parallel
281 #pragma omp for
282 for (p = buf; p < &buf[8]; p++)
283 for (q = &buf[0]; q <= buf + 7; q++)
284 foo();
285 // CHECK: #pragma omp parallel
286 // CHECK-NEXT: #pragma omp for{{$}}
287 // CHECK-NEXT: for (p = buf; p < &buf[8]; p++)
288 // CHECK-NEXT: for (q = &buf[0]; q <= buf + 7; q++)
289 // CHECK-NEXT: foo();
290 return (tmain<int, 5>(argc) + tmain<char, 1>(argv[0][0]));
293 #endif