[SyntaxParse] Fix ASAN issue

rdar://problem/55711699
rdar://problem/55711787
rdar://problem/55711952
This commit is contained in:
Rintaro Ishizaki
2019-09-25 21:27:44 -07:00
parent 7189c09720
commit d9eba19b74
2 changed files with 16 additions and 8 deletions

View File

@@ -574,8 +574,11 @@ GenericParamList *ASTGen::generate(const GenericParameterClauseSyntax &clause,
DeclAttributes attrs; DeclAttributes attrs;
if (auto attrsSyntax = elem.getAttributes()) { if (auto attrsSyntax = elem.getAttributes()) {
auto attrsLoc = advanceLocBegin(Loc, *attrsSyntax->getFirstToken()); if (auto firstTok = attrsSyntax->getFirstToken()) {
attrs = getDeclAttributes(attrsLoc); auto attrsLoc = advanceLocBegin(Loc, *firstTok);
if (hasDeclAttributes(attrsLoc))
attrs = getDeclAttributes(attrsLoc);
}
} }
Identifier name = Context.getIdentifier(elem.getName().getIdentifierText()); Identifier name = Context.getIdentifier(elem.getName().getIdentifierText());
SourceLoc nameLoc = advanceLocBegin(Loc, elem.getName()); SourceLoc nameLoc = advanceLocBegin(Loc, elem.getName());

View File

@@ -73,12 +73,17 @@ Parser::parseGenericParameterClauseSyntax() {
// Parse attributes. // Parse attributes.
// TODO: Implement syntax attribute parsing. // TODO: Implement syntax attribute parsing.
DeclAttributes attrsAST; if (Tok.is(tok::at_sign)) {
parseDeclAttributeList(attrsAST); SyntaxParsingContext TmpCtxt(SyntaxContext);
auto attrs = SyntaxContext->popIf<ParsedAttributeListSyntax>(); TmpCtxt.setTransparent();
if (attrs) {
paramBuilder.useAttributes(std::move(*attrs)); DeclAttributes attrsAST;
Generator.addDeclAttributes(attrsAST, attrsAST.getStartLoc()); parseDeclAttributeList(attrsAST);
if (!attrsAST.isEmpty())
Generator.addDeclAttributes(attrsAST, attrsAST.getStartLoc());
auto attrs = SyntaxContext->popIf<ParsedAttributeListSyntax>();
if (attrs)
paramBuilder.useAttributes(std::move(*attrs));
} }
// Parse the name of the parameter. // Parse the name of the parameter.