[clang] [clang][utils] Add auto mode to reduction script (PR #163282)
Paul Kirth via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 15 20:18:11 PDT 2025
================
@@ -424,11 +490,76 @@ def run_creduce(self):
print("\n\nctrl-c detected, killed reduction tool")
p.kill()
+ def run_llvm_reduce(self):
+ full_llvm_reduce_cmd = [
+ llvm_reduce_cmd,
+ f"--test={self.testfile}",
+ self.ir_file,
+ ]
+ print("\nRunning llvm-reduce tool...")
+ verbose_print(quote_cmd(full_llvm_reduce_cmd))
+ try:
+ p = subprocess.Popen(full_llvm_reduce_cmd)
+ p.communicate()
+ except KeyboardInterrupt:
+ # Hack to kill C-Reduce because it jumps into its own pgid
+ print("\n\nctrl-c detected, killed reduction tool")
+ p.kill()
+
+ def classify_crash(self) -> FailureType:
+ print("classifying crash ...")
+ if self.check_expected_output(args=self.clang_args + ["-fsyntax-only"]):
+ print("Found Frontend Crash")
+ return FailureType.FrontEnd
+
+ print("Found Middle/Backend failure")
+ args = self.clang_args + [
+ "-mllvm",
+ "--print-on-crash",
+ "-mllvm",
+ f"--print-on-crash-path={self.ir_file}",
+ "-mllvm",
+ "--print-module-scope",
+ ]
+
+ if not self.check_expected_output(args=args):
+ sys.exit("The interestingness test does not pass with '--print-on-crash'.")
+
+ # The output from --print-on-crash has an invalid first line (pass name).
+ remove_first_line(self.ir_file)
+
+ self.opt_level = extract_opt_level(self.clang_args) or "-O2"
+
+ if self.check_expected_output(
----------------
ilovepi wrote:
let me double check, but I think opt definitly still crashes here (at least in my test case). it certainly was in my earlier testing (and I'm pretty sure I confirmed it after I refactored this yesterday).
but I'd actually like to get the precise pass from the backtrace and use that to just craft the
```
opt -passes="function<eager-inv>(drop-unnecessary-assumes,float2int,lower-constant-intrinsics,loop(loop-rotate<header-duplication;no-prepare-for-lto>,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,infer-alignment,loop-load-elim,instcombine<max-iterations=1;no-verify-fixpoint>,simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,slp-vectorizer,vector-combine,instcombine<max-iterations=1;no-verify-fixpoint>,loop-unroll<O2>,transform-warning,sroa<preserve-cfg>,infer-alignment,instcombine<max-iterations=1;no-verify-fixpoint>,loop-mssa(licm<allowspeculation>),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>)" < crash.ll
```
This is the backtrace I'm seeing locally. I'm not 100% on if any of this is gated on a specific cmake flag we set in a typical build of our toolchain, but having the pass string printed seems like a really easy way to get it to reproduce if we get the IR from -print-on-crash.
```
../bin/opt < reduced.ll -O2 -disable-output
opt: /usr/local/google/home/paulkirth/llvm-fork/llvm/include/llvm/Support/Casting.h:109: static bool llvm::isa_impl_cl<llvm::VPWidenCastRecipe, const llvm::VPRecipeBase *>::doit(const From *) [To = llvm::VPWidenCastRecipe, From = const llvm::VPRecipeBase *]: Assertion `Val && "isa<> used on a null pointer"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0. Program arguments: ../bin/opt -O2 -disable-output
1. Running pass "function<eager-inv>(drop-unnecessary-assumes,float2int,lower-constant-intrinsics,loop(loop-rotate<header-duplication;no-prepare-for-lto>,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,infer-alignment,loop-load-elim,instcombine<max-iterations=1;no-verify-fixpoint>,simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>,slp-vectorizer,vector-combine,instcombine<max-iterations=1;no-verify-fixpoint>,loop-unroll<O2>,transform-warning,sroa<preserve-cfg>,infer-alignment,instcombine<max-iterations=1;no-verify-fixpoint>,loop-mssa(licm<allowspeculation>),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,tailcallelim,simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;hoist-loads-stores-with-cond-faulting;no-sink-common-insts;speculate-blocks;simplify-cond-branch;speculate-unpredictables>)" on module "<stdin>"
2. Running pass "loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>" on function "_Z1db"
#0 0x0000555739c1b686 ___interceptor_backtrace ../../../../../../../../../llvm-llvm-project/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors.inc:4556:13
#1 0x0000555739daf2e4 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /usr/local/google/home/paulkirth/llvm-fork/llvm/lib/Support/Unix/Signals.inc:838:8
[1] 3448508 IOT instruction ../bin/opt -O2 -disable-output < reduced.ll
```
https://github.com/llvm/llvm-project/pull/163282
More information about the cfe-commits
mailing list