James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1 | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 2 | From: PJ Reiniger <pj.reiniger@gmail.com> |
| 3 | Date: Sun, 8 May 2022 16:46:20 -0400 |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 4 | Subject: [PATCH 19/31] Prefer fmtlib |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 5 | |
| 6 | --- |
| 7 | llvm/lib/Support/ErrorHandling.cpp | 20 ++++++-------------- |
| 8 | 1 file changed, 6 insertions(+), 14 deletions(-) |
| 9 | |
| 10 | diff --git a/llvm/lib/Support/ErrorHandling.cpp b/llvm/lib/Support/ErrorHandling.cpp |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 11 | index 3a88178cfbbcf7062a958c7de820247bc913ab33..54137a331ca9e752b02c0f16ae996094a6f2fafa 100644 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 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 |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 40 | @@ -176,11 +168,11 @@ void llvm::llvm_unreachable_internal(const char *msg, const char *file, |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 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, |