aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Parse/ParseDecl.cpp
diff options
context:
space:
mode:
authorHenrik G. Olsson <hnrklssn@gmail.com>2025-10-09 22:13:37 -0700
committerGitHub <noreply@github.com>2025-10-09 22:13:37 -0700
commit3a9440b9f73b5b85917cff123ba0ce7f2e8115c4 (patch)
tree6530328cac2ab8c175152968c8730495659771a6 /clang/lib/Parse/ParseDecl.cpp
parenta1b5e975c92a2f425817e321648036b386fc6b03 (diff)
downloadllvm-3a9440b9f73b5b85917cff123ba0ce7f2e8115c4.zip
llvm-3a9440b9f73b5b85917cff123ba0ce7f2e8115c4.tar.gz
llvm-3a9440b9f73b5b85917cff123ba0ce7f2e8115c4.tar.bz2
[Sema] Keep attribute lists in the order the attributes were parsed (#162714)
This renames some attribute list related functions, to make callers think about whether they want to append or prepend to the list, instead of defaulting to prepending which is often not the desired behaviour (for the cases where it matters, sometimes we're just adding to an empty list). Then it adjusts some of these calls to append where they were previously prepending. This has the effect of making `err_attributes_are_not_compatible` consistent in emitting diagnostics as `<new-attr> and <existing-attr> are not compatible`, regardless of the syntax used to apply the attributes.
Diffstat (limited to 'clang/lib/Parse/ParseDecl.cpp')
-rw-r--r--clang/lib/Parse/ParseDecl.cpp22
1 files changed, 11 insertions, 11 deletions
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index d6cd7eb..e4b158e 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.prepend(DeclSpecAttrs.begin(), DeclSpecAttrs.end());
OriginalDeclSpecAttrs.Range = DeclSpecAttrs.Range;
// Parse the common declaration-specifiers piece.
ParsingDeclSpec DS(*this);
- DS.takeAttributesFrom(DeclSpecAttrs);
+ DS.takeAttributesAppendingingFrom(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.takeAllPrependingFrom(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.takeAttributesAppendingingFrom(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.takeAllAppendingFrom(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.takeAllAppendingFrom(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.takeAllAppendingFrom(Attributes);
}
continue;
}
@@ -4830,7 +4830,7 @@ void Parser::ParseLexedCAttribute(LateParsedAttribute &LA, bool EnterScope,
ConsumeAnyToken();
if (OutAttrs) {
- OutAttrs->takeAllFrom(Attrs);
+ OutAttrs->takeAllAppendingFrom(Attrs);
}
}
@@ -6122,7 +6122,7 @@ void Parser::ParseTypeQualifierListOpt(
isAllowedCXX11AttributeSpecifier()) {
ParsedAttributes Attrs(AttrFactory);
ParseCXX11Attributes(Attrs);
- DS.takeAttributesFrom(Attrs);
+ DS.takeAttributesAppendingingFrom(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.takeAllPrependingFrom(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.takeAttributesAppendingingFrom(ArgDeclSpecAttrs);
// Parse the declarator. This is "PrototypeContext" or
// "LambdaExprParameterContext", because we must accept either