[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

Yeoul Na via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 6 15:02:33 PST 2024


================
@@ -8463,133 +8463,110 @@ static void handleZeroCallUsedRegsAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
   D->addAttr(ZeroCallUsedRegsAttr::Create(S.Context, Kind, AL));
 }
 
-static void handleCountedByAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
-  if (!AL.isArgIdent(0)) {
-    S.Diag(AL.getLoc(), diag::err_attribute_argument_type)
-        << AL << AANT_ArgumentIdentifier;
-    return;
+static const RecordDecl *GetEnclosingNamedOrTopAnonRecord(const FieldDecl *FD) {
+  const auto *RD = FD->getParent();
+  while (RD && (RD->isAnonymousStructOrUnion() || RD->getName().empty())) {
----------------
rapidsna wrote:

> Are you sure this is processing after it's set?
@bwendling No, it doesn't, but I was initially meant to find the other struct that was already parsed like below. 
```
struct Parent {
  struct {
    int count;
  }; // anonymous struct
  int fam[__counted_by(count)]; // Sema is here
} ;
```
But now I'm looking at it, the logic needs to be fixed because it still doesn't tell us apart from: 
```
struct Parent {
  struct {
    int count;
  }; p // unnamed but non-anonymous struct
  int fam[__counted_by(count)]; // Sema is here
} ;
```

I'll fix that.

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


More information about the cfe-commits mailing list