Skip to content

Commit 7a66fe1

Browse files
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. #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
1 parent b334709 commit 7a66fe1

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

llvm/include/llvm/Support/ErrorHandling.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,11 @@ llvm_unreachable_internal(const char *msg = nullptr, const char *file = nullptr,
147147
#elif LLVM_UNREACHABLE_OPTIMIZE
148148
#define llvm_unreachable(msg) LLVM_BUILTIN_UNREACHABLE
149149
#else
150-
#define llvm_unreachable(msg) LLVM_BUILTIN_TRAP, LLVM_BUILTIN_UNREACHABLE
150+
#define llvm_unreachable(msg) \
151+
do { \
152+
LLVM_BUILTIN_TRAP; \
153+
LLVM_BUILTIN_UNREACHABLE; \
154+
} while (false)
151155
#endif
152156

153157
#endif

0 commit comments

Comments
 (0)