summaryrefslogtreecommitdiff
path: root/lib/Support/ErrorHandling.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-08-17 23:03:53 +0000
committerChris Lattner <sabre@nondot.org>2010-08-17 23:03:53 +0000
commit73ebaff79f2a26d76cccd37d176f05f32b09ad2e (patch)
treedf85c468cec6ed9851e19b6467dafa009f2467c4 /lib/Support/ErrorHandling.cpp
parent68c23f861694f7b06df2ce39ced01d1d39fc5809 (diff)
downloadllvm-73ebaff79f2a26d76cccd37d176f05f32b09ad2e.tar.gz
llvm-73ebaff79f2a26d76cccd37d176f05f32b09ad2e.tar.bz2
llvm-73ebaff79f2a26d76cccd37d176f05f32b09ad2e.tar.xz
report_fatal_error can't use errs(), because errs() can call
into report_fatal_error. Just blast the string to stderr with write(2) and hope for the best! Part of rdar://8318441 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111320 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/ErrorHandling.cpp')
-rw-r--r--lib/Support/ErrorHandling.cpp34
1 files changed, 26 insertions, 8 deletions
diff --git a/lib/Support/ErrorHandling.cpp b/lib/Support/ErrorHandling.cpp
index 7e7ca9debe..c4d5ea4c3d 100644
--- a/lib/Support/ErrorHandling.cpp
+++ b/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 <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 +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<char, 64> 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