After converting assert(0) to LLVM_UNREACHABLE we lost file/line location.
authorTorok Edwin <edwintorok@gmail.com>
Tue, 14 Jul 2009 12:49:22 +0000 (12:49 +0000)
committerTorok Edwin <edwintorok@gmail.com>
Tue, 14 Jul 2009 12:49:22 +0000 (12:49 +0000)
Fix by making the LLVM_UNREACHABLE pass __FILE__ and __LINE__ to
llvm_unreachable.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75631 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/ErrorHandling.h
include/llvm/Support/PassNameParser.h
lib/Support/ErrorHandling.cpp

index 07faba758452ec87f79511ce50af39dbe850ea5e..c14eed98850b2e6ed4ae8fc7a3dea4061044761e 100644 (file)
@@ -49,11 +49,15 @@ namespace llvm {
   /// This function calls abort(), and prints the optional message to stderr.
   /// Call this instead of assert(0), so that compiler knows the path is not
   /// reachable even for NDEBUG builds.
-  void llvm_unreachable(const char *msg=0) NORETURN;
+  /// Use the LLVM_UNREACHABLE macro instead that adds location info.
+  void llvm_unreachable(const char *msg=0, const char *file=0,
+                        unsigned line=0) NORETURN;
 }
 
+/// Macro that calls llvm_unreachable with location info and message in 
+/// debug mode. In NDEBUG mode it calls llvm_unreachable with no message.
 #ifndef NDEBUG
-#define LLVM_UNREACHABLE(msg) llvm_unreachable(msg)
+#define LLVM_UNREACHABLE(msg) llvm_unreachable(msg, __FILE__, __LINE__)
 #else
 #define LLVM_UNREACHABLE(msg) llvm_unreachable()
 #endif
index 12c124074d71a4c321b16aa0b28a73f9bd0d6e4f..559dfd3e977a6a45841ece1ae3eacbcb74798aaf 100644 (file)
@@ -68,7 +68,7 @@ public:
     if (findOption(P->getPassArgument()) != getNumOptions()) {
       cerr << "Two passes with the same argument (-"
            << P->getPassArgument() << ") attempted to be registered!\n";
-      llvm_unreachable();
+      LLVM_UNREACHABLE(0);
     }
     addLiteralOption(P->getPassArgument(), P, P->getPassName());
   }
index f2e247c5274779868efd673b974b8c86c5514572..be0b3803f152e7630967b58a531a22b88eb92581 100644 (file)
@@ -44,9 +44,13 @@ void llvm_report_error(const std::string &reason) {
   exit(1);
 }
 
-void llvm_unreachable(const char *msg) {
+void llvm_unreachable(const char *msg, const char *file, unsigned line) {
   if (msg)
     errs() << msg << "\n";
+  errs() << "UNREACHABLE executed";
+  if (file)
+    errs() << " at " << file << ":" << line;
+  errs() << "!\n";
   abort();
 }
 }