diff --git a/llvm/lib/Support/ErrorHandling.cpp b/llvm/lib/Support/ErrorHandling.cpp index 7e7ca9debe9a..c4d5ea4c3db7 100644 --- a/llvm/lib/Support/ErrorHandling.cpp +++ b/llvm/lib/Support/ErrorHandling.cpp @@ -18,8 +18,18 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/System/Signals.h" #include "llvm/System/Threading.h" +#include "llvm/ADT/SmallVector.h" #include #include + +#if defined(HAVE_UNISTD_H) +# include +#endif +#if defined(_MSC_VER) +# include +# include +#endif + using namespace llvm; using namespace std; @@ -39,19 +49,27 @@ void llvm::remove_fatal_error_handler() { ErrorHandler = 0; } -void llvm::report_fatal_error(const char *reason) { - report_fatal_error(Twine(reason)); +void llvm::report_fatal_error(const char *Reason) { + report_fatal_error(Twine(Reason)); } -void llvm::report_fatal_error(const std::string &reason) { - report_fatal_error(Twine(reason)); +void llvm::report_fatal_error(const std::string &Reason) { + report_fatal_error(Twine(Reason)); } -void llvm::report_fatal_error(const Twine &reason) { - if (!ErrorHandler) { - errs() << "LLVM ERROR: " << reason << "\n"; +void llvm::report_fatal_error(const Twine &Reason) { + if (ErrorHandler) { + ErrorHandler(ErrorHandlerUserData, Reason.str()); } else { - ErrorHandler(ErrorHandlerUserData, reason.str()); + // 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 Buffer; + StringRef ReasonStr = Reason.toStringRef(Buffer); + + ::write(2, "LLVM ERROR: ", 12); + ::write(2, ReasonStr.data(), ReasonStr.size()); + ::write(2, "\n", 1); } // If we reached here, we are failing ungracefully. Run the interrupt handlers