diff options
| author | Andy Russell <arussell123@gmail.com> | 2018-10-12 15:35:55 -0400 |
|---|---|---|
| committer | Andy Russell <arussell123@gmail.com> | 2018-10-12 17:29:40 -0400 |
| commit | 00e1f5b8df5382a7296ba463a8e53ce55bf4c6a5 (patch) | |
| tree | 2ec2525efd16d091c0d6f3647f6c8c8aa29c5d74 /src/rustllvm/RustWrapper.cpp | |
| parent | e9e27e6a6258b3adf00a5dd35d2676656224880d (diff) | |
| download | rust-00e1f5b8df5382a7296ba463a8e53ce55bf4c6a5.tar.gz rust-00e1f5b8df5382a7296ba463a8e53ce55bf4c6a5.zip | |
exit with status code 101 on fatal LLVM error
Fixes #54992.
Diffstat (limited to 'src/rustllvm/RustWrapper.cpp')
| -rw-r--r-- | src/rustllvm/RustWrapper.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp index 2b1bf1c0290..bf7afa1b6c0 100644 --- a/src/rustllvm/RustWrapper.cpp +++ b/src/rustllvm/RustWrapper.cpp @@ -17,6 +17,7 @@ #include "llvm/Object/Archive.h" #include "llvm/Object/ObjectFile.h" #include "llvm/Bitcode/BitcodeWriterPass.h" +#include "llvm/Support/Signals.h" #include "llvm/IR/CallSite.h" @@ -26,6 +27,8 @@ #include <cstdlib> #endif +#include <iostream> + //===----------------------------------------------------------------------=== // // This file defines alternate interfaces to core functions that are more @@ -62,6 +65,27 @@ static AtomicOrdering fromRust(LLVMAtomicOrdering Ordering) { static LLVM_THREAD_LOCAL char *LastError; +// Custom error handler for fatal LLVM errors. +// +// Notably it exits the process with code 101, unlike LLVM's default of 1. +static void FatalErrorHandler(void *UserData, + const std::string& Reason, + bool GenCrashDiag) { + // Do the same thing that the default error handler does. + std::cerr << "LLVM ERROR: " << Reason << std::endl; + + // Since this error handler exits the process, we have to run any cleanup that + // LLVM would run after handling the error. This might change with an LLVM + // upgrade. + sys::RunInterruptHandlers(); + + exit(101); +} + +extern "C" void LLVMRustInstallFatalErrorHandler() { + install_fatal_error_handler(FatalErrorHandler); +} + extern "C" LLVMMemoryBufferRef LLVMRustCreateMemoryBufferWithContentsOfFile(const char *Path) { ErrorOr<std::unique_ptr<MemoryBuffer>> BufOr = |
