Add flag to dump the raw SemIR in the event of a crash. (#6558)

This commit is contained in:
Geoff Romer
2026-01-06 21:56:08 +00:00
committed by GitHub
parent 0e5832d3c2
commit 2380be2ae1
5 changed files with 47 additions and 0 deletions
+22
View File
@@ -9,6 +9,7 @@
#include "common/check.h"
#include "common/map.h"
#include "common/pretty_stack_trace_function.h"
#include "toolchain/check/check_unit.h"
#include "toolchain/check/context.h"
#include "toolchain/check/cpp/import.h"
@@ -417,6 +418,27 @@ auto CheckParseTrees(
&unit, tree_and_subtrees_getters.Get(unit.sem_ir->check_ir_id()));
}));
// Dump the raw SemIR in the event of a crash. We dump it to a separate file
// to keep the stack trace manageable.
PrettyStackTraceFunction sem_ir_dumper([&](llvm::raw_ostream& output) {
if (!options.sem_ir_crash_dump.empty()) {
output << "Dumping raw SemIR to " << options.sem_ir_crash_dump << "\n";
std::error_code error_code;
llvm::raw_fd_ostream sem_ir_dump(options.sem_ir_crash_dump, error_code);
if (error_code) {
output << "Raw SemIR dump failed: " << error_code.category().name()
<< ":" << error_code.value() << ": " << error_code.message()
<< "\n";
} else {
for (const auto& unit_info : unit_infos) {
if (unit_info.is_checked && unit_info.unit->sem_ir != nullptr) {
unit_info.unit->sem_ir->Print(sem_ir_dump);
}
}
}
}
});
Map<ImportKey, UnitAndImports*> api_map =
BuildApiMapAndDiagnosePackaging(unit_infos);