Skip to content

Commit 0952621

Browse files
committed
[OpenACC][NFC] Simplify FOREACH_CASE idiom in lit tests
That is, make it like the occurrence in the recent `openmp/libacc2omp/test/prof/api/device-init.c`. Specifically, use lit `%for cases` to generate the `FOREACH_CASE` definition so that you don't have to maintain the list of cases also in the source code, and so you don't need code to verify that the two lists are in still sync.
1 parent d3884ee commit 0952621

File tree

5 files changed

+64
-170
lines changed

5 files changed

+64
-170
lines changed

clang/test/OpenACC/no-create.c

Lines changed: 19 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@
8282
// RUN: (case=CASE_INHERITED_SUBARRAY_PRESENT not-crash-if-fail= )
8383
// RUN: (case=CASE_INHERITED_SUBARRAY_ABSENT not-crash-if-fail= )
8484
// RUN: }
85+
// RUN: echo '#define FOREACH_CASE(Macro) \' > %t-cases.h
86+
// RUN: %for cases {
87+
// RUN: echo ' Macro(%[case]) \' >> %t-cases.h
88+
// RUN: }
89+
// RUN: echo ' /*end of FOREACH_CASE*/' >> %t-cases.h
8590

8691
// Check -ast-dump before and after AST serialization.
8792
//
@@ -90,10 +95,10 @@
9095
//
9196
// RUN: %for no-create-opts {
9297
// RUN: %clang -Xclang -verify -Xclang -ast-dump -fsyntax-only -fopenacc %s \
93-
// RUN: %acc-includes %[no-create-opt] \
98+
// RUN: %acc-includes %[no-create-opt] -DCASES_HEADER='"%t-cases.h"' \
9499
// RUN: | FileCheck -check-prefixes=DMP,DMP-%[noAlloc-or-alloc] %s
95100
// RUN: %clang -Xclang -verify -fopenacc -emit-ast -o %t.ast %s \
96-
// RUN: %acc-includes %[no-create-opt]
101+
// RUN: %acc-includes %[no-create-opt] -DCASES_HEADER='"%t-cases.h"'
97102
// RUN: %clang_cc1 -ast-dump-all %t.ast \
98103
// RUN: | FileCheck -check-prefixes=DMP,DMP-%[noAlloc-or-alloc] %s
99104
// RUN: }
@@ -104,7 +109,7 @@
104109
// more than sufficient to show it's working for the no_create clause.
105110
//
106111
// RUN: %clang -Xclang -verify -Xclang -ast-print -fsyntax-only %acc-includes \
107-
// RUN: %s \
112+
// RUN: -DCASES_HEADER='"%t-cases.h"' %s \
108113
// RUN: | FileCheck -check-prefixes=PRT %s
109114
//
110115
// TODO: If lit were to support %for inside a %data, we could iterate prt-opts
@@ -133,7 +138,8 @@
133138
// RUN: %for no-create-opts {
134139
// RUN: %for prt-args {
135140
// RUN: %clang -Xclang -verify %[prt] %[no-create-opt] %acc-includes \
136-
// RUN: %t-acc.c -Wno-openacc-omp-map-hold \
141+
// RUN: -DCASES_HEADER='"%t-cases.h"' %t-acc.c \
142+
// RUN: -Wno-openacc-omp-map-hold \
137143
// RUN: | FileCheck -check-prefixes=%[prt-chk] \
138144
// RUN: -DNO_CREATE_MT=%[no-create-mt] \
139145
// RUN: -DINHERITED_NO_CREATE_MT=%[inherited-no-create-mt] %s
@@ -148,7 +154,7 @@
148154
//
149155
// RUN: %for no-create-opts {
150156
// RUN: %clang -Xclang -verify -fopenacc %[no-create-opt] -emit-ast \
151-
// RUN: %acc-includes -o %t.ast %t-acc.c
157+
// RUN: %acc-includes -DCASES_HEADER='"%t-cases.h"' -o %t.ast %t-acc.c
152158
// RUN: %for prt-args {
153159
// RUN: %clang %[prt] %t.ast 2>&1 \
154160
// RUN: | FileCheck -check-prefixes=%[prt-chk] \
@@ -170,11 +176,14 @@
170176
// RUN: %for tgts {
171177
// RUN: %for prt-opts {
172178
// RUN: %[run-if] %clang -Xclang -verify %[prt-opt]=omp \
173-
// RUN: %[no-create-opt] %acc-includes %s > %t-omp.c \
179+
// RUN: %[no-create-opt] %acc-includes \
180+
// RUN: -DCASES_HEADER='"%t-cases.h"' %s > %t-omp.c \
174181
// RUN: -Wno-openacc-omp-map-hold
175182
// RUN: %[run-if] echo "// expected""-no-diagnostics" >> %t-omp.c
176183
// RUN: %[run-if] %clang -Xclang -verify -fopenmp %fopenmp-version \
177-
// RUN: %[tgt-cflags] %acc-includes -o %t.exe %t-omp.c %acc-libs
184+
// RUN: %[tgt-cflags] %acc-includes \
185+
// RUN: -DCASES_HEADER='"%t-cases.h"' -o %t.exe %t-omp.c \
186+
// RUN: %acc-libs
178187
// RUN: %for cases {
179188
// RUN: %[run-if] %[not-crash-if-fail] %t.exe %[case] > %t.out 2>&1
180189
// RUN: %[run-if] FileCheck -input-file %t.out %s \
@@ -191,24 +200,18 @@
191200
// RUN: %for no-create-opts {
192201
// RUN: %for tgts {
193202
// RUN: %[run-if] %clang -Xclang -verify -fopenacc %[no-create-opt] \
194-
// RUN: %[tgt-cflags] %acc-includes -o %t.exe %s
195-
// RUN: rm -f %t.actual-cases && touch %t.actual-cases
203+
// RUN: %[tgt-cflags] %acc-includes \
204+
// RUN: -DCASES_HEADER='"%t-cases.h"' -o %t.exe %s
196205
// RUN: %for cases {
197206
// RUN: %[run-if] %[not-crash-if-fail] %t.exe %[case] > %t.out 2>&1
198207
// RUN: %[run-if] FileCheck -input-file %t.out %s \
199208
// RUN: -match-full-lines -allow-empty \
200209
// RUN: -check-prefixes=EXE%[host],EXE-%[case]%[host] \
201210
// RUN: -check-prefixes=EXE-%[case]-%[noAlloc-or-alloc]%[host]
202-
// RUN: echo '%[case]' >> %t.actual-cases
203211
// RUN: }
204212
// RUN: }
205213
// RUN: }
206214

207-
// Make sure %data cases didn't omit any cases defined in the code.
208-
//
209-
// RUN: %t.exe -dump-cases > %t.expected-cases
210-
// RUN: diff -u %t.expected-cases %t.actual-cases >&2
211-
212215
// END.
213216

214217
// expected-no-diagnostics
@@ -217,33 +220,7 @@
217220
#include <stdio.h>
218221
#include <string.h>
219222

220-
#define FOREACH_CASE(Macro) \
221-
Macro(CASE_DATA_SCALAR_PRESENT) \
222-
Macro(CASE_DATA_SCALAR_ABSENT) \
223-
Macro(CASE_DATA_ARRAY_PRESENT) \
224-
Macro(CASE_DATA_ARRAY_ABSENT) \
225-
Macro(CASE_DATA_SUBARRAY_PRESENT) \
226-
Macro(CASE_DATA_SUBARRAY_DISJOINT) \
227-
Macro(CASE_DATA_SUBARRAY_OVERLAP_START) \
228-
Macro(CASE_DATA_SUBARRAY_OVERLAP_END) \
229-
Macro(CASE_DATA_SUBARRAY_CONCAT2) \
230-
Macro(CASE_PARALLEL_SCALAR_PRESENT) \
231-
Macro(CASE_PARALLEL_SCALAR_ABSENT) \
232-
Macro(CASE_PARALLEL_ARRAY_PRESENT) \
233-
Macro(CASE_PARALLEL_ARRAY_ABSENT) \
234-
Macro(CASE_PARALLEL_SUBARRAY_PRESENT) \
235-
Macro(CASE_PARALLEL_SUBARRAY_DISJOINT) \
236-
Macro(CASE_PARALLEL_SUBARRAY_OVERLAP_START) \
237-
Macro(CASE_PARALLEL_SUBARRAY_OVERLAP_END) \
238-
Macro(CASE_PARALLEL_SUBARRAY_CONCAT2) \
239-
Macro(CASE_PARALLEL_LOOP_SCALAR_PRESENT) \
240-
Macro(CASE_PARALLEL_LOOP_SCALAR_ABSENT) \
241-
Macro(CASE_CONST_PRESENT) \
242-
Macro(CASE_CONST_ABSENT) \
243-
Macro(CASE_INHERITED_PRESENT) \
244-
Macro(CASE_INHERITED_ABSENT) \
245-
Macro(CASE_INHERITED_SUBARRAY_PRESENT) \
246-
Macro(CASE_INHERITED_SUBARRAY_ABSENT)
223+
#include CASES_HEADER
247224

248225
enum Case {
249226
#define AddCase(CaseName) \
@@ -294,11 +271,6 @@ int main(int argc, char *argv[]) {
294271
fprintf(stderr, "expected one argument\n");
295272
return 1;
296273
}
297-
if (!strcmp(argv[1], "-dump-cases")) {
298-
for (int i = 0; i < CASE_END; ++i)
299-
printf("%s\n", CaseNames[i]);
300-
return 0;
301-
}
302274
enum Case selectedCase;
303275
for (selectedCase = 0; selectedCase < CASE_END; ++selectedCase) {
304276
if (!strcmp(argv[1], CaseNames[selectedCase]))

clang/test/OpenACC/present.c

Lines changed: 17 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@
8181
// RUN: (case=CASE_CONST_PRESENT not-if-fail= not-crash-if-fail= not-if-presentError= not-if-arrayExtError= )
8282
// RUN: (case=CASE_CONST_ABSENT not-if-fail=%[not-if-off-and-present] not-crash-if-fail=%[not-crash-if-off-and-present] not-if-presentError=%[not-if-off-and-present] not-if-arrayExtError= )
8383
// RUN: }
84+
// RUN: echo '#define FOREACH_CASE(Macro) \' > %t-cases.h
85+
// RUN: %for cases {
86+
// RUN: echo ' Macro(%[case]) \' >> %t-cases.h
87+
// RUN: }
88+
// RUN: echo ' /*end of FOREACH_CASE*/' >> %t-cases.h
8489

8590
// Check -ast-dump before and after AST serialization.
8691
//
@@ -89,10 +94,10 @@
8994
//
9095
// RUN: %for present-opts {
9196
// RUN: %clang -Xclang -verify -Xclang -ast-dump -fsyntax-only -fopenacc %s \
92-
// RUN: %[present-opt] \
97+
// RUN: %[present-opt] -DCASES_HEADER='"%t-cases.h"' \
9398
// RUN: | FileCheck -check-prefixes=DMP %s
9499
// RUN: %clang -Xclang -verify -fopenacc -emit-ast -o %t.ast %s \
95-
// RUN: %[present-opt]
100+
// RUN: %[present-opt] -DCASES_HEADER='"%t-cases.h"'
96101
// RUN: %clang_cc1 -ast-dump-all %t.ast \
97102
// RUN: | FileCheck -check-prefixes=DMP %s
98103
// RUN: }
@@ -102,7 +107,8 @@
102107
// We include print checking on only a few representative cases, which should be
103108
// more than sufficient to show it's working for the present clause.
104109
//
105-
// RUN: %clang -Xclang -verify -Xclang -ast-print -fsyntax-only %s \
110+
// RUN: %clang -Xclang -verify -Xclang -ast-print -fsyntax-only \
111+
// RUN: -DCASES_HEADER='"%t-cases.h"' %s \
106112
// RUN: | FileCheck -check-prefixes=PRT %s
107113
//
108114
// TODO: If lit were to support %for inside a %data, we could iterate prt-opts
@@ -131,7 +137,7 @@
131137
// RUN: %for present-opts {
132138
// RUN: %for prt-args {
133139
// RUN: %clang -Xclang -verify %[prt] %[present-opt] %t-acc.c \
134-
// RUN: -Wno-openacc-omp-map-hold \
140+
// RUN: -DCASES_HEADER='"%t-cases.h"' -Wno-openacc-omp-map-hold \
135141
// RUN: | FileCheck -check-prefixes=%[prt-chk] -DPRESENT_MT=%[present-mt] %s
136142
// RUN: }
137143
// RUN: }
@@ -144,7 +150,7 @@
144150
//
145151
// RUN: %for present-opts {
146152
// RUN: %clang -Xclang -verify -fopenacc %[present-opt] -emit-ast -o %t.ast \
147-
// RUN: %t-acc.c
153+
// RUN: -DCASES_HEADER='"%t-cases.h"' %t-acc.c
148154
// RUN: %for prt-args {
149155
// RUN: %clang %[prt] %t.ast 2>&1 \
150156
// RUN: | FileCheck -check-prefixes=%[prt-chk] -DPRESENT_MT=%[present-mt] %s
@@ -166,10 +172,12 @@
166172
// RUN: %for prt-opts {
167173
// RUN: %[run-if] %clang -Xclang -verify %[prt-opt]=omp %[present-opt] \
168174
// RUN: %[use-var-cflags] %s > %t-omp.c \
175+
// RUN: -DCASES_HEADER='"%t-cases.h"' \
169176
// RUN: -Wno-openacc-omp-map-hold
170177
// RUN: %[run-if] echo "// expected""-no-diagnostics" >> %t-omp.c
171178
// RUN: %[run-if] %clang -Xclang -verify -fopenmp %fopenmp-version \
172-
// RUN: %[tgt-cflags] %[use-var-cflags] -o %t.exe %t-omp.c
179+
// RUN: %[tgt-cflags] %[use-var-cflags] -o %t.exe %t-omp.c \
180+
// RUN: -DCASES_HEADER='"%t-cases.h"'
173181
// RUN: %for cases {
174182
// RUN: %[run-if] %[not-crash-if-fail] %t.exe %[case] \
175183
// RUN: > %t.out 2> %t.err
@@ -191,8 +199,8 @@
191199
// RUN: %for tgts {
192200
// RUN: %for use-vars {
193201
// RUN: %[run-if] %clang -Xclang -verify -fopenacc %[present-opt] \
194-
// RUN: %[tgt-cflags] %[use-var-cflags] -o %t.exe %s
195-
// RUN: rm -f %t.actual-cases && touch %t.actual-cases
202+
// RUN: %[tgt-cflags] %[use-var-cflags] -o %t.exe %s \
203+
// RUN: -DCASES_HEADER='"%t-cases.h"'
196204
// RUN: %for cases {
197205
// RUN: %[run-if] %[not-crash-if-fail] %t.exe %[case] > %t.out 2> %t.err
198206
// RUN: %[run-if] FileCheck -input-file %t.err -allow-empty %s \
@@ -201,47 +209,19 @@
201209
// RUN: -check-prefixes=EXE-ERR-%[not-if-arrayExtError]ARRAYEXT
202210
// RUN: %[run-if] FileCheck -input-file %t.out -allow-empty %s \
203211
// RUN: -check-prefixes=EXE-OUT,EXE-OUT-%[not-if-fail]PASS
204-
// RUN: echo '%[case]' >> %t.actual-cases
205212
// RUN: }
206213
// RUN: }
207214
// RUN: }
208215
// RUN: }
209216

210-
// Make sure %data cases didn't omit any cases defined in the code.
211-
//
212-
// RUN: %t.exe -dump-cases > %t.expected-cases
213-
// RUN: diff -u %t.expected-cases %t.actual-cases >&2
214-
215217
// END.
216218

217219
// expected-no-diagnostics
218220

219221
#include <stdio.h>
220222
#include <string.h>
221223

222-
#define FOREACH_CASE(Macro) \
223-
Macro(CASE_DATA_SCALAR_PRESENT) \
224-
Macro(CASE_DATA_SCALAR_ABSENT) \
225-
Macro(CASE_DATA_ARRAY_PRESENT) \
226-
Macro(CASE_DATA_ARRAY_ABSENT) \
227-
Macro(CASE_DATA_SUBARRAY_PRESENT) \
228-
Macro(CASE_DATA_SUBARRAY_DISJOINT) \
229-
Macro(CASE_DATA_SUBARRAY_OVERLAP_START) \
230-
Macro(CASE_DATA_SUBARRAY_OVERLAP_END) \
231-
Macro(CASE_DATA_SUBARRAY_CONCAT2) \
232-
Macro(CASE_PARALLEL_SCALAR_PRESENT) \
233-
Macro(CASE_PARALLEL_SCALAR_ABSENT) \
234-
Macro(CASE_PARALLEL_ARRAY_PRESENT) \
235-
Macro(CASE_PARALLEL_ARRAY_ABSENT) \
236-
Macro(CASE_PARALLEL_SUBARRAY_PRESENT) \
237-
Macro(CASE_PARALLEL_SUBARRAY_DISJOINT) \
238-
Macro(CASE_PARALLEL_SUBARRAY_OVERLAP_START) \
239-
Macro(CASE_PARALLEL_SUBARRAY_OVERLAP_END) \
240-
Macro(CASE_PARALLEL_SUBARRAY_CONCAT2) \
241-
Macro(CASE_PARALLEL_LOOP_SCALAR_PRESENT) \
242-
Macro(CASE_PARALLEL_LOOP_SCALAR_ABSENT) \
243-
Macro(CASE_CONST_PRESENT) \
244-
Macro(CASE_CONST_ABSENT)
224+
#include CASES_HEADER
245225

246226
enum Case {
247227
#define AddCase(CaseName) \
@@ -276,11 +256,6 @@ int main(int argc, char *argv[]) {
276256
fprintf(stderr, "expected one argument\n");
277257
return 1;
278258
}
279-
if (!strcmp(argv[1], "-dump-cases")) {
280-
for (int i = 0; i < CASE_END; ++i)
281-
printf("%s\n", CaseNames[i]);
282-
return 0;
283-
}
284259
enum Case selectedCase;
285260
for (selectedCase = 0; selectedCase < CASE_END; ++selectedCase) {
286261
if (!strcmp(argv[1], CaseNames[selectedCase]))

0 commit comments

Comments
 (0)