diff options
author | Stefan Gränitz <stefan.graenitz@gmail.com> | 2022-08-04 13:58:26 +0200 |
---|---|---|
committer | Tom Stellard <tstellar@redhat.com> | 2022-08-08 15:50:35 -0700 |
commit | 8371a291093ecd545fb6cb8d1de641f6d27847f9 (patch) | |
tree | 234c73bdac4917ce68d5977cdbe9823989d5b78c | |
parent | d6e5bfce508af9e4c3f9b7357a00f7c02e94657c (diff) | |
download | llvm-8371a291093ecd545fb6cb8d1de641f6d27847f9.zip llvm-8371a291093ecd545fb6cb8d1de641f6d27847f9.tar.gz llvm-8371a291093ecd545fb6cb8d1de641f6d27847f9.tar.bz2 |
Wrap `llvm_unreachable` macro in do-while loop
Macros that expand into multiple terms can cause interesting preprocessor hickups depending
on the context they are used in. https://github.com/llvm/llvm-project/issues/56867 reported
a miscompilation of `llvm_unreachable(msg)` inside a `LLVM_DEBUG({ ... })` block. We were
able to fix it by wrapping the expansion in a `do {} while(false)`.
Differential Revision: https://reviews.llvm.org/D131337
(cherry picked from commit 7a66fe1075cfc7568554aeea9c40997dfb581979)
-rw-r--r-- | llvm/include/llvm/Support/ErrorHandling.h | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/llvm/include/llvm/Support/ErrorHandling.h b/llvm/include/llvm/Support/ErrorHandling.h index 004b3b7..9c8e344 100644 --- a/llvm/include/llvm/Support/ErrorHandling.h +++ b/llvm/include/llvm/Support/ErrorHandling.h @@ -147,7 +147,11 @@ llvm_unreachable_internal(const char *msg = nullptr, const char *file = nullptr, #elif LLVM_UNREACHABLE_OPTIMIZE #define llvm_unreachable(msg) LLVM_BUILTIN_UNREACHABLE #else -#define llvm_unreachable(msg) LLVM_BUILTIN_TRAP, LLVM_BUILTIN_UNREACHABLE +#define llvm_unreachable(msg) \ + do { \ + LLVM_BUILTIN_TRAP; \ + LLVM_BUILTIN_UNREACHABLE; \ + } while (false) #endif #endif |