blob: 4d5b81c3cc9ae0736e42632626f4d91ea7d00f58 [file] [log] [blame]
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: PJ Reiniger <pj.reiniger@gmail.com>
Date: Sun, 8 May 2022 16:46:20 -0400
Subject: [PATCH 19/31] Prefer fmtlib
---
llvm/lib/Support/ErrorHandling.cpp | 20 ++++++--------------
1 file changed, 6 insertions(+), 14 deletions(-)
diff --git a/llvm/lib/Support/ErrorHandling.cpp b/llvm/lib/Support/ErrorHandling.cpp
index 3a88178cfbbcf7062a958c7de820247bc913ab33..54137a331ca9e752b02c0f16ae996094a6f2fafa 100644
--- a/llvm/lib/Support/ErrorHandling.cpp
+++ b/llvm/lib/Support/ErrorHandling.cpp
@@ -22,7 +22,7 @@
#include "llvm/Support/Signals.h"
#include "llvm/Support/Threading.h"
#include "llvm/Support/WindowsError.h"
-#include "llvm/Support/raw_ostream.h"
+#include "fmt/format.h"
#include <cassert>
#include <cstdlib>
#include <mutex>
@@ -93,15 +93,7 @@ void llvm::report_fatal_error(std::string_view Reason, bool GenCrashDiag) {
if (handler) {
handler(handlerData, std::string{Reason}.c_str(), GenCrashDiag);
} else {
- // Blast the result out to stderr. We don't try hard to make sure this
- // succeeds (e.g. handling EINTR) and we can't use errs() here because
- // raw ostreams can call report_fatal_error.
- SmallVector<char, 64> Buffer;
- raw_svector_ostream OS(Buffer);
- OS << "LLVM ERROR: " << Reason << "\n";
- std::string_view MessageStr = OS.str();
- ssize_t written = ::write(2, MessageStr.data(), MessageStr.size());
- (void)written; // If something went wrong, we deliberately just give up.
+ fmt::print(stderr, "LLVM ERROR: {}\n", Reason);
}
// If we reached here, we are failing ungracefully. Run the interrupt handlers
@@ -176,11 +168,11 @@ void llvm::llvm_unreachable_internal(const char *msg, const char *file,
// llvm_unreachable is intended to be used to indicate "impossible"
// situations, and not legitimate runtime errors.
if (msg)
- dbgs() << msg << "\n";
- dbgs() << "UNREACHABLE executed";
+ fmt::print(stderr, "{}\n", msg);
+ std::fputs("UNREACHABLE executed", stderr);
if (file)
- dbgs() << " at " << file << ":" << line;
- dbgs() << "!\n";
+ fmt::print(stderr, " at {}:{}", file, line);
+ fmt::print(stderr, "!\n");
abort();
#ifdef LLVM_BUILTIN_UNREACHABLE
// Windows systems and possibly others don't declare abort() to be noreturn,