From dfb1520de70f3c56a74ee798180f9a82934fe40f Mon Sep 17 00:00:00 2001 From: "Henrik G. Olsson" Date: Wed, 8 Oct 2025 23:10:18 -0700 Subject: [PATCH 1/9] [attrs] Rename allAll, takeAllFrom etc. for clarity (NFC) This renames functions that prepend or append lists of attributes, to be explicit wrt whether they prepend or append. This should make it easier to spot mistakes, and no longer makes the prepend option seem like the default. --- clang/include/clang/Parse/Parser.h | 8 ++++---- clang/include/clang/Sema/DeclSpec.h | 14 +++++++------- clang/include/clang/Sema/ParsedAttr.h | 16 ++++++++-------- clang/lib/Parse/ParseDecl.cpp | 22 +++++++++++----------- clang/lib/Parse/ParseDeclCXX.cpp | 8 ++++---- clang/lib/Parse/ParseExprCXX.cpp | 2 +- clang/lib/Parse/ParseObjc.cpp | 10 +++++----- clang/lib/Parse/ParseStmt.cpp | 4 ++-- clang/lib/Parse/ParseTemplate.cpp | 2 +- clang/lib/Parse/Parser.cpp | 4 ++-- clang/lib/Sema/DeclSpec.cpp | 2 +- clang/lib/Sema/ParsedAttr.cpp | 2 +- clang/lib/Sema/SemaDecl.cpp | 2 +- 13 files changed, 48 insertions(+), 48 deletions(-) diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index e301cf1080977..9dda41a95bc90 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -2173,7 +2173,7 @@ class Parser : public CodeCompletionHandler { if (Tok.is(tok::kw___attribute)) { ParsedAttributes Attrs(AttrFactory); ParseGNUAttributes(Attrs, LateAttrs, &D); - D.takeAttributes(Attrs); + D.takeAttributesPrepend(Attrs); } } @@ -2272,7 +2272,7 @@ class Parser : public CodeCompletionHandler { if (isAllowedCXX11AttributeSpecifier()) { ParsedAttributes Attrs(AttrFactory); ParseCXX11Attributes(Attrs); - D.takeAttributes(Attrs); + D.takeAttributesPrepend(Attrs); } } @@ -2292,7 +2292,7 @@ class Parser : public CodeCompletionHandler { ParsedAttributes AttrsWithRange(AttrFactory); ParseMicrosoftAttributes(AttrsWithRange); AttrsParsed = !AttrsWithRange.empty(); - Attrs.takeAllFrom(AttrsWithRange); + Attrs.takeAllFromPrepend(AttrsWithRange); } return AttrsParsed; } @@ -5175,7 +5175,7 @@ class Parser : public CodeCompletionHandler { if (Tok.is(tok::colon)) { ParsedAttributes Attrs(AttrFactory); ParseHLSLAnnotations(Attrs, EndLoc, CouldBeBitField); - D.takeAttributes(Attrs); + D.takeAttributesPrepend(Attrs); return true; } return false; diff --git a/clang/include/clang/Sema/DeclSpec.h b/clang/include/clang/Sema/DeclSpec.h index c1a99a1fddc80..2d2ef9b363792 100644 --- a/clang/include/clang/Sema/DeclSpec.h +++ b/clang/include/clang/Sema/DeclSpec.h @@ -835,7 +835,7 @@ class DeclSpec { /// \endcode /// void addAttributes(const ParsedAttributesView &AL) { - Attrs.addAll(AL.begin(), AL.end()); + Attrs.addAllPrepend(AL.begin(), AL.end()); } bool hasAttributes() const { return !Attrs.empty(); } @@ -843,8 +843,8 @@ class DeclSpec { ParsedAttributes &getAttributes() { return Attrs; } const ParsedAttributes &getAttributes() const { return Attrs; } - void takeAttributesFrom(ParsedAttributes &attrs) { - Attrs.takeAllFrom(attrs); + void takeAttributesFromPrepend(ParsedAttributes &attrs) { + Attrs.takeAllFromPrepend(attrs); } /// Finish - This does final analysis of the declspec, issuing diagnostics for @@ -2327,7 +2327,7 @@ class Declarator { void AddTypeInfo(const DeclaratorChunk &TI, ParsedAttributes &&attrs, SourceLocation EndLoc) { DeclTypeInfo.push_back(TI); - DeclTypeInfo.back().getAttrs().addAll(attrs.begin(), attrs.end()); + DeclTypeInfo.back().getAttrs().addAllPrepend(attrs.begin(), attrs.end()); getAttributePool().takeAllFrom(attrs.getPool()); if (!EndLoc.isInvalid()) @@ -2638,7 +2638,7 @@ class Declarator { return InventedTemplateParameterList; } - /// takeAttributes - Takes attributes from the given parsed-attributes + /// takeAttributesPrepend - Takes attributes from the given parsed-attributes /// set and add them to this declarator. /// /// These examples both add 3 attributes to "var": @@ -2647,8 +2647,8 @@ class Declarator { /// __attribute__((common,deprecated)); /// /// Also extends the range of the declarator. - void takeAttributes(ParsedAttributes &attrs) { - Attrs.takeAllFrom(attrs); + void takeAttributesPrepend(ParsedAttributes &attrs) { + Attrs.takeAllFromPrepend(attrs); if (attrs.Range.getEnd().isValid()) SetRangeEnd(attrs.Range.getEnd()); diff --git a/clang/include/clang/Sema/ParsedAttr.h b/clang/include/clang/Sema/ParsedAttr.h index 2edee7eaa19a1..85b75742808a9 100644 --- a/clang/include/clang/Sema/ParsedAttr.h +++ b/clang/include/clang/Sema/ParsedAttr.h @@ -856,19 +856,19 @@ class ParsedAttributesView { friend class ParsedAttributesView; }; - void addAll(iterator B, iterator E) { + void addAllPrepend(iterator B, iterator E) { AttrList.insert(AttrList.begin(), B.I, E.I); } - void addAll(const_iterator B, const_iterator E) { + void addAllPrepend(const_iterator B, const_iterator E) { AttrList.insert(AttrList.begin(), B.I, E.I); } - void addAllAtEnd(iterator B, iterator E) { + void addAllAppend(iterator B, iterator E) { AttrList.insert(AttrList.end(), B.I, E.I); } - void addAllAtEnd(const_iterator B, const_iterator E) { + void addAllAppend(const_iterator B, const_iterator E) { AttrList.insert(AttrList.end(), B.I, E.I); } @@ -943,18 +943,18 @@ class ParsedAttributes : public ParsedAttributesView { AttributePool &getPool() const { return pool; } - void takeAllFrom(ParsedAttributes &Other) { + void takeAllFromPrepend(ParsedAttributes &Other) { assert(&Other != this && "ParsedAttributes can't take attributes from itself"); - addAll(Other.begin(), Other.end()); + addAllPrepend(Other.begin(), Other.end()); Other.clearListOnly(); pool.takeAllFrom(Other.pool); } - void takeAllAtEndFrom(ParsedAttributes &Other) { + void takeAllFromAppend(ParsedAttributes &Other) { assert(&Other != this && "ParsedAttributes can't take attributes from itself"); - addAllAtEnd(Other.begin(), Other.end()); + addAllAppend(Other.begin(), Other.end()); Other.clearListOnly(); pool.takeAllFrom(Other.pool); } diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index d6cd7eb8c2c3d..549280978b243 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -1934,12 +1934,12 @@ Parser::DeclGroupPtrTy Parser::ParseSimpleDeclaration( bool RequireSemi, ForRangeInit *FRI, SourceLocation *DeclSpecStart) { // Need to retain these for diagnostics before we add them to the DeclSepc. ParsedAttributesView OriginalDeclSpecAttrs; - OriginalDeclSpecAttrs.addAll(DeclSpecAttrs.begin(), DeclSpecAttrs.end()); + OriginalDeclSpecAttrs.addAllPrepend(DeclSpecAttrs.begin(), DeclSpecAttrs.end()); OriginalDeclSpecAttrs.Range = DeclSpecAttrs.Range; // Parse the common declaration-specifiers piece. ParsingDeclSpec DS(*this); - DS.takeAttributesFrom(DeclSpecAttrs); + DS.takeAttributesFromPrepend(DeclSpecAttrs); ParsedTemplateInfo TemplateInfo; DeclSpecContext DSContext = getDeclSpecContextFromDeclaratorContext(Context); @@ -2135,7 +2135,7 @@ Parser::DeclGroupPtrTy Parser::ParseDeclGroup(ParsingDeclSpec &DS, // list. This ensures that we will not attempt to interpret them as statement // attributes higher up the callchain. ParsedAttributes LocalAttrs(AttrFactory); - LocalAttrs.takeAllFrom(Attrs); + LocalAttrs.takeAllFromPrepend(Attrs); ParsingDeclarator D(*this, DS, LocalAttrs, Context); if (TemplateInfo.TemplateParams) D.setTemplateParameterLists(*TemplateInfo.TemplateParams); @@ -3462,7 +3462,7 @@ void Parser::ParseDeclarationSpecifiers( PA.setInvalid(); } - DS.takeAttributesFrom(attrs); + DS.takeAttributesFromPrepend(attrs); } // If this is not a declaration specifier token, we're done reading decl @@ -3689,7 +3689,7 @@ void Parser::ParseDeclarationSpecifiers( if (ParseImplicitInt(DS, &SS, TemplateInfo, AS, DSContext, Attrs)) { if (!Attrs.empty()) { AttrsLastTime = true; - attrs.takeAllFrom(Attrs); + attrs.takeAllFromPrepend(Attrs); } continue; } @@ -3854,7 +3854,7 @@ void Parser::ParseDeclarationSpecifiers( if (ParseImplicitInt(DS, nullptr, TemplateInfo, AS, DSContext, Attrs)) { if (!Attrs.empty()) { AttrsLastTime = true; - attrs.takeAllFrom(Attrs); + attrs.takeAllFromPrepend(Attrs); } continue; } @@ -4463,7 +4463,7 @@ void Parser::ParseDeclarationSpecifiers( // take them over and handle them here. if (!Attributes.empty()) { AttrsLastTime = true; - attrs.takeAllFrom(Attributes); + attrs.takeAllFromPrepend(Attributes); } continue; } @@ -4830,7 +4830,7 @@ void Parser::ParseLexedCAttribute(LateParsedAttribute &LA, bool EnterScope, ConsumeAnyToken(); if (OutAttrs) { - OutAttrs->takeAllFrom(Attrs); + OutAttrs->takeAllFromPrepend(Attrs); } } @@ -6122,7 +6122,7 @@ void Parser::ParseTypeQualifierListOpt( isAllowedCXX11AttributeSpecifier()) { ParsedAttributes Attrs(AttrFactory); ParseCXX11Attributes(Attrs); - DS.takeAttributesFrom(Attrs); + DS.takeAttributesFromPrepend(Attrs); } SourceLocation EndLoc; @@ -7483,7 +7483,7 @@ void Parser::ParseParameterDeclarationClause( // Take them so that we only apply the attributes to the first parameter. // We have already started parsing the decl-specifier sequence, so don't // parse any parameter-declaration pieces that precede it. - ArgDeclSpecAttrs.takeAllFrom(FirstArgAttrs); + ArgDeclSpecAttrs.takeAllFromPrepend(FirstArgAttrs); } else { // Parse any C++11 attributes. MaybeParseCXX11Attributes(ArgDeclAttrs); @@ -7505,7 +7505,7 @@ void Parser::ParseParameterDeclarationClause( DeclSpecContext::DSC_normal, /*LateAttrs=*/nullptr, AllowImplicitTypename); - DS.takeAttributesFrom(ArgDeclSpecAttrs); + DS.takeAttributesFromPrepend(ArgDeclSpecAttrs); // Parse the declarator. This is "PrototypeContext" or // "LambdaExprParameterContext", because we must accept either diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index 19f94122f151e..a5c7674c7d4ff 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -739,7 +739,7 @@ Parser::DeclGroupPtrTy Parser::ParseUsingDeclaration( << FixItHint::CreateInsertionFromRange( Tok.getLocation(), CharSourceRange::getTokenRange(Range)) << FixItHint::CreateRemoval(Range); - Attrs.takeAllFrom(MisplacedAttrs); + Attrs.takeAllFromPrepend(MisplacedAttrs); } // Maybe this is an alias-declaration. @@ -787,7 +787,7 @@ Parser::DeclGroupPtrTy Parser::ParseUsingDeclaration( // Parse (optional) attributes. MaybeParseAttributes(PAKM_GNU | PAKM_CXX11, Attrs); DiagnoseCXX11AttributeExtension(Attrs); - Attrs.addAll(PrefixAttrs.begin(), PrefixAttrs.end()); + Attrs.addAllPrepend(PrefixAttrs.begin(), PrefixAttrs.end()); if (InvalidDeclarator) SkipUntil(tok::comma, tok::semi, StopBeforeMatch); @@ -1948,7 +1948,7 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind, // Recover by adding misplaced attributes to the attribute list // of the class so they can be applied on the class later. - attrs.takeAllFrom(Attributes); + attrs.takeAllFromPrepend(Attributes); } } @@ -2842,7 +2842,7 @@ Parser::DeclGroupPtrTy Parser::ParseCXXClassMemberDeclaration( // decl-specifier-seq: // Parse the common declaration-specifiers piece. ParsingDeclSpec DS(*this, TemplateDiags); - DS.takeAttributesFrom(DeclSpecAttrs); + DS.takeAttributesFromPrepend(DeclSpecAttrs); if (MalformedTypeSpec) DS.SetTypeSpecError(); diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp index a2c69578d5087..2d2ac5984cf6a 100644 --- a/clang/lib/Parse/ParseExprCXX.cpp +++ b/clang/lib/Parse/ParseExprCXX.cpp @@ -1244,7 +1244,7 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer( break; } - D.takeAttributes(Attributes); + D.takeAttributesPrepend(Attributes); } MultiParseScope TemplateParamScope(*this); diff --git a/clang/lib/Parse/ParseObjc.cpp b/clang/lib/Parse/ParseObjc.cpp index a64fb02294c5a..c2dbc4edf0c3c 100644 --- a/clang/lib/Parse/ParseObjc.cpp +++ b/clang/lib/Parse/ParseObjc.cpp @@ -43,7 +43,7 @@ void Parser::MaybeSkipAttributes(tok::ObjCKeywordKind Kind) { Parser::DeclGroupPtrTy Parser::ParseObjCAtDirectives(ParsedAttributes &DeclAttrs, ParsedAttributes &DeclSpecAttrs) { - DeclAttrs.takeAllFrom(DeclSpecAttrs); + DeclAttrs.takeAllFromPrepend(DeclSpecAttrs); SourceLocation AtLoc = ConsumeToken(); // the "@" @@ -1065,7 +1065,7 @@ void Parser::ParseObjCTypeQualifierList(ObjCDeclSpec &DS, /// Take all the decl attributes out of the given list and add /// them to the given attribute set. -static void takeDeclAttributes(ParsedAttributesView &attrs, +static void takeDeclAttributesAppend(ParsedAttributesView &attrs, ParsedAttributesView &from) { for (auto &AL : llvm::reverse(from)) { if (!AL.isUsedAsTypeAttr()) { @@ -1088,10 +1088,10 @@ static void takeDeclAttributes(ParsedAttributes &attrs, attrs.getPool().takeAllFrom(D.getDeclSpec().getAttributePool()); // Now actually move the attributes over. - takeDeclAttributes(attrs, D.getMutableDeclSpec().getAttributes()); - takeDeclAttributes(attrs, D.getAttributes()); + takeDeclAttributesAppend(attrs, D.getMutableDeclSpec().getAttributes()); + takeDeclAttributesAppend(attrs, D.getAttributes()); for (unsigned i = 0, e = D.getNumTypeObjects(); i != e; ++i) - takeDeclAttributes(attrs, D.getTypeObject(i).getAttrs()); + takeDeclAttributesAppend(attrs, D.getTypeObject(i).getAttrs()); } ParsedType Parser::ParseObjCTypeName(ObjCDeclSpec &DS, diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp index 2e7af1219547e..9a7b830cae5ba 100644 --- a/clang/lib/Parse/ParseStmt.cpp +++ b/clang/lib/Parse/ParseStmt.cpp @@ -718,7 +718,7 @@ StmtResult Parser::ParseLabeledStatement(ParsedAttributes &Attrs, // and followed by a semicolon, GCC will reject (it appears to parse the // attributes as part of a statement in that case). That looks like a bug. if (!getLangOpts().CPlusPlus || Tok.is(tok::semi)) - Attrs.takeAllFrom(TempAttrs); + Attrs.takeAllFromPrepend(TempAttrs); else { StmtVector Stmts; ParsedAttributes EmptyCXX11Attrs(AttrFactory); @@ -2407,7 +2407,7 @@ StmtResult Parser::ParsePragmaLoopHint(StmtVector &Stmts, Stmts, StmtCtx, TrailingElseLoc, Attrs, EmptyDeclSpecAttrs, PrecedingLabel); - Attrs.takeAllFrom(TempAttrs); + Attrs.takeAllFromPrepend(TempAttrs); // Start of attribute range may already be set for some invalid input. // See PR46336. diff --git a/clang/lib/Parse/ParseTemplate.cpp b/clang/lib/Parse/ParseTemplate.cpp index 74aff0b804057..7c538fdd4b670 100644 --- a/clang/lib/Parse/ParseTemplate.cpp +++ b/clang/lib/Parse/ParseTemplate.cpp @@ -196,7 +196,7 @@ Parser::DeclGroupPtrTy Parser::ParseDeclarationAfterTemplate( ParsingDeclSpec DS(*this, &DiagsFromTParams); DS.SetRangeStart(DeclSpecAttrs.Range.getBegin()); DS.SetRangeEnd(DeclSpecAttrs.Range.getEnd()); - DS.takeAttributesFrom(DeclSpecAttrs); + DS.takeAttributesFromPrepend(DeclSpecAttrs); ParseDeclarationSpecifiers(DS, TemplateInfo, AS, getDeclSpecContextFromDeclaratorContext(Context)); diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index a17398b84c6a6..81f9cff9cac71 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -1083,7 +1083,7 @@ Parser::DeclGroupPtrTy Parser::ParseDeclOrFunctionDefInternal( "expected uninitialised source range"); DS.SetRangeStart(DeclSpecAttrs.Range.getBegin()); DS.SetRangeEnd(DeclSpecAttrs.Range.getEnd()); - DS.takeAttributesFrom(DeclSpecAttrs); + DS.takeAttributesFromPrepend(DeclSpecAttrs); ParsedTemplateInfo TemplateInfo; MaybeParseMicrosoftAttributes(DS.getAttributes()); @@ -1155,7 +1155,7 @@ Parser::DeclGroupPtrTy Parser::ParseDeclOrFunctionDefInternal( } DS.abort(); - DS.takeAttributesFrom(Attrs); + DS.takeAttributesFromPrepend(Attrs); const char *PrevSpec = nullptr; unsigned DiagID; diff --git a/clang/lib/Sema/DeclSpec.cpp b/clang/lib/Sema/DeclSpec.cpp index 8756ce5f0d850..f086c5d489f4c 100644 --- a/clang/lib/Sema/DeclSpec.cpp +++ b/clang/lib/Sema/DeclSpec.cpp @@ -197,7 +197,7 @@ DeclaratorChunk DeclaratorChunk::getFunction(bool hasProto, [&](DeclSpec::TQ TypeQual, StringRef PrintName, SourceLocation SL) { I.Fun.MethodQualifiers->SetTypeQual(TypeQual, SL); }); - I.Fun.MethodQualifiers->getAttributes().takeAllFrom(attrs); + I.Fun.MethodQualifiers->getAttributes().takeAllFromPrepend(attrs); I.Fun.MethodQualifiers->getAttributePool().takeAllFrom(attrs.getPool()); } diff --git a/clang/lib/Sema/ParsedAttr.cpp b/clang/lib/Sema/ParsedAttr.cpp index 294f88eae931c..42fa2af65b04f 100644 --- a/clang/lib/Sema/ParsedAttr.cpp +++ b/clang/lib/Sema/ParsedAttr.cpp @@ -304,7 +304,7 @@ bool ParsedAttr::checkAtMostNumArgs(Sema &S, unsigned Num) const { void clang::takeAndConcatenateAttrs(ParsedAttributes &First, ParsedAttributes &&Second) { - First.takeAllAtEndFrom(Second); + First.takeAllFromAppend(Second); if (!First.Range.getBegin().isValid()) First.Range.setBegin(Second.Range.getBegin()); diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 6eaf7b9435491..a60a313e7747f 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -14637,7 +14637,7 @@ StmtResult Sema::ActOnCXXForRangeIdentifier(Scope *S, SourceLocation IdentLoc, Declarator D(DS, ParsedAttributesView::none(), DeclaratorContext::ForInit); D.SetIdentifier(Ident, IdentLoc); - D.takeAttributes(Attrs); + D.takeAttributesPrepend(Attrs); D.AddTypeInfo(DeclaratorChunk::getReference(0, IdentLoc, /*lvalue*/ false), IdentLoc); From 8c99cbb9df4e6a4dc81be556d804c3e6175a497d Mon Sep 17 00:00:00 2001 From: "Henrik G. Olsson" Date: Thu, 9 Oct 2025 10:50:49 -0700 Subject: [PATCH 2/9] [sema] Append attributes parsed later, instead of prepending To make sure attributes occur the order they are parsed (for consistent diagnostics), the most recently parsed attributes should be appended rather than prepended. --- clang/include/clang/Parse/Parser.h | 8 ++++---- clang/include/clang/Sema/DeclSpec.h | 8 ++++---- clang/lib/Parse/ParseDecl.cpp | 16 ++++++++-------- clang/lib/Parse/ParseDeclCXX.cpp | 4 ++-- clang/lib/Parse/ParseExprCXX.cpp | 2 +- clang/lib/Parse/ParseStmt.cpp | 2 +- clang/lib/Parse/ParseTemplate.cpp | 2 +- clang/lib/Parse/Parser.cpp | 4 ++-- clang/lib/Sema/SemaDecl.cpp | 2 +- clang/test/Sema/internal_linkage.c | 2 +- 10 files changed, 25 insertions(+), 25 deletions(-) diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index 9dda41a95bc90..5fc70ebb39930 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -2173,7 +2173,7 @@ class Parser : public CodeCompletionHandler { if (Tok.is(tok::kw___attribute)) { ParsedAttributes Attrs(AttrFactory); ParseGNUAttributes(Attrs, LateAttrs, &D); - D.takeAttributesPrepend(Attrs); + D.takeAttributesAppend(Attrs); } } @@ -2272,7 +2272,7 @@ class Parser : public CodeCompletionHandler { if (isAllowedCXX11AttributeSpecifier()) { ParsedAttributes Attrs(AttrFactory); ParseCXX11Attributes(Attrs); - D.takeAttributesPrepend(Attrs); + D.takeAttributesAppend(Attrs); } } @@ -2292,7 +2292,7 @@ class Parser : public CodeCompletionHandler { ParsedAttributes AttrsWithRange(AttrFactory); ParseMicrosoftAttributes(AttrsWithRange); AttrsParsed = !AttrsWithRange.empty(); - Attrs.takeAllFromPrepend(AttrsWithRange); + Attrs.takeAllFromAppend(AttrsWithRange); } return AttrsParsed; } @@ -5175,7 +5175,7 @@ class Parser : public CodeCompletionHandler { if (Tok.is(tok::colon)) { ParsedAttributes Attrs(AttrFactory); ParseHLSLAnnotations(Attrs, EndLoc, CouldBeBitField); - D.takeAttributesPrepend(Attrs); + D.takeAttributesAppend(Attrs); return true; } return false; diff --git a/clang/include/clang/Sema/DeclSpec.h b/clang/include/clang/Sema/DeclSpec.h index 2d2ef9b363792..4b52fc02088a0 100644 --- a/clang/include/clang/Sema/DeclSpec.h +++ b/clang/include/clang/Sema/DeclSpec.h @@ -843,8 +843,8 @@ class DeclSpec { ParsedAttributes &getAttributes() { return Attrs; } const ParsedAttributes &getAttributes() const { return Attrs; } - void takeAttributesFromPrepend(ParsedAttributes &attrs) { - Attrs.takeAllFromPrepend(attrs); + void takeAttributesFromAppend(ParsedAttributes &attrs) { + Attrs.takeAllFromAppend(attrs); } /// Finish - This does final analysis of the declspec, issuing diagnostics for @@ -2647,8 +2647,8 @@ class Declarator { /// __attribute__((common,deprecated)); /// /// Also extends the range of the declarator. - void takeAttributesPrepend(ParsedAttributes &attrs) { - Attrs.takeAllFromPrepend(attrs); + void takeAttributesAppend(ParsedAttributes &attrs) { + Attrs.takeAllFromAppend(attrs); if (attrs.Range.getEnd().isValid()) SetRangeEnd(attrs.Range.getEnd()); diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 549280978b243..a6dd47ba85409 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -1939,7 +1939,7 @@ Parser::DeclGroupPtrTy Parser::ParseSimpleDeclaration( // Parse the common declaration-specifiers piece. ParsingDeclSpec DS(*this); - DS.takeAttributesFromPrepend(DeclSpecAttrs); + DS.takeAttributesFromAppend(DeclSpecAttrs); ParsedTemplateInfo TemplateInfo; DeclSpecContext DSContext = getDeclSpecContextFromDeclaratorContext(Context); @@ -3462,7 +3462,7 @@ void Parser::ParseDeclarationSpecifiers( PA.setInvalid(); } - DS.takeAttributesFromPrepend(attrs); + DS.takeAttributesFromAppend(attrs); } // If this is not a declaration specifier token, we're done reading decl @@ -3689,7 +3689,7 @@ void Parser::ParseDeclarationSpecifiers( if (ParseImplicitInt(DS, &SS, TemplateInfo, AS, DSContext, Attrs)) { if (!Attrs.empty()) { AttrsLastTime = true; - attrs.takeAllFromPrepend(Attrs); + attrs.takeAllFromAppend(Attrs); } continue; } @@ -3854,7 +3854,7 @@ void Parser::ParseDeclarationSpecifiers( if (ParseImplicitInt(DS, nullptr, TemplateInfo, AS, DSContext, Attrs)) { if (!Attrs.empty()) { AttrsLastTime = true; - attrs.takeAllFromPrepend(Attrs); + attrs.takeAllFromAppend(Attrs); } continue; } @@ -4463,7 +4463,7 @@ void Parser::ParseDeclarationSpecifiers( // take them over and handle them here. if (!Attributes.empty()) { AttrsLastTime = true; - attrs.takeAllFromPrepend(Attributes); + attrs.takeAllFromAppend(Attributes); } continue; } @@ -4830,7 +4830,7 @@ void Parser::ParseLexedCAttribute(LateParsedAttribute &LA, bool EnterScope, ConsumeAnyToken(); if (OutAttrs) { - OutAttrs->takeAllFromPrepend(Attrs); + OutAttrs->takeAllFromAppend(Attrs); } } @@ -6122,7 +6122,7 @@ void Parser::ParseTypeQualifierListOpt( isAllowedCXX11AttributeSpecifier()) { ParsedAttributes Attrs(AttrFactory); ParseCXX11Attributes(Attrs); - DS.takeAttributesFromPrepend(Attrs); + DS.takeAttributesFromAppend(Attrs); } SourceLocation EndLoc; @@ -7505,7 +7505,7 @@ void Parser::ParseParameterDeclarationClause( DeclSpecContext::DSC_normal, /*LateAttrs=*/nullptr, AllowImplicitTypename); - DS.takeAttributesFromPrepend(ArgDeclSpecAttrs); + DS.takeAttributesFromAppend(ArgDeclSpecAttrs); // Parse the declarator. This is "PrototypeContext" or // "LambdaExprParameterContext", because we must accept either diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index a5c7674c7d4ff..9c7e3a9e56901 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -1948,7 +1948,7 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind, // Recover by adding misplaced attributes to the attribute list // of the class so they can be applied on the class later. - attrs.takeAllFromPrepend(Attributes); + attrs.takeAllFromAppend(Attributes); } } @@ -2842,7 +2842,7 @@ Parser::DeclGroupPtrTy Parser::ParseCXXClassMemberDeclaration( // decl-specifier-seq: // Parse the common declaration-specifiers piece. ParsingDeclSpec DS(*this, TemplateDiags); - DS.takeAttributesFromPrepend(DeclSpecAttrs); + DS.takeAttributesFromAppend(DeclSpecAttrs); if (MalformedTypeSpec) DS.SetTypeSpecError(); diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp index 2d2ac5984cf6a..cb0d2a000994a 100644 --- a/clang/lib/Parse/ParseExprCXX.cpp +++ b/clang/lib/Parse/ParseExprCXX.cpp @@ -1244,7 +1244,7 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer( break; } - D.takeAttributesPrepend(Attributes); + D.takeAttributesAppend(Attributes); } MultiParseScope TemplateParamScope(*this); diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp index 9a7b830cae5ba..7ac0d335a6555 100644 --- a/clang/lib/Parse/ParseStmt.cpp +++ b/clang/lib/Parse/ParseStmt.cpp @@ -718,7 +718,7 @@ StmtResult Parser::ParseLabeledStatement(ParsedAttributes &Attrs, // and followed by a semicolon, GCC will reject (it appears to parse the // attributes as part of a statement in that case). That looks like a bug. if (!getLangOpts().CPlusPlus || Tok.is(tok::semi)) - Attrs.takeAllFromPrepend(TempAttrs); + Attrs.takeAllFromAppend(TempAttrs); else { StmtVector Stmts; ParsedAttributes EmptyCXX11Attrs(AttrFactory); diff --git a/clang/lib/Parse/ParseTemplate.cpp b/clang/lib/Parse/ParseTemplate.cpp index 7c538fdd4b670..b9f691597a736 100644 --- a/clang/lib/Parse/ParseTemplate.cpp +++ b/clang/lib/Parse/ParseTemplate.cpp @@ -196,7 +196,7 @@ Parser::DeclGroupPtrTy Parser::ParseDeclarationAfterTemplate( ParsingDeclSpec DS(*this, &DiagsFromTParams); DS.SetRangeStart(DeclSpecAttrs.Range.getBegin()); DS.SetRangeEnd(DeclSpecAttrs.Range.getEnd()); - DS.takeAttributesFromPrepend(DeclSpecAttrs); + DS.takeAttributesFromAppend(DeclSpecAttrs); ParseDeclarationSpecifiers(DS, TemplateInfo, AS, getDeclSpecContextFromDeclaratorContext(Context)); diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index 81f9cff9cac71..e13bfacadd5c2 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -1083,7 +1083,7 @@ Parser::DeclGroupPtrTy Parser::ParseDeclOrFunctionDefInternal( "expected uninitialised source range"); DS.SetRangeStart(DeclSpecAttrs.Range.getBegin()); DS.SetRangeEnd(DeclSpecAttrs.Range.getEnd()); - DS.takeAttributesFromPrepend(DeclSpecAttrs); + DS.takeAttributesFromAppend(DeclSpecAttrs); ParsedTemplateInfo TemplateInfo; MaybeParseMicrosoftAttributes(DS.getAttributes()); @@ -1155,7 +1155,7 @@ Parser::DeclGroupPtrTy Parser::ParseDeclOrFunctionDefInternal( } DS.abort(); - DS.takeAttributesFromPrepend(Attrs); + DS.takeAttributesFromAppend(Attrs); const char *PrevSpec = nullptr; unsigned DiagID; diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index a60a313e7747f..24d80c3c08a96 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -14637,7 +14637,7 @@ StmtResult Sema::ActOnCXXForRangeIdentifier(Scope *S, SourceLocation IdentLoc, Declarator D(DS, ParsedAttributesView::none(), DeclaratorContext::ForInit); D.SetIdentifier(Ident, IdentLoc); - D.takeAttributesPrepend(Attrs); + D.takeAttributesAppend(Attrs); D.AddTypeInfo(DeclaratorChunk::getReference(0, IdentLoc, /*lvalue*/ false), IdentLoc); diff --git a/clang/test/Sema/internal_linkage.c b/clang/test/Sema/internal_linkage.c index a1bff73fb6620..4ea8599039c14 100644 --- a/clang/test/Sema/internal_linkage.c +++ b/clang/test/Sema/internal_linkage.c @@ -20,7 +20,7 @@ struct __attribute__((internal_linkage)) S { // expected-warning{{'internal_link __attribute__((internal_linkage("foo"))) int g(void) {} // expected-error{{'internal_linkage' attribute takes no arguments}} int var6 [[clang::internal_linkage]]; -int var7 [[clang::internal_linkage]] __attribute__((common)); // expected-error{{'clang::internal_linkage' and 'common' attributes are not compatible}} \ +int var7 [[clang::internal_linkage]] __attribute__((common)); // expected-error{{'common' and 'clang::internal_linkage' attributes are not compatible}} \ // expected-note{{conflicting attribute is here}} __attribute__((common)) int var8 [[clang::internal_linkage]]; // expected-error{{'clang::internal_linkage' and 'common' attributes are not compatible}} \ // expected-note{{conflicting attribute is here}} From 9b08278de3b384b5b24fc129d54ef2194abe1b21 Mon Sep 17 00:00:00 2001 From: "Henrik G. Olsson" Date: Thu, 9 Oct 2025 11:48:14 -0700 Subject: [PATCH 3/9] format --- clang/lib/Parse/ParseDecl.cpp | 3 ++- clang/lib/Parse/ParseObjc.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index a6dd47ba85409..a5a8f16030989 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -1934,7 +1934,8 @@ Parser::DeclGroupPtrTy Parser::ParseSimpleDeclaration( bool RequireSemi, ForRangeInit *FRI, SourceLocation *DeclSpecStart) { // Need to retain these for diagnostics before we add them to the DeclSepc. ParsedAttributesView OriginalDeclSpecAttrs; - OriginalDeclSpecAttrs.addAllPrepend(DeclSpecAttrs.begin(), DeclSpecAttrs.end()); + OriginalDeclSpecAttrs.addAllPrepend(DeclSpecAttrs.begin(), + DeclSpecAttrs.end()); OriginalDeclSpecAttrs.Range = DeclSpecAttrs.Range; // Parse the common declaration-specifiers piece. diff --git a/clang/lib/Parse/ParseObjc.cpp b/clang/lib/Parse/ParseObjc.cpp index c2dbc4edf0c3c..69348342758eb 100644 --- a/clang/lib/Parse/ParseObjc.cpp +++ b/clang/lib/Parse/ParseObjc.cpp @@ -1066,7 +1066,7 @@ void Parser::ParseObjCTypeQualifierList(ObjCDeclSpec &DS, /// Take all the decl attributes out of the given list and add /// them to the given attribute set. static void takeDeclAttributesAppend(ParsedAttributesView &attrs, - ParsedAttributesView &from) { + ParsedAttributesView &from) { for (auto &AL : llvm::reverse(from)) { if (!AL.isUsedAsTypeAttr()) { from.remove(&AL); From 9d171f96a3a69183cbb848100ab31aa3aac8861d Mon Sep 17 00:00:00 2001 From: "Henrik G. Olsson" Date: Thu, 9 Oct 2025 13:49:15 -0700 Subject: [PATCH 4/9] update doc comment --- clang/include/clang/Sema/DeclSpec.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/include/clang/Sema/DeclSpec.h b/clang/include/clang/Sema/DeclSpec.h index 4b52fc02088a0..8b802bec581dd 100644 --- a/clang/include/clang/Sema/DeclSpec.h +++ b/clang/include/clang/Sema/DeclSpec.h @@ -2638,7 +2638,7 @@ class Declarator { return InventedTemplateParameterList; } - /// takeAttributesPrepend - Takes attributes from the given parsed-attributes + /// takeAttributesAppend - Takes attributes from the given parsed-attributes /// set and add them to this declarator. /// /// These examples both add 3 attributes to "var": From cc15fc4dd8087c15f687b0c1c1b2b3ce1ebd77bb Mon Sep 17 00:00:00 2001 From: "Henrik G. Olsson" Date: Thu, 9 Oct 2025 13:53:28 -0700 Subject: [PATCH 5/9] Rename attribute prepend/append functions (NFC) addAll[Prepend/Append] -> [prepend/append]All takeAllFrom[Prepend/Append] -> takeAll[Prepend/Append]From takeAttributesFromAppend -> takeAttributesAppendFrom --- clang/include/clang/Parse/Parser.h | 2 +- clang/include/clang/Sema/DeclSpec.h | 10 +++++----- clang/include/clang/Sema/ParsedAttr.h | 16 ++++++++-------- clang/lib/Parse/ParseDecl.cpp | 22 +++++++++++----------- clang/lib/Parse/ParseDeclCXX.cpp | 8 ++++---- clang/lib/Parse/ParseObjc.cpp | 2 +- clang/lib/Parse/ParseStmt.cpp | 4 ++-- clang/lib/Parse/ParseTemplate.cpp | 2 +- clang/lib/Parse/Parser.cpp | 4 ++-- clang/lib/Sema/DeclSpec.cpp | 2 +- clang/lib/Sema/ParsedAttr.cpp | 2 +- 11 files changed, 37 insertions(+), 37 deletions(-) diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index 5fc70ebb39930..647986311b1fc 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -2292,7 +2292,7 @@ class Parser : public CodeCompletionHandler { ParsedAttributes AttrsWithRange(AttrFactory); ParseMicrosoftAttributes(AttrsWithRange); AttrsParsed = !AttrsWithRange.empty(); - Attrs.takeAllFromAppend(AttrsWithRange); + Attrs.takeAllAppendFrom(AttrsWithRange); } return AttrsParsed; } diff --git a/clang/include/clang/Sema/DeclSpec.h b/clang/include/clang/Sema/DeclSpec.h index 8b802bec581dd..c1b1d028e0090 100644 --- a/clang/include/clang/Sema/DeclSpec.h +++ b/clang/include/clang/Sema/DeclSpec.h @@ -835,7 +835,7 @@ class DeclSpec { /// \endcode /// void addAttributes(const ParsedAttributesView &AL) { - Attrs.addAllPrepend(AL.begin(), AL.end()); + Attrs.prependAll(AL.begin(), AL.end()); } bool hasAttributes() const { return !Attrs.empty(); } @@ -843,8 +843,8 @@ class DeclSpec { ParsedAttributes &getAttributes() { return Attrs; } const ParsedAttributes &getAttributes() const { return Attrs; } - void takeAttributesFromAppend(ParsedAttributes &attrs) { - Attrs.takeAllFromAppend(attrs); + void takeAttributesAppendFrom(ParsedAttributes &attrs) { + Attrs.takeAllAppendFrom(attrs); } /// Finish - This does final analysis of the declspec, issuing diagnostics for @@ -2327,7 +2327,7 @@ class Declarator { void AddTypeInfo(const DeclaratorChunk &TI, ParsedAttributes &&attrs, SourceLocation EndLoc) { DeclTypeInfo.push_back(TI); - DeclTypeInfo.back().getAttrs().addAllPrepend(attrs.begin(), attrs.end()); + DeclTypeInfo.back().getAttrs().prependAll(attrs.begin(), attrs.end()); getAttributePool().takeAllFrom(attrs.getPool()); if (!EndLoc.isInvalid()) @@ -2648,7 +2648,7 @@ class Declarator { /// /// Also extends the range of the declarator. void takeAttributesAppend(ParsedAttributes &attrs) { - Attrs.takeAllFromAppend(attrs); + Attrs.takeAllAppendFrom(attrs); if (attrs.Range.getEnd().isValid()) SetRangeEnd(attrs.Range.getEnd()); diff --git a/clang/include/clang/Sema/ParsedAttr.h b/clang/include/clang/Sema/ParsedAttr.h index 85b75742808a9..7204d6d88672d 100644 --- a/clang/include/clang/Sema/ParsedAttr.h +++ b/clang/include/clang/Sema/ParsedAttr.h @@ -856,19 +856,19 @@ class ParsedAttributesView { friend class ParsedAttributesView; }; - void addAllPrepend(iterator B, iterator E) { + void prependAll(iterator B, iterator E) { AttrList.insert(AttrList.begin(), B.I, E.I); } - void addAllPrepend(const_iterator B, const_iterator E) { + void prependAll(const_iterator B, const_iterator E) { AttrList.insert(AttrList.begin(), B.I, E.I); } - void addAllAppend(iterator B, iterator E) { + void appendAll(iterator B, iterator E) { AttrList.insert(AttrList.end(), B.I, E.I); } - void addAllAppend(const_iterator B, const_iterator E) { + void appendAll(const_iterator B, const_iterator E) { AttrList.insert(AttrList.end(), B.I, E.I); } @@ -943,18 +943,18 @@ class ParsedAttributes : public ParsedAttributesView { AttributePool &getPool() const { return pool; } - void takeAllFromPrepend(ParsedAttributes &Other) { + void takeAllPrependFrom(ParsedAttributes &Other) { assert(&Other != this && "ParsedAttributes can't take attributes from itself"); - addAllPrepend(Other.begin(), Other.end()); + prependAll(Other.begin(), Other.end()); Other.clearListOnly(); pool.takeAllFrom(Other.pool); } - void takeAllFromAppend(ParsedAttributes &Other) { + void takeAllAppendFrom(ParsedAttributes &Other) { assert(&Other != this && "ParsedAttributes can't take attributes from itself"); - addAllAppend(Other.begin(), Other.end()); + appendAll(Other.begin(), Other.end()); Other.clearListOnly(); pool.takeAllFrom(Other.pool); } diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index a5a8f16030989..48e1912402731 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -1934,13 +1934,13 @@ Parser::DeclGroupPtrTy Parser::ParseSimpleDeclaration( bool RequireSemi, ForRangeInit *FRI, SourceLocation *DeclSpecStart) { // Need to retain these for diagnostics before we add them to the DeclSepc. ParsedAttributesView OriginalDeclSpecAttrs; - OriginalDeclSpecAttrs.addAllPrepend(DeclSpecAttrs.begin(), + OriginalDeclSpecAttrs.prependAll(DeclSpecAttrs.begin(), DeclSpecAttrs.end()); OriginalDeclSpecAttrs.Range = DeclSpecAttrs.Range; // Parse the common declaration-specifiers piece. ParsingDeclSpec DS(*this); - DS.takeAttributesFromAppend(DeclSpecAttrs); + DS.takeAttributesAppendFrom(DeclSpecAttrs); ParsedTemplateInfo TemplateInfo; DeclSpecContext DSContext = getDeclSpecContextFromDeclaratorContext(Context); @@ -2136,7 +2136,7 @@ Parser::DeclGroupPtrTy Parser::ParseDeclGroup(ParsingDeclSpec &DS, // list. This ensures that we will not attempt to interpret them as statement // attributes higher up the callchain. ParsedAttributes LocalAttrs(AttrFactory); - LocalAttrs.takeAllFromPrepend(Attrs); + LocalAttrs.takeAllPrependFrom(Attrs); ParsingDeclarator D(*this, DS, LocalAttrs, Context); if (TemplateInfo.TemplateParams) D.setTemplateParameterLists(*TemplateInfo.TemplateParams); @@ -3463,7 +3463,7 @@ void Parser::ParseDeclarationSpecifiers( PA.setInvalid(); } - DS.takeAttributesFromAppend(attrs); + DS.takeAttributesAppendFrom(attrs); } // If this is not a declaration specifier token, we're done reading decl @@ -3690,7 +3690,7 @@ void Parser::ParseDeclarationSpecifiers( if (ParseImplicitInt(DS, &SS, TemplateInfo, AS, DSContext, Attrs)) { if (!Attrs.empty()) { AttrsLastTime = true; - attrs.takeAllFromAppend(Attrs); + attrs.takeAllAppendFrom(Attrs); } continue; } @@ -3855,7 +3855,7 @@ void Parser::ParseDeclarationSpecifiers( if (ParseImplicitInt(DS, nullptr, TemplateInfo, AS, DSContext, Attrs)) { if (!Attrs.empty()) { AttrsLastTime = true; - attrs.takeAllFromAppend(Attrs); + attrs.takeAllAppendFrom(Attrs); } continue; } @@ -4464,7 +4464,7 @@ void Parser::ParseDeclarationSpecifiers( // take them over and handle them here. if (!Attributes.empty()) { AttrsLastTime = true; - attrs.takeAllFromAppend(Attributes); + attrs.takeAllAppendFrom(Attributes); } continue; } @@ -4831,7 +4831,7 @@ void Parser::ParseLexedCAttribute(LateParsedAttribute &LA, bool EnterScope, ConsumeAnyToken(); if (OutAttrs) { - OutAttrs->takeAllFromAppend(Attrs); + OutAttrs->takeAllAppendFrom(Attrs); } } @@ -6123,7 +6123,7 @@ void Parser::ParseTypeQualifierListOpt( isAllowedCXX11AttributeSpecifier()) { ParsedAttributes Attrs(AttrFactory); ParseCXX11Attributes(Attrs); - DS.takeAttributesFromAppend(Attrs); + DS.takeAttributesAppendFrom(Attrs); } SourceLocation EndLoc; @@ -7484,7 +7484,7 @@ void Parser::ParseParameterDeclarationClause( // Take them so that we only apply the attributes to the first parameter. // We have already started parsing the decl-specifier sequence, so don't // parse any parameter-declaration pieces that precede it. - ArgDeclSpecAttrs.takeAllFromPrepend(FirstArgAttrs); + ArgDeclSpecAttrs.takeAllPrependFrom(FirstArgAttrs); } else { // Parse any C++11 attributes. MaybeParseCXX11Attributes(ArgDeclAttrs); @@ -7506,7 +7506,7 @@ void Parser::ParseParameterDeclarationClause( DeclSpecContext::DSC_normal, /*LateAttrs=*/nullptr, AllowImplicitTypename); - DS.takeAttributesFromAppend(ArgDeclSpecAttrs); + DS.takeAttributesAppendFrom(ArgDeclSpecAttrs); // Parse the declarator. This is "PrototypeContext" or // "LambdaExprParameterContext", because we must accept either diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index 9c7e3a9e56901..b51a748b0f60e 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -739,7 +739,7 @@ Parser::DeclGroupPtrTy Parser::ParseUsingDeclaration( << FixItHint::CreateInsertionFromRange( Tok.getLocation(), CharSourceRange::getTokenRange(Range)) << FixItHint::CreateRemoval(Range); - Attrs.takeAllFromPrepend(MisplacedAttrs); + Attrs.takeAllPrependFrom(MisplacedAttrs); } // Maybe this is an alias-declaration. @@ -787,7 +787,7 @@ Parser::DeclGroupPtrTy Parser::ParseUsingDeclaration( // Parse (optional) attributes. MaybeParseAttributes(PAKM_GNU | PAKM_CXX11, Attrs); DiagnoseCXX11AttributeExtension(Attrs); - Attrs.addAllPrepend(PrefixAttrs.begin(), PrefixAttrs.end()); + Attrs.prependAll(PrefixAttrs.begin(), PrefixAttrs.end()); if (InvalidDeclarator) SkipUntil(tok::comma, tok::semi, StopBeforeMatch); @@ -1948,7 +1948,7 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind, // Recover by adding misplaced attributes to the attribute list // of the class so they can be applied on the class later. - attrs.takeAllFromAppend(Attributes); + attrs.takeAllAppendFrom(Attributes); } } @@ -2842,7 +2842,7 @@ Parser::DeclGroupPtrTy Parser::ParseCXXClassMemberDeclaration( // decl-specifier-seq: // Parse the common declaration-specifiers piece. ParsingDeclSpec DS(*this, TemplateDiags); - DS.takeAttributesFromAppend(DeclSpecAttrs); + DS.takeAttributesAppendFrom(DeclSpecAttrs); if (MalformedTypeSpec) DS.SetTypeSpecError(); diff --git a/clang/lib/Parse/ParseObjc.cpp b/clang/lib/Parse/ParseObjc.cpp index 69348342758eb..2cc3d2c137ccf 100644 --- a/clang/lib/Parse/ParseObjc.cpp +++ b/clang/lib/Parse/ParseObjc.cpp @@ -43,7 +43,7 @@ void Parser::MaybeSkipAttributes(tok::ObjCKeywordKind Kind) { Parser::DeclGroupPtrTy Parser::ParseObjCAtDirectives(ParsedAttributes &DeclAttrs, ParsedAttributes &DeclSpecAttrs) { - DeclAttrs.takeAllFromPrepend(DeclSpecAttrs); + DeclAttrs.takeAllPrependFrom(DeclSpecAttrs); SourceLocation AtLoc = ConsumeToken(); // the "@" diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp index 7ac0d335a6555..af39877aed964 100644 --- a/clang/lib/Parse/ParseStmt.cpp +++ b/clang/lib/Parse/ParseStmt.cpp @@ -718,7 +718,7 @@ StmtResult Parser::ParseLabeledStatement(ParsedAttributes &Attrs, // and followed by a semicolon, GCC will reject (it appears to parse the // attributes as part of a statement in that case). That looks like a bug. if (!getLangOpts().CPlusPlus || Tok.is(tok::semi)) - Attrs.takeAllFromAppend(TempAttrs); + Attrs.takeAllAppendFrom(TempAttrs); else { StmtVector Stmts; ParsedAttributes EmptyCXX11Attrs(AttrFactory); @@ -2407,7 +2407,7 @@ StmtResult Parser::ParsePragmaLoopHint(StmtVector &Stmts, Stmts, StmtCtx, TrailingElseLoc, Attrs, EmptyDeclSpecAttrs, PrecedingLabel); - Attrs.takeAllFromPrepend(TempAttrs); + Attrs.takeAllPrependFrom(TempAttrs); // Start of attribute range may already be set for some invalid input. // See PR46336. diff --git a/clang/lib/Parse/ParseTemplate.cpp b/clang/lib/Parse/ParseTemplate.cpp index b9f691597a736..9cc953ac57591 100644 --- a/clang/lib/Parse/ParseTemplate.cpp +++ b/clang/lib/Parse/ParseTemplate.cpp @@ -196,7 +196,7 @@ Parser::DeclGroupPtrTy Parser::ParseDeclarationAfterTemplate( ParsingDeclSpec DS(*this, &DiagsFromTParams); DS.SetRangeStart(DeclSpecAttrs.Range.getBegin()); DS.SetRangeEnd(DeclSpecAttrs.Range.getEnd()); - DS.takeAttributesFromAppend(DeclSpecAttrs); + DS.takeAttributesAppendFrom(DeclSpecAttrs); ParseDeclarationSpecifiers(DS, TemplateInfo, AS, getDeclSpecContextFromDeclaratorContext(Context)); diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index e13bfacadd5c2..2e11e6f0c718a 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -1083,7 +1083,7 @@ Parser::DeclGroupPtrTy Parser::ParseDeclOrFunctionDefInternal( "expected uninitialised source range"); DS.SetRangeStart(DeclSpecAttrs.Range.getBegin()); DS.SetRangeEnd(DeclSpecAttrs.Range.getEnd()); - DS.takeAttributesFromAppend(DeclSpecAttrs); + DS.takeAttributesAppendFrom(DeclSpecAttrs); ParsedTemplateInfo TemplateInfo; MaybeParseMicrosoftAttributes(DS.getAttributes()); @@ -1155,7 +1155,7 @@ Parser::DeclGroupPtrTy Parser::ParseDeclOrFunctionDefInternal( } DS.abort(); - DS.takeAttributesFromAppend(Attrs); + DS.takeAttributesAppendFrom(Attrs); const char *PrevSpec = nullptr; unsigned DiagID; diff --git a/clang/lib/Sema/DeclSpec.cpp b/clang/lib/Sema/DeclSpec.cpp index f086c5d489f4c..cde5dc1b58d59 100644 --- a/clang/lib/Sema/DeclSpec.cpp +++ b/clang/lib/Sema/DeclSpec.cpp @@ -197,7 +197,7 @@ DeclaratorChunk DeclaratorChunk::getFunction(bool hasProto, [&](DeclSpec::TQ TypeQual, StringRef PrintName, SourceLocation SL) { I.Fun.MethodQualifiers->SetTypeQual(TypeQual, SL); }); - I.Fun.MethodQualifiers->getAttributes().takeAllFromPrepend(attrs); + I.Fun.MethodQualifiers->getAttributes().takeAllPrependFrom(attrs); I.Fun.MethodQualifiers->getAttributePool().takeAllFrom(attrs.getPool()); } diff --git a/clang/lib/Sema/ParsedAttr.cpp b/clang/lib/Sema/ParsedAttr.cpp index 42fa2af65b04f..b5636c52122c4 100644 --- a/clang/lib/Sema/ParsedAttr.cpp +++ b/clang/lib/Sema/ParsedAttr.cpp @@ -304,7 +304,7 @@ bool ParsedAttr::checkAtMostNumArgs(Sema &S, unsigned Num) const { void clang::takeAndConcatenateAttrs(ParsedAttributes &First, ParsedAttributes &&Second) { - First.takeAllFromAppend(Second); + First.takeAllAppendFrom(Second); if (!First.Range.getBegin().isValid()) First.Range.setBegin(Second.Range.getBegin()); From 63703abc25c83130a073950ee475db8e5147ea3c Mon Sep 17 00:00:00 2001 From: "Henrik G. Olsson" Date: Thu, 9 Oct 2025 13:58:51 -0700 Subject: [PATCH 6/9] Rename functions again (NFC) Rename from AppendFrom/PrependFrom to AppendingFrom/PrependingFrom. --- clang/include/clang/Parse/Parser.h | 2 +- clang/include/clang/Sema/DeclSpec.h | 6 +++--- clang/include/clang/Sema/ParsedAttr.h | 4 ++-- clang/lib/Parse/ParseDecl.cpp | 20 ++++++++++---------- clang/lib/Parse/ParseDeclCXX.cpp | 6 +++--- clang/lib/Parse/ParseObjc.cpp | 2 +- clang/lib/Parse/ParseStmt.cpp | 4 ++-- clang/lib/Parse/ParseTemplate.cpp | 2 +- clang/lib/Parse/Parser.cpp | 4 ++-- clang/lib/Sema/DeclSpec.cpp | 2 +- clang/lib/Sema/ParsedAttr.cpp | 2 +- 11 files changed, 27 insertions(+), 27 deletions(-) diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index 647986311b1fc..ba043efca04a0 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -2292,7 +2292,7 @@ class Parser : public CodeCompletionHandler { ParsedAttributes AttrsWithRange(AttrFactory); ParseMicrosoftAttributes(AttrsWithRange); AttrsParsed = !AttrsWithRange.empty(); - Attrs.takeAllAppendFrom(AttrsWithRange); + Attrs.takeAllAppendingFrom(AttrsWithRange); } return AttrsParsed; } diff --git a/clang/include/clang/Sema/DeclSpec.h b/clang/include/clang/Sema/DeclSpec.h index c1b1d028e0090..b9e156591f47b 100644 --- a/clang/include/clang/Sema/DeclSpec.h +++ b/clang/include/clang/Sema/DeclSpec.h @@ -843,8 +843,8 @@ class DeclSpec { ParsedAttributes &getAttributes() { return Attrs; } const ParsedAttributes &getAttributes() const { return Attrs; } - void takeAttributesAppendFrom(ParsedAttributes &attrs) { - Attrs.takeAllAppendFrom(attrs); + void takeAttributesAppendingFrom(ParsedAttributes &attrs) { + Attrs.takeAllAppendingFrom(attrs); } /// Finish - This does final analysis of the declspec, issuing diagnostics for @@ -2648,7 +2648,7 @@ class Declarator { /// /// Also extends the range of the declarator. void takeAttributesAppend(ParsedAttributes &attrs) { - Attrs.takeAllAppendFrom(attrs); + Attrs.takeAllAppendingFrom(attrs); if (attrs.Range.getEnd().isValid()) SetRangeEnd(attrs.Range.getEnd()); diff --git a/clang/include/clang/Sema/ParsedAttr.h b/clang/include/clang/Sema/ParsedAttr.h index 7204d6d88672d..1437d3ec6dfb3 100644 --- a/clang/include/clang/Sema/ParsedAttr.h +++ b/clang/include/clang/Sema/ParsedAttr.h @@ -943,7 +943,7 @@ class ParsedAttributes : public ParsedAttributesView { AttributePool &getPool() const { return pool; } - void takeAllPrependFrom(ParsedAttributes &Other) { + void takeAllPrependingFrom(ParsedAttributes &Other) { assert(&Other != this && "ParsedAttributes can't take attributes from itself"); prependAll(Other.begin(), Other.end()); @@ -951,7 +951,7 @@ class ParsedAttributes : public ParsedAttributesView { pool.takeAllFrom(Other.pool); } - void takeAllAppendFrom(ParsedAttributes &Other) { + void takeAllAppendingFrom(ParsedAttributes &Other) { assert(&Other != this && "ParsedAttributes can't take attributes from itself"); appendAll(Other.begin(), Other.end()); diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 48e1912402731..d779a874d9894 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -1940,7 +1940,7 @@ Parser::DeclGroupPtrTy Parser::ParseSimpleDeclaration( // Parse the common declaration-specifiers piece. ParsingDeclSpec DS(*this); - DS.takeAttributesAppendFrom(DeclSpecAttrs); + DS.takeAttributesAppendingFrom(DeclSpecAttrs); ParsedTemplateInfo TemplateInfo; DeclSpecContext DSContext = getDeclSpecContextFromDeclaratorContext(Context); @@ -2136,7 +2136,7 @@ Parser::DeclGroupPtrTy Parser::ParseDeclGroup(ParsingDeclSpec &DS, // list. This ensures that we will not attempt to interpret them as statement // attributes higher up the callchain. ParsedAttributes LocalAttrs(AttrFactory); - LocalAttrs.takeAllPrependFrom(Attrs); + LocalAttrs.takeAllPrependingFrom(Attrs); ParsingDeclarator D(*this, DS, LocalAttrs, Context); if (TemplateInfo.TemplateParams) D.setTemplateParameterLists(*TemplateInfo.TemplateParams); @@ -3463,7 +3463,7 @@ void Parser::ParseDeclarationSpecifiers( PA.setInvalid(); } - DS.takeAttributesAppendFrom(attrs); + DS.takeAttributesAppendingFrom(attrs); } // If this is not a declaration specifier token, we're done reading decl @@ -3690,7 +3690,7 @@ void Parser::ParseDeclarationSpecifiers( if (ParseImplicitInt(DS, &SS, TemplateInfo, AS, DSContext, Attrs)) { if (!Attrs.empty()) { AttrsLastTime = true; - attrs.takeAllAppendFrom(Attrs); + attrs.takeAllAppendingFrom(Attrs); } continue; } @@ -3855,7 +3855,7 @@ void Parser::ParseDeclarationSpecifiers( if (ParseImplicitInt(DS, nullptr, TemplateInfo, AS, DSContext, Attrs)) { if (!Attrs.empty()) { AttrsLastTime = true; - attrs.takeAllAppendFrom(Attrs); + attrs.takeAllAppendingFrom(Attrs); } continue; } @@ -4464,7 +4464,7 @@ void Parser::ParseDeclarationSpecifiers( // take them over and handle them here. if (!Attributes.empty()) { AttrsLastTime = true; - attrs.takeAllAppendFrom(Attributes); + attrs.takeAllAppendingFrom(Attributes); } continue; } @@ -4831,7 +4831,7 @@ void Parser::ParseLexedCAttribute(LateParsedAttribute &LA, bool EnterScope, ConsumeAnyToken(); if (OutAttrs) { - OutAttrs->takeAllAppendFrom(Attrs); + OutAttrs->takeAllAppendingFrom(Attrs); } } @@ -6123,7 +6123,7 @@ void Parser::ParseTypeQualifierListOpt( isAllowedCXX11AttributeSpecifier()) { ParsedAttributes Attrs(AttrFactory); ParseCXX11Attributes(Attrs); - DS.takeAttributesAppendFrom(Attrs); + DS.takeAttributesAppendingFrom(Attrs); } SourceLocation EndLoc; @@ -7484,7 +7484,7 @@ void Parser::ParseParameterDeclarationClause( // Take them so that we only apply the attributes to the first parameter. // We have already started parsing the decl-specifier sequence, so don't // parse any parameter-declaration pieces that precede it. - ArgDeclSpecAttrs.takeAllPrependFrom(FirstArgAttrs); + ArgDeclSpecAttrs.takeAllPrependingFrom(FirstArgAttrs); } else { // Parse any C++11 attributes. MaybeParseCXX11Attributes(ArgDeclAttrs); @@ -7506,7 +7506,7 @@ void Parser::ParseParameterDeclarationClause( DeclSpecContext::DSC_normal, /*LateAttrs=*/nullptr, AllowImplicitTypename); - DS.takeAttributesAppendFrom(ArgDeclSpecAttrs); + DS.takeAttributesAppendingFrom(ArgDeclSpecAttrs); // Parse the declarator. This is "PrototypeContext" or // "LambdaExprParameterContext", because we must accept either diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index b51a748b0f60e..7fff8b560b277 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -739,7 +739,7 @@ Parser::DeclGroupPtrTy Parser::ParseUsingDeclaration( << FixItHint::CreateInsertionFromRange( Tok.getLocation(), CharSourceRange::getTokenRange(Range)) << FixItHint::CreateRemoval(Range); - Attrs.takeAllPrependFrom(MisplacedAttrs); + Attrs.takeAllPrependingFrom(MisplacedAttrs); } // Maybe this is an alias-declaration. @@ -1948,7 +1948,7 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind, // Recover by adding misplaced attributes to the attribute list // of the class so they can be applied on the class later. - attrs.takeAllAppendFrom(Attributes); + attrs.takeAllAppendingFrom(Attributes); } } @@ -2842,7 +2842,7 @@ Parser::DeclGroupPtrTy Parser::ParseCXXClassMemberDeclaration( // decl-specifier-seq: // Parse the common declaration-specifiers piece. ParsingDeclSpec DS(*this, TemplateDiags); - DS.takeAttributesAppendFrom(DeclSpecAttrs); + DS.takeAttributesAppendingFrom(DeclSpecAttrs); if (MalformedTypeSpec) DS.SetTypeSpecError(); diff --git a/clang/lib/Parse/ParseObjc.cpp b/clang/lib/Parse/ParseObjc.cpp index 2cc3d2c137ccf..0b9f113d9edc7 100644 --- a/clang/lib/Parse/ParseObjc.cpp +++ b/clang/lib/Parse/ParseObjc.cpp @@ -43,7 +43,7 @@ void Parser::MaybeSkipAttributes(tok::ObjCKeywordKind Kind) { Parser::DeclGroupPtrTy Parser::ParseObjCAtDirectives(ParsedAttributes &DeclAttrs, ParsedAttributes &DeclSpecAttrs) { - DeclAttrs.takeAllPrependFrom(DeclSpecAttrs); + DeclAttrs.takeAllPrependingFrom(DeclSpecAttrs); SourceLocation AtLoc = ConsumeToken(); // the "@" diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp index af39877aed964..92038985f9163 100644 --- a/clang/lib/Parse/ParseStmt.cpp +++ b/clang/lib/Parse/ParseStmt.cpp @@ -718,7 +718,7 @@ StmtResult Parser::ParseLabeledStatement(ParsedAttributes &Attrs, // and followed by a semicolon, GCC will reject (it appears to parse the // attributes as part of a statement in that case). That looks like a bug. if (!getLangOpts().CPlusPlus || Tok.is(tok::semi)) - Attrs.takeAllAppendFrom(TempAttrs); + Attrs.takeAllAppendingFrom(TempAttrs); else { StmtVector Stmts; ParsedAttributes EmptyCXX11Attrs(AttrFactory); @@ -2407,7 +2407,7 @@ StmtResult Parser::ParsePragmaLoopHint(StmtVector &Stmts, Stmts, StmtCtx, TrailingElseLoc, Attrs, EmptyDeclSpecAttrs, PrecedingLabel); - Attrs.takeAllPrependFrom(TempAttrs); + Attrs.takeAllPrependingFrom(TempAttrs); // Start of attribute range may already be set for some invalid input. // See PR46336. diff --git a/clang/lib/Parse/ParseTemplate.cpp b/clang/lib/Parse/ParseTemplate.cpp index 9cc953ac57591..ac80a21d0d08b 100644 --- a/clang/lib/Parse/ParseTemplate.cpp +++ b/clang/lib/Parse/ParseTemplate.cpp @@ -196,7 +196,7 @@ Parser::DeclGroupPtrTy Parser::ParseDeclarationAfterTemplate( ParsingDeclSpec DS(*this, &DiagsFromTParams); DS.SetRangeStart(DeclSpecAttrs.Range.getBegin()); DS.SetRangeEnd(DeclSpecAttrs.Range.getEnd()); - DS.takeAttributesAppendFrom(DeclSpecAttrs); + DS.takeAttributesAppendingFrom(DeclSpecAttrs); ParseDeclarationSpecifiers(DS, TemplateInfo, AS, getDeclSpecContextFromDeclaratorContext(Context)); diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index 2e11e6f0c718a..ab0dc6159a670 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -1083,7 +1083,7 @@ Parser::DeclGroupPtrTy Parser::ParseDeclOrFunctionDefInternal( "expected uninitialised source range"); DS.SetRangeStart(DeclSpecAttrs.Range.getBegin()); DS.SetRangeEnd(DeclSpecAttrs.Range.getEnd()); - DS.takeAttributesAppendFrom(DeclSpecAttrs); + DS.takeAttributesAppendingFrom(DeclSpecAttrs); ParsedTemplateInfo TemplateInfo; MaybeParseMicrosoftAttributes(DS.getAttributes()); @@ -1155,7 +1155,7 @@ Parser::DeclGroupPtrTy Parser::ParseDeclOrFunctionDefInternal( } DS.abort(); - DS.takeAttributesAppendFrom(Attrs); + DS.takeAttributesAppendingFrom(Attrs); const char *PrevSpec = nullptr; unsigned DiagID; diff --git a/clang/lib/Sema/DeclSpec.cpp b/clang/lib/Sema/DeclSpec.cpp index cde5dc1b58d59..184d31ecd1e40 100644 --- a/clang/lib/Sema/DeclSpec.cpp +++ b/clang/lib/Sema/DeclSpec.cpp @@ -197,7 +197,7 @@ DeclaratorChunk DeclaratorChunk::getFunction(bool hasProto, [&](DeclSpec::TQ TypeQual, StringRef PrintName, SourceLocation SL) { I.Fun.MethodQualifiers->SetTypeQual(TypeQual, SL); }); - I.Fun.MethodQualifiers->getAttributes().takeAllPrependFrom(attrs); + I.Fun.MethodQualifiers->getAttributes().takeAllPrependingFrom(attrs); I.Fun.MethodQualifiers->getAttributePool().takeAllFrom(attrs.getPool()); } diff --git a/clang/lib/Sema/ParsedAttr.cpp b/clang/lib/Sema/ParsedAttr.cpp index b5636c52122c4..2b5ad33ad7b29 100644 --- a/clang/lib/Sema/ParsedAttr.cpp +++ b/clang/lib/Sema/ParsedAttr.cpp @@ -304,7 +304,7 @@ bool ParsedAttr::checkAtMostNumArgs(Sema &S, unsigned Num) const { void clang::takeAndConcatenateAttrs(ParsedAttributes &First, ParsedAttributes &&Second) { - First.takeAllAppendFrom(Second); + First.takeAllAppendingFrom(Second); if (!First.Range.getBegin().isValid()) First.Range.setBegin(Second.Range.getBegin()); From ecf29ba6bad4bbd3f56d9b94e1fa4586dcd12896 Mon Sep 17 00:00:00 2001 From: "Henrik G. Olsson" Date: Thu, 9 Oct 2025 14:01:24 -0700 Subject: [PATCH 7/9] format --- clang/lib/Parse/ParseDecl.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index d779a874d9894..ae581498bd8d6 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -1934,8 +1934,7 @@ Parser::DeclGroupPtrTy Parser::ParseSimpleDeclaration( bool RequireSemi, ForRangeInit *FRI, SourceLocation *DeclSpecStart) { // Need to retain these for diagnostics before we add them to the DeclSepc. ParsedAttributesView OriginalDeclSpecAttrs; - OriginalDeclSpecAttrs.prependAll(DeclSpecAttrs.begin(), - DeclSpecAttrs.end()); + OriginalDeclSpecAttrs.prependAll(DeclSpecAttrs.begin(), DeclSpecAttrs.end()); OriginalDeclSpecAttrs.Range = DeclSpecAttrs.Range; // Parse the common declaration-specifiers piece. From 285412ac26e4e7217519f95b784f3defb9e80720 Mon Sep 17 00:00:00 2001 From: "Henrik G. Olsson" Date: Thu, 9 Oct 2025 15:18:05 -0700 Subject: [PATCH 8/9] Rename functions (NFC) takeAttributesAppend -> takeAttributesAppending prependAll -> prepend appendAll -> append --- clang/include/clang/Parse/Parser.h | 6 +++--- clang/include/clang/Sema/DeclSpec.h | 12 ++++++------ clang/include/clang/Sema/ParsedAttr.h | 12 ++++++------ clang/lib/Parse/ParseDecl.cpp | 10 +++++----- clang/lib/Parse/ParseDeclCXX.cpp | 4 ++-- clang/lib/Parse/ParseExprCXX.cpp | 2 +- clang/lib/Parse/ParseTemplate.cpp | 2 +- clang/lib/Parse/Parser.cpp | 4 ++-- clang/lib/Sema/SemaDecl.cpp | 2 +- 9 files changed, 27 insertions(+), 27 deletions(-) diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index ba043efca04a0..0d2316f73fb62 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -2173,7 +2173,7 @@ class Parser : public CodeCompletionHandler { if (Tok.is(tok::kw___attribute)) { ParsedAttributes Attrs(AttrFactory); ParseGNUAttributes(Attrs, LateAttrs, &D); - D.takeAttributesAppend(Attrs); + D.takeAttributesAppending(Attrs); } } @@ -2272,7 +2272,7 @@ class Parser : public CodeCompletionHandler { if (isAllowedCXX11AttributeSpecifier()) { ParsedAttributes Attrs(AttrFactory); ParseCXX11Attributes(Attrs); - D.takeAttributesAppend(Attrs); + D.takeAttributesAppending(Attrs); } } @@ -5175,7 +5175,7 @@ class Parser : public CodeCompletionHandler { if (Tok.is(tok::colon)) { ParsedAttributes Attrs(AttrFactory); ParseHLSLAnnotations(Attrs, EndLoc, CouldBeBitField); - D.takeAttributesAppend(Attrs); + D.takeAttributesAppending(Attrs); return true; } return false; diff --git a/clang/include/clang/Sema/DeclSpec.h b/clang/include/clang/Sema/DeclSpec.h index b9e156591f47b..2365e630975d8 100644 --- a/clang/include/clang/Sema/DeclSpec.h +++ b/clang/include/clang/Sema/DeclSpec.h @@ -835,7 +835,7 @@ class DeclSpec { /// \endcode /// void addAttributes(const ParsedAttributesView &AL) { - Attrs.prependAll(AL.begin(), AL.end()); + Attrs.prepend(AL.begin(), AL.end()); } bool hasAttributes() const { return !Attrs.empty(); } @@ -843,7 +843,7 @@ class DeclSpec { ParsedAttributes &getAttributes() { return Attrs; } const ParsedAttributes &getAttributes() const { return Attrs; } - void takeAttributesAppendingFrom(ParsedAttributes &attrs) { + void takeAttributesAppendingingFrom(ParsedAttributes &attrs) { Attrs.takeAllAppendingFrom(attrs); } @@ -2327,7 +2327,7 @@ class Declarator { void AddTypeInfo(const DeclaratorChunk &TI, ParsedAttributes &&attrs, SourceLocation EndLoc) { DeclTypeInfo.push_back(TI); - DeclTypeInfo.back().getAttrs().prependAll(attrs.begin(), attrs.end()); + DeclTypeInfo.back().getAttrs().prepend(attrs.begin(), attrs.end()); getAttributePool().takeAllFrom(attrs.getPool()); if (!EndLoc.isInvalid()) @@ -2638,8 +2638,8 @@ class Declarator { return InventedTemplateParameterList; } - /// takeAttributesAppend - Takes attributes from the given parsed-attributes - /// set and add them to this declarator. + /// takeAttributesAppending - Takes attributes from the given + /// parsed-attributes set and add them to this declarator. /// /// These examples both add 3 attributes to "var": /// short int var __attribute__((aligned(16),common,deprecated)); @@ -2647,7 +2647,7 @@ class Declarator { /// __attribute__((common,deprecated)); /// /// Also extends the range of the declarator. - void takeAttributesAppend(ParsedAttributes &attrs) { + void takeAttributesAppending(ParsedAttributes &attrs) { Attrs.takeAllAppendingFrom(attrs); if (attrs.Range.getEnd().isValid()) diff --git a/clang/include/clang/Sema/ParsedAttr.h b/clang/include/clang/Sema/ParsedAttr.h index 1437d3ec6dfb3..5387f9fad6cd2 100644 --- a/clang/include/clang/Sema/ParsedAttr.h +++ b/clang/include/clang/Sema/ParsedAttr.h @@ -856,19 +856,19 @@ class ParsedAttributesView { friend class ParsedAttributesView; }; - void prependAll(iterator B, iterator E) { + void prepend(iterator B, iterator E) { AttrList.insert(AttrList.begin(), B.I, E.I); } - void prependAll(const_iterator B, const_iterator E) { + void prepend(const_iterator B, const_iterator E) { AttrList.insert(AttrList.begin(), B.I, E.I); } - void appendAll(iterator B, iterator E) { + void append(iterator B, iterator E) { AttrList.insert(AttrList.end(), B.I, E.I); } - void appendAll(const_iterator B, const_iterator E) { + void append(const_iterator B, const_iterator E) { AttrList.insert(AttrList.end(), B.I, E.I); } @@ -946,7 +946,7 @@ class ParsedAttributes : public ParsedAttributesView { void takeAllPrependingFrom(ParsedAttributes &Other) { assert(&Other != this && "ParsedAttributes can't take attributes from itself"); - prependAll(Other.begin(), Other.end()); + prepend(Other.begin(), Other.end()); Other.clearListOnly(); pool.takeAllFrom(Other.pool); } @@ -954,7 +954,7 @@ class ParsedAttributes : public ParsedAttributesView { void takeAllAppendingFrom(ParsedAttributes &Other) { assert(&Other != this && "ParsedAttributes can't take attributes from itself"); - appendAll(Other.begin(), Other.end()); + append(Other.begin(), Other.end()); Other.clearListOnly(); pool.takeAllFrom(Other.pool); } diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index ae581498bd8d6..e4b158e4a6248 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -1934,12 +1934,12 @@ Parser::DeclGroupPtrTy Parser::ParseSimpleDeclaration( bool RequireSemi, ForRangeInit *FRI, SourceLocation *DeclSpecStart) { // Need to retain these for diagnostics before we add them to the DeclSepc. ParsedAttributesView OriginalDeclSpecAttrs; - OriginalDeclSpecAttrs.prependAll(DeclSpecAttrs.begin(), DeclSpecAttrs.end()); + OriginalDeclSpecAttrs.prepend(DeclSpecAttrs.begin(), DeclSpecAttrs.end()); OriginalDeclSpecAttrs.Range = DeclSpecAttrs.Range; // Parse the common declaration-specifiers piece. ParsingDeclSpec DS(*this); - DS.takeAttributesAppendingFrom(DeclSpecAttrs); + DS.takeAttributesAppendingingFrom(DeclSpecAttrs); ParsedTemplateInfo TemplateInfo; DeclSpecContext DSContext = getDeclSpecContextFromDeclaratorContext(Context); @@ -3462,7 +3462,7 @@ void Parser::ParseDeclarationSpecifiers( PA.setInvalid(); } - DS.takeAttributesAppendingFrom(attrs); + DS.takeAttributesAppendingingFrom(attrs); } // If this is not a declaration specifier token, we're done reading decl @@ -6122,7 +6122,7 @@ void Parser::ParseTypeQualifierListOpt( isAllowedCXX11AttributeSpecifier()) { ParsedAttributes Attrs(AttrFactory); ParseCXX11Attributes(Attrs); - DS.takeAttributesAppendingFrom(Attrs); + DS.takeAttributesAppendingingFrom(Attrs); } SourceLocation EndLoc; @@ -7505,7 +7505,7 @@ void Parser::ParseParameterDeclarationClause( DeclSpecContext::DSC_normal, /*LateAttrs=*/nullptr, AllowImplicitTypename); - DS.takeAttributesAppendingFrom(ArgDeclSpecAttrs); + DS.takeAttributesAppendingingFrom(ArgDeclSpecAttrs); // Parse the declarator. This is "PrototypeContext" or // "LambdaExprParameterContext", because we must accept either diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index 7fff8b560b277..b96968d4592f5 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -787,7 +787,7 @@ Parser::DeclGroupPtrTy Parser::ParseUsingDeclaration( // Parse (optional) attributes. MaybeParseAttributes(PAKM_GNU | PAKM_CXX11, Attrs); DiagnoseCXX11AttributeExtension(Attrs); - Attrs.prependAll(PrefixAttrs.begin(), PrefixAttrs.end()); + Attrs.prepend(PrefixAttrs.begin(), PrefixAttrs.end()); if (InvalidDeclarator) SkipUntil(tok::comma, tok::semi, StopBeforeMatch); @@ -2842,7 +2842,7 @@ Parser::DeclGroupPtrTy Parser::ParseCXXClassMemberDeclaration( // decl-specifier-seq: // Parse the common declaration-specifiers piece. ParsingDeclSpec DS(*this, TemplateDiags); - DS.takeAttributesAppendingFrom(DeclSpecAttrs); + DS.takeAttributesAppendingingFrom(DeclSpecAttrs); if (MalformedTypeSpec) DS.SetTypeSpecError(); diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp index cb0d2a000994a..0606fcbbe635b 100644 --- a/clang/lib/Parse/ParseExprCXX.cpp +++ b/clang/lib/Parse/ParseExprCXX.cpp @@ -1244,7 +1244,7 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer( break; } - D.takeAttributesAppend(Attributes); + D.takeAttributesAppending(Attributes); } MultiParseScope TemplateParamScope(*this); diff --git a/clang/lib/Parse/ParseTemplate.cpp b/clang/lib/Parse/ParseTemplate.cpp index ac80a21d0d08b..dbc7cbc6cdc0c 100644 --- a/clang/lib/Parse/ParseTemplate.cpp +++ b/clang/lib/Parse/ParseTemplate.cpp @@ -196,7 +196,7 @@ Parser::DeclGroupPtrTy Parser::ParseDeclarationAfterTemplate( ParsingDeclSpec DS(*this, &DiagsFromTParams); DS.SetRangeStart(DeclSpecAttrs.Range.getBegin()); DS.SetRangeEnd(DeclSpecAttrs.Range.getEnd()); - DS.takeAttributesAppendingFrom(DeclSpecAttrs); + DS.takeAttributesAppendingingFrom(DeclSpecAttrs); ParseDeclarationSpecifiers(DS, TemplateInfo, AS, getDeclSpecContextFromDeclaratorContext(Context)); diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index ab0dc6159a670..bbff627d46600 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -1083,7 +1083,7 @@ Parser::DeclGroupPtrTy Parser::ParseDeclOrFunctionDefInternal( "expected uninitialised source range"); DS.SetRangeStart(DeclSpecAttrs.Range.getBegin()); DS.SetRangeEnd(DeclSpecAttrs.Range.getEnd()); - DS.takeAttributesAppendingFrom(DeclSpecAttrs); + DS.takeAttributesAppendingingFrom(DeclSpecAttrs); ParsedTemplateInfo TemplateInfo; MaybeParseMicrosoftAttributes(DS.getAttributes()); @@ -1155,7 +1155,7 @@ Parser::DeclGroupPtrTy Parser::ParseDeclOrFunctionDefInternal( } DS.abort(); - DS.takeAttributesAppendingFrom(Attrs); + DS.takeAttributesAppendingingFrom(Attrs); const char *PrevSpec = nullptr; unsigned DiagID; diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 24d80c3c08a96..0e83c20b27c22 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -14637,7 +14637,7 @@ StmtResult Sema::ActOnCXXForRangeIdentifier(Scope *S, SourceLocation IdentLoc, Declarator D(DS, ParsedAttributesView::none(), DeclaratorContext::ForInit); D.SetIdentifier(Ident, IdentLoc); - D.takeAttributesAppend(Attrs); + D.takeAttributesAppending(Attrs); D.AddTypeInfo(DeclaratorChunk::getReference(0, IdentLoc, /*lvalue*/ false), IdentLoc); From 4e2a0694b0139fbce62e70eb839906369ecc4704 Mon Sep 17 00:00:00 2001 From: "Henrik G. Olsson" Date: Thu, 9 Oct 2025 15:43:32 -0700 Subject: [PATCH 9/9] parsed-attributes -> ParsedAttributes --- clang/include/clang/Sema/DeclSpec.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/include/clang/Sema/DeclSpec.h b/clang/include/clang/Sema/DeclSpec.h index 2365e630975d8..43a48c92fc305 100644 --- a/clang/include/clang/Sema/DeclSpec.h +++ b/clang/include/clang/Sema/DeclSpec.h @@ -2639,7 +2639,7 @@ class Declarator { } /// takeAttributesAppending - Takes attributes from the given - /// parsed-attributes set and add them to this declarator. + /// ParsedAttributes set and add them to this declarator. /// /// These examples both add 3 attributes to "var": /// short int var __attribute__((aligned(16),common,deprecated));