llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Yeoul Na (rapidsna) <details> <summary>Changes</summary> 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 --- Full diff: https://github.com/llvm/llvm-project/pull/239050.diff 3 Files Affected: - (modified) clang/include/clang/Parse/Parser.h (+5-4) - (modified) clang/include/clang/Sema/DeclSpec.h (+16-13) - (modified) clang/lib/Parse/ParseDecl.cpp (+3-3) ``````````diff 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(<A->Info); return true; } return false; `````````` </details> https://github.com/llvm/llvm-project/pull/239050 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
