diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2010-09-17 15:48:55 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2010-09-17 15:48:55 +0000 | 
| commit | d39c594d39df7f283c2fb8a704a3f31c501180d9 (patch) | |
| tree | 36453626c792cccd91f783a38a169d610a6b9db9 /lib/Support/ErrorHandling.cpp | |
| parent | 6144c1de6a7674dad94290650e4e14f24d42e421 (diff) | |
Notes
Diffstat (limited to 'lib/Support/ErrorHandling.cpp')
| -rw-r--r-- | lib/Support/ErrorHandling.cpp | 34 | 
1 files changed, 26 insertions, 8 deletions
| diff --git a/lib/Support/ErrorHandling.cpp b/lib/Support/ErrorHandling.cpp index 7e7ca9debe9a7..0b7af3e5905be 100644 --- a/lib/Support/ErrorHandling.cpp +++ b/lib/Support/ErrorHandling.cpp @@ -18,8 +18,19 @@  #include "llvm/Support/raw_ostream.h"  #include "llvm/System/Signals.h"  #include "llvm/System/Threading.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/Config/config.h"  #include <cassert>  #include <cstdlib> + +#if defined(HAVE_UNISTD_H) +# include <unistd.h> +#endif +#if defined(_MSC_VER) +# include <io.h> +# include <fcntl.h> +#endif +  using namespace llvm;  using namespace std; @@ -39,19 +50,26 @@ 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<char, 64> Buffer; +    raw_svector_ostream OS(Buffer); +    OS << "LLVM ERROR: " << Reason << "\n"; +    StringRef MessageStr = OS.str(); +    (void)::write(2, MessageStr.data(), MessageStr.size());    }    // If we reached here, we are failing ungracefully. Run the interrupt handlers | 
