Make llvm_unreachable evaluate to __builtin_unreachable() in -Asserts
authorJohn McCall <rjmccall@apple.com>
Mon, 14 Mar 2011 20:01:21 +0000 (20:01 +0000)
committerJohn McCall <rjmccall@apple.com>
Mon, 14 Mar 2011 20:01:21 +0000 (20:01 +0000)
builds, which was the apparent consensus of PR8973 and llvmdev.

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

include/llvm/Support/Compiler.h
include/llvm/Support/ErrorHandling.h

index 67f0fd7e0dc6747989dece751db2fc74fcbf0a70..2d2a0b124abe4015bb0e19232639beb931967610 100644 (file)
   decl
 #endif
 
+// LLVM_BUILTIN_UNREACHABLE - On compilers which support it, expands
+// to an expression which states that it is undefined behavior for the
+// compiler to reach this point.
+#if defined(__clang__) || (__GNUC__ > 4) \
+ || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
+# define LLVM_BUILTIN_UNREACHABLE __builtin_unreachable()
+#else
+#ifdef __cplusplus
+extern "C" LLVM_ATTRIBUTE_NORETURN void abort();
+#else
+extern LLVM_ATTRIBUTE_NORETURN void abort();
+#endif
+# define LLVM_BUILTIN_UNREACHABLE abort()
+#endif
+
 #endif
index 5eca438d8b4ac034ff0c3fab629f3f5d47b292b7..fb0c88d8d8d22ed80a717388d8eeefb94003b2ef 100644 (file)
@@ -97,7 +97,7 @@ namespace llvm {
 #define llvm_unreachable(msg) \
   ::llvm::llvm_unreachable_internal(msg, __FILE__, __LINE__)
 #else
-#define llvm_unreachable(msg) ::llvm::llvm_unreachable_internal()
+#define llvm_unreachable(msg) LLVM_BUILTIN_UNREACHABLE
 #endif
 
 #endif