Skip to content

Commit 6a0bc45

Browse files
authored
Merge pull request swiftlang#27377 from rintaro/syntaxparse-rdar55711699
[SyntaxParse] Fix ASAN issue
2 parents 6aadbc3 + d9eba19 commit 6a0bc45

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

lib/Parse/ASTGen.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,8 +576,11 @@ GenericParamList *ASTGen::generate(const GenericParameterClauseSyntax &clause,
576576

577577
DeclAttributes attrs;
578578
if (auto attrsSyntax = elem.getAttributes()) {
579-
auto attrsLoc = advanceLocBegin(Loc, *attrsSyntax->getFirstToken());
580-
attrs = getDeclAttributes(attrsLoc);
579+
if (auto firstTok = attrsSyntax->getFirstToken()) {
580+
auto attrsLoc = advanceLocBegin(Loc, *firstTok);
581+
if (hasDeclAttributes(attrsLoc))
582+
attrs = getDeclAttributes(attrsLoc);
583+
}
581584
}
582585
Identifier name = Context.getIdentifier(elem.getName().getIdentifierText());
583586
SourceLoc nameLoc = advanceLocBegin(Loc, elem.getName());

lib/Parse/ParseGeneric.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,17 @@ Parser::parseGenericParameterClauseSyntax() {
7474

7575
// Parse attributes.
7676
// TODO: Implement syntax attribute parsing.
77-
DeclAttributes attrsAST;
78-
parseDeclAttributeList(attrsAST);
79-
auto attrs = SyntaxContext->popIf<ParsedAttributeListSyntax>();
80-
if (attrs) {
81-
paramBuilder.useAttributes(std::move(*attrs));
82-
Generator.addDeclAttributes(attrsAST, attrsAST.getStartLoc());
77+
if (Tok.is(tok::at_sign)) {
78+
SyntaxParsingContext TmpCtxt(SyntaxContext);
79+
TmpCtxt.setTransparent();
80+
81+
DeclAttributes attrsAST;
82+
parseDeclAttributeList(attrsAST);
83+
if (!attrsAST.isEmpty())
84+
Generator.addDeclAttributes(attrsAST, attrsAST.getStartLoc());
85+
auto attrs = SyntaxContext->popIf<ParsedAttributeListSyntax>();
86+
if (attrs)
87+
paramBuilder.useAttributes(std::move(*attrs));
8388
}
8489

8590
// Parse the name of the parameter.

0 commit comments

Comments
 (0)