Don't output files on LLVM errors. (#4425)

Fix issue where an LLVM error or warning during IR passes (e.g. --fwarn-stack-size) does not abort outputting files. The object file would be added to the cache, and subsequent repeated LDC
execution would fetch the object file from the cache, effectively swallowing the error.
This commit is contained in:
Johan Engelen 2023-06-16 00:26:07 +02:00 committed by GitHub
parent 29bf2d302c
commit 3e2156fa68
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 62 additions and 12 deletions

View file

@ -377,15 +377,24 @@ void CodeGenerator::writeMLIRModule(mlir::OwningModuleRef *module,
const auto llpath = replaceExtensionWith(mlir_ext, filename);
Logger::println("Writting MLIR to %s\n", llpath.c_str());
std::error_code errinfo;
llvm::raw_fd_ostream aos(llpath, errinfo, llvm::sys::fs::OF_None);
llvm::ToolOutputFile aos(llpath, errinfo, llvm::sys::fs::OF_None);
if (aos.has_error()) {
if (aos.os().has_error()) {
error(Loc(), "Cannot write MLIR file '%s': %s", llpath.c_str(),
errinfo.message().c_str());
fatal();
}
// module->print(aos);
// Terminate upon errors during the LLVM passes.
if (global.errors || global.warnings) {
Logger::println(
"Aborting because of errors/warnings during bitcode LLVM passes");
fatal();
}
aos.keep();
}
}