[PATCH] D117301: [clang][NFC] Wrap TYPE_SWITCH in "do while (0)" in the interpreter
Owen Pan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 14 04:33:20 PST 2022
owenpan created this revision.
owenpan added reviewers: jfb, rsmith, RKSimon, nand.
owenpan added a project: clang.
owenpan requested review of this revision.
Herald added a subscriber: cfe-commits.
Wraps the expansion of TYPE_SWITCH of the constexpr interpreter
in `do { ... } while (0)` so that the macro can be used like this:
if (llvm::Optional<PrimType> T = Ctx.classify(FieldTy))
TYPE_SWITCH(*T, Ok &= ReturnValue<T>(FP.deref<T>(), Value));
else
Ok &= Composite(FieldTy, FP, Value);
This bug was found while testing D116316 <https://reviews.llvm.org/D116316>. See also this review comment <https://reviews.llvm.org/D64146?id=208520#inline-584131>.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D117301
Files:
clang/lib/AST/Interp/PrimType.h
Index: clang/lib/AST/Interp/PrimType.h
===================================================================
--- clang/lib/AST/Interp/PrimType.h
+++ clang/lib/AST/Interp/PrimType.h
@@ -83,18 +83,20 @@
#define TYPE_SWITCH_CASE(Name, B) \
case Name: { using T = PrimConv<Name>::T; do {B;} while(0); break; }
#define TYPE_SWITCH(Expr, B) \
- switch (Expr) { \
- TYPE_SWITCH_CASE(PT_Sint8, B) \
- TYPE_SWITCH_CASE(PT_Uint8, B) \
- TYPE_SWITCH_CASE(PT_Sint16, B) \
- TYPE_SWITCH_CASE(PT_Uint16, B) \
- TYPE_SWITCH_CASE(PT_Sint32, B) \
- TYPE_SWITCH_CASE(PT_Uint32, B) \
- TYPE_SWITCH_CASE(PT_Sint64, B) \
- TYPE_SWITCH_CASE(PT_Uint64, B) \
- TYPE_SWITCH_CASE(PT_Bool, B) \
- TYPE_SWITCH_CASE(PT_Ptr, B) \
- }
+ do { \
+ switch (Expr) { \
+ TYPE_SWITCH_CASE(PT_Sint8, B) \
+ TYPE_SWITCH_CASE(PT_Uint8, B) \
+ TYPE_SWITCH_CASE(PT_Sint16, B) \
+ TYPE_SWITCH_CASE(PT_Uint16, B) \
+ TYPE_SWITCH_CASE(PT_Sint32, B) \
+ TYPE_SWITCH_CASE(PT_Uint32, B) \
+ TYPE_SWITCH_CASE(PT_Sint64, B) \
+ TYPE_SWITCH_CASE(PT_Uint64, B) \
+ TYPE_SWITCH_CASE(PT_Bool, B) \
+ TYPE_SWITCH_CASE(PT_Ptr, B) \
+ } \
+ } while (0)
#define COMPOSITE_TYPE_SWITCH(Expr, B, D) \
switch (Expr) { \
TYPE_SWITCH_CASE(PT_Ptr, B) \
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117301.399953.patch
Type: text/x-patch
Size: 2624 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220114/fcd55185/attachment.bin>
More information about the cfe-commits
mailing list