[PATCH] D150892: [clang][ExprConstant] fix __builtin_object_size for flexible array members

Erich Keane via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu May 18 11:30:34 PDT 2023


erichkeane added inline comments.


================
Comment at: clang/lib/AST/ExprConstant.cpp:11740
+          LVal.getLValueBase().dyn_cast<const ValueDecl *>());
+      Result += VD->getFlexibleArrayInitChars(Info.Ctx);
+    }
----------------
nickdesaulniers wrote:
> erichkeane wrote:
> > Isn't this a possible null-deref?  
> I don't think so; in fact, I can use `cast` and `get` rather than `dyn_cast_or_null` and `dyn_cast` here.
> 
> Just because we have a pointer doesn't mean it's possibly `nullptr`; I don't think we can reach this code patch for evaluating the `__builtin_object_size` of a struct with a flexible array member if the LValue doesn't have a corresponding VarDecl.
Of course that is a possibility.  You shouldn't use dyn_cast right before a dereference, this should definitely be using `cast`/`get`, since they assert.

What does the LValue have when the dynamic struct does not have an initializer?  Or just an empty one? 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150892



More information about the cfe-commits mailing list