[clang] af80392 - [BoundsSafety] Unify ParseLexedAttributeTokens (#206689)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 17 21:51:54 PDT 2026
Author: Mohammed Ashraf
Date: 2026-09-17T21:51:48-07:00
New Revision: af8039273a760a21b3cf8006ebaa107481227fd6
URL: https://github.com/llvm/llvm-project/commit/af8039273a760a21b3cf8006ebaa107481227fd6
DIFF: https://github.com/llvm/llvm-project/commit/af8039273a760a21b3cf8006ebaa107481227fd6.diff
LOG: [BoundsSafety] Unify ParseLexedAttributeTokens (#206689)
This PR is a continuation of the previous [Unify ParseLexedAttribute
PR](https://github.com/llvm/llvm-project/pull/186033)
Added:
Modified:
clang/include/clang/Parse/Parser.h
clang/lib/Parse/ParseCXXInlineMethods.cpp
clang/lib/Parse/ParseDecl.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h
index 87e8dc9808e5c..e9bab81b095fd 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -1525,9 +1525,9 @@ class Parser : public CodeCompletionHandler {
ParsedAttributes &OutAttrs);
/// Parse cached tokens for a late-parsed attribute and return the parsed
- /// attributes. Shared implementation used by both ParseLexedCAttribute and
+ /// attributes. Shared implementation used by both ParseLexedAttribute and
/// ParseLexedTypeAttribute.
- ParsedAttributes ParseLexedCAttributeTokens(LateParsedAttribute &LA);
+ ParsedAttributes ParseLexedAttributeTokens(LateParsedAttribute &LPA);
/// Helper function to move LateParsedTypeAttribute pointers from one list
/// to another. Filters type attributes from \p From and appends them to \p
diff --git a/clang/lib/Parse/ParseCXXInlineMethods.cpp b/clang/lib/Parse/ParseCXXInlineMethods.cpp
index e472628dd36bc..35dbec8dfb2f7 100644
--- a/clang/lib/Parse/ParseCXXInlineMethods.cpp
+++ b/clang/lib/Parse/ParseCXXInlineMethods.cpp
@@ -718,22 +718,6 @@ void Parser::ParseLexedAttributeList(LateParsedAttrList &LAs, Decl *D,
void Parser::ParseLexedAttribute(LateParsedAttribute &LPA, bool EnterScope,
bool OnDefinition,
ParsedAttributes *OutAttrs) {
- // Create a fake EOF so that attribute parsing won't go off the end of the
- // attribute.
- Token AttrEnd;
- AttrEnd.startToken();
- AttrEnd.setKind(tok::eof);
- AttrEnd.setLocation(Tok.getLocation());
- AttrEnd.setEofData(LPA.Toks.data());
- LPA.Toks.push_back(AttrEnd);
-
- // Append the current token at the end of the new token stream so that it
- // doesn't get lost.
- LPA.Toks.push_back(Tok);
- PP.EnterTokenStream(LPA.Toks, true, /*IsReinject=*/true);
- // Consume the previously pushed token.
- ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true);
-
ParsedAttributes Attrs(AttrFactory);
if (LPA.Decls.size() > 0) {
@@ -760,20 +744,14 @@ void Parser::ParseLexedAttribute(LateParsedAttribute &LPA, bool EnterScope,
Actions.ActOnReenterFunctionContext(Actions.CurScope, D);
}
- ParseGNUAttributeArgs(&LPA.AttrName, LPA.AttrNameLoc, Attrs,
- /*EndLoc=*/nullptr, /*ScopeName=*/nullptr,
- SourceLocation(), ParsedAttr::Form::GNU(),
- /*D=*/nullptr);
+ ParsedAttributes Parsed = ParseLexedAttributeTokens(LPA);
+ Attrs.takeAllAppendingFrom(Parsed);
if (HasFuncScope)
Actions.ActOnExitFunctionContext();
- } else if (OutAttrs) {
- ParseGNUAttributeArgs(&LPA.AttrName, LPA.AttrNameLoc, Attrs,
- /*EndLoc=*/nullptr, /*ScopeName=*/nullptr,
- SourceLocation(), ParsedAttr::Form::GNU(),
- /*D=*/nullptr);
} else {
- Diag(Tok, diag::warn_attribute_no_decl) << LPA.AttrName.getName();
+ Diag(LPA.AttrNameLoc, diag::warn_attribute_no_decl)
+ << LPA.AttrName.getName();
}
if (OnDefinition && !Attrs.empty() && !Attrs.begin()->isCXX11Attribute() &&
@@ -783,14 +761,6 @@ void Parser::ParseLexedAttribute(LateParsedAttribute &LPA, bool EnterScope,
for (auto *D : LPA.Decls)
Actions.ActOnFinishDelayedAttribute(getCurScope(), D, Attrs);
- // Due to a parsing error, we either went over the cached tokens or
- // there are still cached tokens left, so we skip the leftover tokens.
- while (Tok.isNot(tok::eof))
- ConsumeAnyToken();
-
- if (Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData())
- ConsumeAnyToken();
-
if (OutAttrs)
OutAttrs->takeAllAppendingFrom(Attrs);
}
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index a4bdec00ca80a..5976f5a7ccdea 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -4848,33 +4848,32 @@ void Parser::ParseStructDeclaration(
}
}
-ParsedAttributes Parser::ParseLexedCAttributeTokens(LateParsedAttribute &LA) {
+ParsedAttributes Parser::ParseLexedAttributeTokens(LateParsedAttribute &LPA) {
// Create a fake EOF so that attribute parsing won't go off the end of the
// attribute.
Token AttrEnd;
AttrEnd.startToken();
AttrEnd.setKind(tok::eof);
AttrEnd.setLocation(Tok.getLocation());
- AttrEnd.setEofData(LA.Toks.data());
- LA.Toks.push_back(AttrEnd);
+ AttrEnd.setEofData(LPA.Toks.data());
+ LPA.Toks.push_back(AttrEnd);
// Append the current token at the end of the new token stream so that it
// doesn't get lost.
- LA.Toks.push_back(Tok);
- PP.EnterTokenStream(LA.Toks, /*DisableMacroExpansion=*/true,
+ LPA.Toks.push_back(Tok);
+ PP.EnterTokenStream(LPA.Toks, /*DisableMacroExpansion=*/true,
/*IsReinject=*/true);
+
// Drop the current token and bring the first cached one. It's the same token
// as when we entered this function.
ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true);
ParsedAttributes Attrs(AttrFactory);
- assert(LA.Decls.size() <= 1 &&
- "late field attribute expects to have at most one declaration.");
-
- // Dispatch based on the attribute and parse it
- ParseGNUAttributeArgs(&LA.AttrName, LA.AttrNameLoc, Attrs, nullptr, nullptr,
- SourceLocation(), ParsedAttr::Form::GNU(), nullptr);
+ ParseGNUAttributeArgs(&LPA.AttrName, LPA.AttrNameLoc, Attrs,
+ /*EndLoc=*/nullptr, /*ScopeName=*/nullptr,
+ SourceLocation(), ParsedAttr::Form::GNU(),
+ /*D=*/nullptr);
// Due to a parsing error, we either went over the cached tokens or
// there are still cached tokens left, so we skip the leftover tokens.
@@ -4890,7 +4889,10 @@ ParsedAttributes Parser::ParseLexedCAttributeTokens(LateParsedAttribute &LA) {
void Parser::ParseLexedTypeAttribute(LateParsedTypeAttribute &LA,
ParsedAttributes &OutAttrs) {
- ParsedAttributes Attrs = ParseLexedCAttributeTokens(LA);
+ assert(LA.Decls.size() <= 1 &&
+ "late field attribute expects to have at most one declaration.");
+
+ ParsedAttributes Attrs = ParseLexedAttributeTokens(LA);
OutAttrs.takeAllAppendingFrom(Attrs);
}
More information about the cfe-commits
mailing list