[clang] [clang][utils] Add auto mode to reduction script (PR #163282)

Alexander Richardson via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 14 10:45:59 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,
----------------
arichardson wrote:

I'd also try changing the opt-level and/or disabling LLVM passes when creating the IR file. In https://github.com/CTSRD-CHERI/llvm-project/blob/238a953f5c7ca3de3cff67bf2433a0f59c9677ee/clang/utils/creduce_crash_testcase.py#L899C75-L899C96 I try the normal command first, then `-O1` and then `-O0 -disable-O0-optnone`.

A lot of the time we also need many of the llc command flags to actually reproduce the crash so I tried mapping some of the clang args to llc args, but it's not very reliable. Luckily you can still use llvm-reduce with clang in the reproducer script.

https://github.com/llvm/llvm-project/pull/163282


More information about the cfe-commits mailing list