blob: 4315754e098097b9f46b8630d3c6595e11680b21 [file] [log] [blame]
James Kuszmaulcf324122023-01-14 14:07:17 -08001From 8834260a9ee172311cc08d0b4e4e958bf36a260f Mon Sep 17 00:00:00 2001
2From: PJ Reiniger <pj.reiniger@gmail.com>
3Date: Sun, 8 May 2022 16:46:20 -0400
4Subject: [PATCH 20/28] Prefer fmtlib
5
6---
7 llvm/lib/Support/ErrorHandling.cpp | 20 ++++++--------------
8 1 file changed, 6 insertions(+), 14 deletions(-)
9
10diff --git a/llvm/lib/Support/ErrorHandling.cpp b/llvm/lib/Support/ErrorHandling.cpp
11index ec1a1633a..8de7b726d 100644
12--- a/llvm/lib/Support/ErrorHandling.cpp
13+++ b/llvm/lib/Support/ErrorHandling.cpp
14@@ -22,7 +22,7 @@
15 #include "llvm/Support/Signals.h"
16 #include "llvm/Support/Threading.h"
17 #include "llvm/Support/WindowsError.h"
18-#include "llvm/Support/raw_ostream.h"
19+#include "fmt/format.h"
20 #include <cassert>
21 #include <cstdlib>
22 #include <mutex>
23@@ -93,15 +93,7 @@ void llvm::report_fatal_error(std::string_view Reason, bool GenCrashDiag) {
24 if (handler) {
25 handler(handlerData, std::string{Reason}.c_str(), GenCrashDiag);
26 } else {
27- // Blast the result out to stderr. We don't try hard to make sure this
28- // succeeds (e.g. handling EINTR) and we can't use errs() here because
29- // raw ostreams can call report_fatal_error.
30- SmallVector<char, 64> Buffer;
31- raw_svector_ostream OS(Buffer);
32- OS << "LLVM ERROR: " << Reason << "\n";
33- std::string_view MessageStr = OS.str();
34- ssize_t written = ::write(2, MessageStr.data(), MessageStr.size());
35- (void)written; // If something went wrong, we deliberately just give up.
36+ fmt::print(stderr, "LLVM ERROR: {}\n", Reason);
37 }
38
39 // If we reached here, we are failing ungracefully. Run the interrupt handlers
40@@ -173,11 +165,11 @@ void llvm::llvm_unreachable_internal(const char *msg, const char *file,
41 // llvm_unreachable is intended to be used to indicate "impossible"
42 // situations, and not legitimate runtime errors.
43 if (msg)
44- dbgs() << msg << "\n";
45- dbgs() << "UNREACHABLE executed";
46+ fmt::print(stderr, "{}\n", msg);
47+ std::fputs("UNREACHABLE executed", stderr);
48 if (file)
49- dbgs() << " at " << file << ":" << line;
50- dbgs() << "!\n";
51+ fmt::print(stderr, " at {}:{}", file, line);
52+ fmt::print(stderr, "!\n");
53 abort();
54 #ifdef LLVM_BUILTIN_UNREACHABLE
55 // Windows systems and possibly others don't declare abort() to be noreturn,