[PATCH] D131337: Wrap `llvm_unreachable` macro in do-while loop
Stefan Gränitz via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 6 13:24:58 PDT 2022
sgraenitz created this revision.
sgraenitz added reviewers: mehdi_amini, dexonsmith, lhames.
Herald added a subscriber: StephenFan.
Herald added a project: All.
sgraenitz requested review of this revision.
Herald added a project: LLVM.
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)`.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D131337
Files:
llvm/include/llvm/Support/ErrorHandling.h
Index: llvm/include/llvm/Support/ErrorHandling.h
===================================================================
--- llvm/include/llvm/Support/ErrorHandling.h
+++ llvm/include/llvm/Support/ErrorHandling.h
@@ -147,7 +147,9 @@
#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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131337.450568.patch
Type: text/x-patch
Size: 525 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220806/7a4aa99b/attachment.bin>
More information about the llvm-commits
mailing list