[clang] [BoundsSafety][NFC] Hold LateParsedTypeAttrInfo in declarator late-attribute lists (PR #239050)

Yeoul Na via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 4 17:05:46 PST 2026


https://github.com/rapidsna created https://github.com/llvm/llvm-project/pull/239050

Make DeclSpec, Declarator and DeclaratorChunk hold a SmallVector of LateParsedTypeAttrInfo * instead of a LateParsedAttrList.

LateParsedAttrList has inline storage for two pointers plus flags, which makes DeclaratorChunk larger. That may have caused the compile-time regression in #238909. The new list has no inline storage.

Sema also only has the definition of LateParsedTypeAttrInfo, not of LateParsedAttribute. Holding the former lets Sema build the type directly, without a callback into the parser.

No functional change: nothing populates or reads these lists yet.

Assisted-by: Sonnet 5.5

>From 98536db4b5bbcb08cc0ee208b8bd9a73d5182e6d Mon Sep 17 00:00:00 2001
From: Yeoul Na <yeoul_na at apple.com>
Date: Wed, 4 Nov 2026 13:43:46 -0800
Subject: [PATCH] [BoundsSafety][NFC] Hold LateParsedTypeAttrInfo in declarator
 late-attribute lists

Make DeclSpec, Declarator and DeclaratorChunk hold a SmallVector of
LateParsedTypeAttrInfo * instead of a LateParsedAttrList.

LateParsedAttrList has inline storage for two pointers plus flags, which
makes DeclaratorChunk larger. That may have caused the compile-time
regression in #238909. The new list has no inline storage.

Sema also only has the definition of LateParsedTypeAttrInfo, not of
LateParsedAttribute. Holding the former lets Sema build the type directly,
without a callback into the parser.

No functional change: nothing populates or reads these lists yet.

Assisted-by: Sonnet 5.5
---
 clang/include/clang/Parse/Parser.h  |  9 +++++----
 clang/include/clang/Sema/DeclSpec.h | 29 ++++++++++++++++-------------
 clang/lib/Parse/ParseDecl.cpp       |  6 +++---
 3 files changed, 24 insertions(+), 20 deletions(-)

diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h
index e4fa25ebc427f6..99276301482cc6 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -1544,10 +1544,11 @@ class Parser : public CodeCompletionHandler {
                                    ArrayRef<const DeclRefExpr *> ParamRefs,
                                    bool ReenteredProtoParams);
 
-  /// Helper function to move LateParsedTypeAttribute pointers from one list
-  /// to another. Filters type attributes from \p From and appends them to \p
-  /// To.
-  static void TakeTypeAttrsAppendingFrom(LateParsedAttrList &To,
+  /// Moves the late-parsed type attributes out of \p From, appending a pointer
+  /// to each one's LateParsedTypeAttrInfo to \p To. \p To does not own the
+  /// LateParsedTypeAttribute objects: the caller must keep them alive while
+  /// \p To is in use (in a C record, CurRecordLateParsedTypeAttrs does).
+  static void TakeTypeAttrsAppendingFrom(LateParsedTypeAttrInfoList &To,
                                          LateParsedAttrList &From);
 
   void ParseLexedPragmas(ParsingClass &Class);
diff --git a/clang/include/clang/Sema/DeclSpec.h b/clang/include/clang/Sema/DeclSpec.h
index a1fd6c8ef6adc8..f3e1dfa2d148e6 100644
--- a/clang/include/clang/Sema/DeclSpec.h
+++ b/clang/include/clang/Sema/DeclSpec.h
@@ -272,6 +272,11 @@ namespace clang {
         : Kind(Kind), NameLoc(NameLoc) {}
   };
 
+  /// The late-parsed type attributes of a declaration specifier, declarator or
+  /// declarator chunk, as Sema sees them. Almost always empty, so no inline
+  /// storage.
+  using LateParsedTypeAttrInfoList = SmallVector<LateParsedTypeAttrInfo *, 0>;
+
 /// Captures information about "declaration specifiers".
 ///
 /// "Declaration specifiers" encompasses storage-class-specifiers,
@@ -467,7 +472,7 @@ class DeclSpec {
   ParsedAttributes Attrs;
 
   // late attributes
-  LateParsedAttrList LateParsedAttrs;
+  LateParsedTypeAttrInfoList LateParsedAttrs;
 
   // Scope specifier for the type spec, if applicable.
   CXXScopeSpec TypeScope;
@@ -545,8 +550,7 @@ class DeclSpec {
         FS_virtual_specified(false), FS_noreturn_specified(false),
         FriendSpecifiedFirst(false), ConstexprSpecifier(static_cast<unsigned>(
                                          ConstexprSpecKind::Unspecified)),
-        Attrs(attrFactory), LateParsedAttrs(LateParsedAttrList::forTypeAttrs()),
-        writtenBS(), ObjCQualifiers(nullptr) {}
+        Attrs(attrFactory), writtenBS(), ObjCQualifiers(nullptr) {}
 
   // storage-class-specifier
   SCS getStorageClassSpec() const { return (SCS)StorageClassSpec; }
@@ -946,8 +950,8 @@ class DeclSpec {
   ParsedAttributes &getAttributes() { return Attrs; }
   const ParsedAttributes &getAttributes() const { return Attrs; }
 
-  LateParsedAttrList &getLateAttributes() { return LateParsedAttrs; }
-  const LateParsedAttrList &getLateAttributes() const {
+  LateParsedTypeAttrInfoList &getLateAttributes() { return LateParsedAttrs; }
+  const LateParsedTypeAttrInfoList &getLateAttributes() const {
     return LateParsedAttrs;
   }
 
@@ -1328,7 +1332,7 @@ class UnqualifiedId {
 ///
 /// This is intended to be a small value object.
 struct DeclaratorChunk {
-  DeclaratorChunk() : LateAttrList(LateParsedAttrList::forTypeAttrs()) {}
+  DeclaratorChunk() {};
 
   enum {
     Pointer, Reference, Array, Function, BlockPointer, MemberPointer, Paren, Pipe
@@ -1346,7 +1350,7 @@ struct DeclaratorChunk {
   }
 
   ParsedAttributesView AttrList;
-  LateParsedAttrList LateAttrList;
+  LateParsedTypeAttrInfoList LateAttrList;
 
   struct PointerTypeInfo {
     /// The type qualifiers: const/volatile/restrict/unaligned/atomic.
@@ -2059,7 +2063,7 @@ class Declarator {
   /// corresponding constructor parameter.
   const ParsedAttributesView &DeclarationAttrs;
 
-  LateParsedAttrList LateParsedAttrs;
+  LateParsedTypeAttrInfoList LateParsedAttrs;
 
   /// The asm label, if specified.
   Expr *AsmLabel;
@@ -2126,8 +2130,7 @@ class Declarator {
         Redeclaration(false), Extension(false), ObjCIvar(false),
         ObjCWeakProperty(false), InlineStorageUsed(false),
         HasInitializer(false), Attrs(DS.getAttributePool().getFactory()),
-        DeclarationAttrs(DeclarationAttrs),
-        LateParsedAttrs(LateParsedAttrList::forTypeAttrs()), AsmLabel(nullptr),
+        DeclarationAttrs(DeclarationAttrs), AsmLabel(nullptr),
         TrailingRequiresClause(nullptr),
         InventedTemplateParameterList(nullptr) {
     assert(llvm::all_of(DeclarationAttrs,
@@ -2452,7 +2455,7 @@ class Declarator {
   /// of those attributes from the parameter.
   void AddTypeInfo(const DeclaratorChunk &TI, ParsedAttributes &&attrs,
                    SourceLocation EndLoc,
-                   const LateParsedAttrList &LateAttrs = {}) {
+                   const LateParsedTypeAttrInfoList &LateAttrs = {}) {
     DeclTypeInfo.push_back(TI);
     DeclTypeInfo.back().getAttrs().prepend(attrs.begin(), attrs.end());
     getAttributePool().takeAllFrom(attrs.getPool());
@@ -2790,8 +2793,8 @@ class Declarator {
     return DeclarationAttrs;
   }
 
-  LateParsedAttrList &getLateAttributes() { return LateParsedAttrs; }
-  const LateParsedAttrList &getLateAttributes() const {
+  LateParsedTypeAttrInfoList &getLateAttributes() { return LateParsedAttrs; }
+  const LateParsedTypeAttrInfoList &getLateAttributes() const {
     return LateParsedAttrs;
   }
 
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 03252922458d04..4a739f73182c4e 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -4990,12 +4990,12 @@ void LateParsedTypeAttribute::ParseInto(ParsedAttributes &OutAttrs) {
   Self->ParseLexedTypeAttribute(*this, OutAttrs);
 }
 
-void Parser::TakeTypeAttrsAppendingFrom(LateParsedAttrList &To,
+void Parser::TakeTypeAttrsAppendingFrom(LateParsedTypeAttrInfoList &To,
                                         LateParsedAttrList &From) {
   LateParsedAttrList::iterator It =
       llvm::remove_if(From, [&](LateParsedAttribute *LA) {
-        if (isa<LateParsedTypeAttribute>(LA)) {
-          To.push_back(LA);
+        if (auto *LTA = dyn_cast<LateParsedTypeAttribute>(LA)) {
+          To.push_back(&LTA->Info);
           return true;
         }
         return false;



More information about the cfe-commits mailing list