[PATCH] D151148: [clang][ExprConstant] fix __builtin_object_size for compound literal

Eli Friedman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 22 15:48:58 PDT 2023


efriedma added inline comments.


================
Comment at: clang/lib/AST/ExprConstant.cpp:11737
     bool Ret = HandleSizeof(Info, ExprLoc, Ty, Result);
     if (Ty->isStructureType() &&
         Ty->getAsStructureType()->getDecl()->hasFlexibleArrayMember()) {
----------------
For the second call to CheckHandleSizeof (line 11791), is the type of consistent with the type of the variable?  If Ty refers to a field, I'm not sure it makes sense to call getFlexibleArrayInitChars().  Something along the lines of "struct Z { struct A { int x, y[]; } z; int a; };"


================
Comment at: clang/lib/AST/ExprConstant.cpp:11740
+      if (const auto *V = LVal.getLValueBase().dyn_cast<const ValueDecl *>())
+        Result += cast<VarDecl>(V)->getFlexibleArrayInitChars(Info.Ctx);
     }
----------------
I think I'd like to check `isa<VarDecl>` here to be on the safe side, even if I don't have a specific example where it would break.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151148/new/

https://reviews.llvm.org/D151148



More information about the cfe-commits mailing list