[clang] [clang][utils] Add auto mode to reduction script (PR #163282)
Arthur Eubanks via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 15 16:14:41 PDT 2025
================
@@ -424,11 +490,129 @@ 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:
+ 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")
+
+ self.opt_level = extract_opt_level(self.clang_args) or "-O2"
+ backend_result = self.check_backend()
+ if backend_result == FailureType.BackEnd:
+ return backend_result
+
+ # Try running w/ -emit-llvm to generate an IR file,
+ # if it succeeds we have a backend failure, and can use llc.
+ if not self.check_expected_output(
+ args=self.clang_args + ["-emit-llvm", "-o", self.ir_file]
+ ):
+ print("Checking llc for failure")
+ if self.check_expected_output(
+ cmd=self.llc,
+ args=[self.opt_level, "-filetype=obj"],
+ filename=self.ir_file,
+ ):
+ print("Found BackEnd Crash")
+ return FailureType.BackEnd
+ elif os.path.exists(self.ir_file):
+ # clean up the IR file if we generated it, but won't use it.
+ print(f"clean up {self.ir_file}, since we can't repro w/ llc")
+ os.remove(self.ir_file)
+
+ # The IR file will be in 'self.ir_file'
+ self.extract_crashing_ir()
+ return self.check_middle_end()
+
+ def check_llc_failure(self) -> bool:
+ return self.check_expected_output(
+ cmd=self.llc, args=[self.opt_level, "-filetype=obj"], filename=self.ir_file
+ )
+
+ def extract_backend_ir(self) -> bool:
+ return not self.check_expected_output(
+ args=self.clang_args + ["-emit-llvm", "-o", self.ir_file]
+ )
+
+ def check_backend(self) -> Optional[FailureType]:
+ # Try running w/ -emit-llvm to generate an IR file,
+ # if it succeeds we have a backend failure, and can use llc.
+ if self.extract_backend_ir():
+ print("Checking llc for failure")
+ if self.check_llc_failure():
+ print("Found BackEnd Crash")
+ return FailureType.BackEnd
+ elif os.path.exists(self.ir_file):
+ # clean up the IR file if we generated it, but won't use it.
+ print(f"clean up {self.ir_file}, since we can't repro w/ llc")
+ os.remove(self.ir_file)
+
+ def extract_crashing_ir(self):
+ """
+ Extract IR just before the crash using --print-on-crash
+ """
+ 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)
----------------
aeubanks wrote:
we should change the extra line to start with `;` to avoid having to do this (I've also been annoyed with this in the past). lemme have someone make this change to get into the LLVM development workflow
https://github.com/llvm/llvm-project/pull/163282
More information about the cfe-commits
mailing list