[clang] [BoundsSafety][NFC] Introduce LateParsedTypeAttribute for late-parsed type attributes (PR #192799)

Henrik G. Olsson via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 21 21:19:51 PDT 2026


================
@@ -190,20 +190,63 @@ class LateParsedDeclaration {
 /// FIXME: Perhaps we should change the name of LateParsedDeclaration to
 /// LateParsedTokens.
 struct LateParsedAttribute : public LateParsedDeclaration {
+
+  enum LPA_Kind {
+    LPA_Declaration,
+    LPA_Type,
+  };
+
   Parser *Self;
   CachedTokens Toks;
   IdentifierInfo &AttrName;
   IdentifierInfo *MacroII = nullptr;
   SourceLocation AttrNameLoc;
   SmallVector<Decl *, 2> Decls;
 
+private:
+  LPA_Kind Kind;
+
+public:
   explicit LateParsedAttribute(Parser *P, IdentifierInfo &Name,
-                               SourceLocation Loc)
-      : Self(P), AttrName(Name), AttrNameLoc(Loc) {}
+                               SourceLocation Loc,
+                               LPA_Kind Kind = LPA_Declaration)
+      : Self(P), AttrName(Name), AttrNameLoc(Loc), Kind(Kind) {}
 
   void ParseLexedAttributes() override;
 
   void addDecl(Decl *D) { Decls.push_back(D); }
+
+  LPA_Kind getKind() const { return Kind; }
+
+  // LLVM-style RTTI support
+  static bool classof(const LateParsedAttribute *LA) {
+    // LateParsedAttribute matches both Declaration and Type kinds
+    return LA->getKind() == LPA_Declaration || LA->getKind() == LPA_Type;
+  }
+};
+
+/// A late-parsed attribute that will be applied as a type attribute.
+/// Unlike LateParsedAttribute (which applies to declarations via
+/// ActOnFinishDelayedAttribute), this stores cached tokens that are
+/// parsed during type construction when the placeholder LateParsedAttrType
+/// is replaced with a concrete type (e.g., CountAttributedType).
+struct LateParsedTypeAttribute : public LateParsedAttribute {
----------------
hnrklssn wrote:

The comment above makes me wonder whether `LateParsedTypeAttribute` is actually valid to use as a subtype of `LateParsedAttribute` (in the sense of Liskov substitution), or whether they ought to share a common ancestor type?

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


More information about the cfe-commits mailing list