[clang] [BoundsSafety][Sema] Allow `sized_by`/`sized_by_or_null` on pointers to structs with a flexible array member (PR #209603)

Dan Liew via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 15 02:40:36 PDT 2026


================
@@ -152,7 +152,8 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes,
     InvalidTypeKind = CountedByInvalidPointeeTypeKind::SIZELESS;
   } else if (PointeeTy->isFunctionType()) {
     InvalidTypeKind = CountedByInvalidPointeeTypeKind::FUNCTION;
-  } else if (PointeeTy->isStructureTypeWithFlexibleArrayMember()) {
+  } else if (PointeeTy->isStructureTypeWithFlexibleArrayMember() &&
+             !CountInBytes) {
----------------
delcypher wrote:

So I wrote it this way to have the same shape as the `PointeeTy->isAlwaysIncompleteType() && !CountInBytes` above. It would be odd rewrite this one and not the other. Doing the rewrite in this PR makes it less targeted so I'd rather not do it here. If we weren't forced to squash I would just do a second commit to do the rewrite. I'll just do it as a follow up commit.

https://github.com/llvm/llvm-project/pull/209603


More information about the cfe-commits mailing list