[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 7 09:43:29 PST 2025


================
@@ -102,7 +105,36 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes,
   // only `PointeeTy->isStructureTypeWithFlexibleArrayMember()` is reachable
   // when `FieldTy->isArrayType()`.
   bool ShouldWarn = false;
-  if (PointeeTy->isIncompleteType() && !CountInBytes) {
+  if (PointeeTy->isAlwaysIncompleteType() && !CountInBytes) {
----------------
AaronBallman wrote:

Perhaps silly question: did you consider a model where you track incomplete types or their checks to ensure they're completed before the end of the TU and issuing a diagnostic for any that remain incomplete at the end of the TU? We do this dance somewhat frequently: https://github.com/llvm/llvm-project/blob/0d9cf2671e06c9124a0b5fc753330c39c8b4a791/clang/lib/Sema/Sema.cpp#L1171

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


More information about the cfe-commits mailing list