Skip to content

Commit d9eba19

Browse files
committed
[SyntaxParse] Fix ASAN issue
rdar://problem/55711699 rdar://problem/55711787 rdar://problem/55711952
1 parent 7189c09 commit d9eba19

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

Diff for: lib/Parse/ASTGen.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,11 @@ GenericParamList *ASTGen::generate(const GenericParameterClauseSyntax &clause,
574574

575575
DeclAttributes attrs;
576576
if (auto attrsSyntax = elem.getAttributes()) {
577-
auto attrsLoc = advanceLocBegin(Loc, *attrsSyntax->getFirstToken());
578-
attrs = getDeclAttributes(attrsLoc);
577+
if (auto firstTok = attrsSyntax->getFirstToken()) {
578+
auto attrsLoc = advanceLocBegin(Loc, *firstTok);
579+
if (hasDeclAttributes(attrsLoc))
580+
attrs = getDeclAttributes(attrsLoc);
581+
}
579582
}
580583
Identifier name = Context.getIdentifier(elem.getName().getIdentifierText());
581584
SourceLoc nameLoc = advanceLocBegin(Loc, elem.getName());

Diff for: lib/Parse/ParseGeneric.cpp

+11-6
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,17 @@ Parser::parseGenericParameterClauseSyntax() {
7373

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

8489
// Parse the name of the parameter.

0 commit comments

Comments
 (0)