[llvm-branch-commits] [llvm] 8371a29 - Wrap `llvm_unreachable` macro in do-while loop
Tom Stellard via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Aug 8 15:51:07 PDT 2022
Author: Stefan Gränitz
Date: 2022-08-08T15:50:35-07:00
New Revision: 8371a291093ecd545fb6cb8d1de641f6d27847f9
URL: https://github.com/llvm/llvm-project/commit/8371a291093ecd545fb6cb8d1de641f6d27847f9
DIFF: https://github.com/llvm/llvm-project/commit/8371a291093ecd545fb6cb8d1de641f6d27847f9.diff
LOG: 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)
Added:
Modified:
llvm/include/llvm/Support/ErrorHandling.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/Support/ErrorHandling.h b/llvm/include/llvm/Support/ErrorHandling.h
index 004b3b7868fb5..9c8e3448f3a03 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
More information about the llvm-branch-commits
mailing list