Debug info related directories contain a lot of Clang-generated assembly files and LLVM IR files (and some precanned relocatable files which can/should be replaced). In general, the assembly/IR files benefit from being cleaned to remove unnecessary
details. However, for tests requiring elaborate assembly/IR files where cleanup is
less practical (e.g., large amount of debug information output from Clang),
the current practice is to include the C/C++ source file and the generation instructions as comments, e.g.
; Input generated from the following C code using
; clang -g -O2 -S -emit-llvm
; int e(int);
; inline int f(int a) { return e(a); }
; int g(int a) { return f(a); }
;
; namespace n {
; int v;
; }
This is inconvenient when regeneration is needed. (The author introduced the test might have performed non-trivial clean-up steps.) I propose a utility script llvm/utils/update_test_body.py
to make re-generation easier ([utils] Add script to generate elaborated IR and assembly tests by MaskRay · Pull Request #89026 · llvm/llvm-project · GitHub).
## For test with one single assembly file, .endif can be used.
## Other tests need split-file
# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o a.o
# RUN: ... | FileCheck %s
# CHECK: hello
.ifdef GEN
#--- a.cc
int va;
#--- gen
clang --target=x86_64-linux -S -g a.cc -o -
.endif
# content generated by the script 'gen'
The script will prepare extra files with split-file
, invoke gen
, and then rewrite the part after .endif
with its stdout.
If you want to generate extra files, you can print #---
separators and utilize split-file
in RUN lines.