[clang] [BoundsSafety] WIP: Make 'counted_by' work for pointer fields; late parsing for 'counted_by' on decl attr position (PR #87596)

Yeoul Na via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 23 10:29:56 PDT 2024


================
@@ -8547,15 +8547,25 @@ static const RecordDecl *GetEnclosingNamedOrTopAnonRecord(const FieldDecl *FD) {
   return RD;
 }
 
-static bool
-CheckCountExpr(Sema &S, FieldDecl *FD, Expr *E,
-               llvm::SmallVectorImpl<TypeCoupledDeclRefInfo> &Decls) {
+static bool CheckCountedByAttrOnField(
+    Sema &S, FieldDecl *FD, Expr *E,
+    llvm::SmallVectorImpl<TypeCoupledDeclRefInfo> &Decls) {
   if (FD->getParent()->isUnion()) {
     S.Diag(FD->getBeginLoc(), diag::err_counted_by_attr_in_union)
         << FD->getSourceRange();
     return true;
   }
 
+  const auto FieldTy = FD->getType();
+  if (FieldTy->isPointerType() &&
+      FieldTy->getPointeeType()->isIncompleteType()) {
----------------
rapidsna wrote:

`isIncompleteType()` won't be sufficient. We should also prevent a pointer to sizeless type, function type, and struct with flexible array member, etc.

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


More information about the cfe-commits mailing list