[llvm-commits] [llvm] r111320 - /llvm/trunk/lib/Support/ErrorHandling.cpp

Chris Lattner sabre at nondot.org
Tue Aug 17 16:03:53 PDT 2010


Author: lattner
Date: Tue Aug 17 18:03:53 2010
New Revision: 111320

URL: http://llvm.org/viewvc/llvm-project?rev=111320&view=rev
Log:
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

Modified:
    llvm/trunk/lib/Support/ErrorHandling.cpp

Modified: llvm/trunk/lib/Support/ErrorHandling.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/ErrorHandling.cpp?rev=111320&r1=111319&r2=111320&view=diff
==============================================================================
--- llvm/trunk/lib/Support/ErrorHandling.cpp (original)
+++ llvm/trunk/lib/Support/ErrorHandling.cpp Tue Aug 17 18:03:53 2010
@@ -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 @@
   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





More information about the llvm-commits mailing list