Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,17 @@ static AtomicOrdering fromRust(LLVMAtomicOrdering Ordering) {

static LLVM_THREAD_LOCAL char *LastError;

static std::mutex FatalErrorHandlerMutex;
static std::unique_lock<std::mutex> FatalErrorHandlerLock(FatalErrorHandlerMutex, std::defer_lock);
// 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 char* Reason,
bool GenCrashDiag) {
// Add a global lock to avoid re-entry here. When encountering an error,
// we only need and can only enter once.
FatalErrorHandlerLock.lock();
// Once upon a time we emitted "LLVM ERROR:" specifically to mimic LLVM. Then,
// we developed crater and other tools which only expose logs, not error codes.
// Use a more greppable prefix that will still match the "LLVM ERROR:" prefix.
Expand Down