From: Mehdi Amini Date: Mon, 21 Mar 2022 19:57:40 +0000 (+0000) Subject: Adjust `llvm_unreachable` macro to account for platforms that don't define LLVM_BUILT... X-Git-Tag: upstream/15.0.7~12842 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=734b8eadd7d364d5d8162ba6f43539be3d7850aa;p=platform%2Fupstream%2Fllvm.git Adjust `llvm_unreachable` macro to account for platforms that don't define LLVM_BUILTIN_UNREACHABLE Post 892c104fb7, LLVM_BUILTIN_UNREACHABLE may not be defined anymore. Also when LLVM_UNREACHABLE_OPTIMIZE is OFF, emit LLVM_BUILTIN_UNREACHABLE after LLVM_BUILTIN_TRAP to ensure that diagnostics are suppressed on environments where LLVM_BUILTIN_TRAP is not marked as noreturn. Differential Revision: https://reviews.llvm.org/D122170 --- diff --git a/llvm/include/llvm/Support/ErrorHandling.h b/llvm/include/llvm/Support/ErrorHandling.h index 42dcf4b..004b3b7 100644 --- a/llvm/include/llvm/Support/ErrorHandling.h +++ b/llvm/include/llvm/Support/ErrorHandling.h @@ -124,7 +124,9 @@ llvm_unreachable_internal(const char *msg = nullptr, const char *file = nullptr, /// Marks that the current location is not supposed to be reachable. /// In !NDEBUG builds, prints the message and location info to stderr. -/// In NDEBUG builds, the behavior is controlled by the CMake flag +/// In NDEBUG builds, if the platform does not support a builtin unreachable +/// then we call an internal LLVM runtime function. Otherwise the behavior is +/// controlled by the CMake flag /// -DLLVM_UNREACHABLE_OPTIMIZE /// * When "ON" (default) llvm_unreachable() becomes an optimizer hint /// that the current location is not supposed to be reachable: the hint @@ -134,17 +136,18 @@ llvm_unreachable_internal(const char *msg = nullptr, const char *file = nullptr, /// * When "OFF", a builtin_trap is emitted instead of an // optimizer hint or printing a reduced message. /// -/// Use this instead of assert(0). It conveys intent more clearly and -/// allows compilers to omit some unnecessary code. +/// Use this instead of assert(0). It conveys intent more clearly, suppresses +/// diagnostics for unreachable code paths, and allows compilers to omit +/// unnecessary code. #ifndef NDEBUG #define llvm_unreachable(msg) \ ::llvm::llvm_unreachable_internal(msg, __FILE__, __LINE__) -#elif !LLVM_UNREACHABLE_OPTIMIZE -#define llvm_unreachable(msg) LLVM_BUILTIN_TRAP -#elif defined(LLVM_BUILTIN_UNREACHABLE) +#elif !defined(LLVM_BUILTIN_UNREACHABLE) +#define llvm_unreachable(msg) ::llvm::llvm_unreachable_internal() +#elif LLVM_UNREACHABLE_OPTIMIZE #define llvm_unreachable(msg) LLVM_BUILTIN_UNREACHABLE #else -#define llvm_unreachable(msg) ::llvm::llvm_unreachable_internal() +#define llvm_unreachable(msg) LLVM_BUILTIN_TRAP, LLVM_BUILTIN_UNREACHABLE #endif #endif