Skip to content

Commit cac2faa

Browse files
committed
Fix up detection for backend failures
1 parent 12a89a5 commit cac2faa

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

clang/utils/reduce-clang-crash.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,23 @@ def classify_crash(self) -> FailureType:
513513
return FailureType.FrontEnd
514514

515515
print("Found Middle/Backend failure")
516+
517+
self.opt_level = extract_opt_level(self.clang_args) or "-O2"
518+
# Try running w/ -emit-llvm to generate an IR file,
519+
# if it succeeds we have a backend failure, and can use llc.
520+
if not self.check_expected_output(
521+
args=self.clang_args + ["-emit-llvm", "-o", self.ir_file]):
522+
print("Checking llc for failure")
523+
if self.check_expected_output(
524+
cmd=self.llc, args=[self.opt_level, "-filetype=obj"], filename=self.ir_file
525+
):
526+
print("Found BackEnd Crash")
527+
return FailureType.BackEnd
528+
elif os.path.exists(self.ir_file):
529+
# clean up the IR file if we generated it, but won't use it.
530+
print(f"clean up {self.ir_file}, since we can't repro w/ llc")
531+
os.remove(self.ir_file)
532+
516533
args = self.clang_args + [
517534
"-mllvm",
518535
"--print-on-crash",
@@ -528,21 +545,17 @@ def classify_crash(self) -> FailureType:
528545
# The output from --print-on-crash has an invalid first line (pass name).
529546
remove_first_line(self.ir_file)
530547

531-
self.opt_level = extract_opt_level(self.clang_args) or "-O2"
532-
548+
# TODO: parse the exact pass from the backtrace and set the pass
549+
# pipeline directly via -passes="...".
550+
print("Checking opt for failure")
533551
if self.check_expected_output(
534552
cmd=self.opt,
535553
args=[self.opt_level, "-disable-output"],
536554
filename=self.ir_file,
537555
):
538556
print("Found MiddleEnd Crash")
539557
return FailureType.MiddleEnd
540-
if self.check_expected_output(
541-
cmd=self.llc, args=[self.opt_level], filename=self.ir_file
542-
):
543-
print("Found BackEnd Crash")
544-
return FailureType.BackEnd
545-
print("Found Unknow Crash Type. Falling back to creduce")
558+
print("Could not automatically detect crash type, falling back to creduce/cvise.")
546559
return FailureType.Unknown
547560

548561
def reduce_ir_crash(self, new_cmd: List[str]):
@@ -640,13 +653,11 @@ def main():
640653
print("Starting reduction with creduce/cvise")
641654
pass
642655
case FailureType.MiddleEnd:
643-
# TODO: parse the exact pass from the backtrace and set the
644-
# pass pipeline directly.
645656
new_cmd = [opt_cmd, "-disable-output", r.opt_level]
646657
r.reduce_ir_crash(new_cmd)
647658
return
648659
case FailureType.BackEnd:
649-
new_cmd = [llc_cmd, r.opt_level]
660+
new_cmd = [llc_cmd, "-filetype=obj", r.opt_level]
650661
r.reduce_ir_crash(new_cmd)
651662
return
652663

0 commit comments

Comments
 (0)