================
@@ -8463,133 +8463,115 @@ 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();
+  // An unnamed struct is anonymous struct only if it's not instantiated.
+  // However, the struct may not be fully processed yet to determine
+  // whether it's anonymous or not. In that case, this function treats it as
+  // an anonymous struct and tries to find a named parent.
+  while (RD && (RD->isAnonymousStructOrUnion() ||
----------------
rapidsna wrote:

@bwendling I updated the logic so that it distinguishes between anonymous 
struct and unnamed struct that's still processing so whether it's anonymous 
struct is not determined yet. We treat it as anonymous struct here and what 
that means is that we couldn't handle the error case like below here: 

```
struct Parent {
  struct {
    int count;
  };
  struct {
    int dummy;
    int arr[__counted_by(count)]; // error: 'counted_by' field 'count' isn't 
within the same struct as the flexible array
  } unnamed_s; // anonymous struct
};
```

but such a remaining error case will be handled later in 
https://github.com/llvm/llvm-project/pull/78000/files#diff-bf37b284dfa0a76af702a5493cde01dec7f88619533c1be15e74654862299770R4841
 where the unnamed struct is determined whether it's actually anonymous or not.

https://github.com/llvm/llvm-project/pull/78000
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to