Skip to content

Commit 3f8d80a

Browse files
committed
Fix infinite recursion at the end of a file
1 parent b3c5fde commit 3f8d80a

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4346,8 +4346,8 @@ bool Parser::isStartOfSwiftDecl(bool allowPoundIfAttributes) {
43464346
if (Tok.is(tok::pound_if) && allowPoundIfAttributes) {
43474347
BacktrackingScope backtrack(*this);
43484348
bool sawAnyAttributes = false;
4349-
return skipIfConfigOfAttributes(sawAnyAttributes) && sawAnyAttributes &&
4350-
isStartOfSwiftDecl();
4349+
return skipIfConfigOfAttributes(sawAnyAttributes) &&
4350+
(Tok.is(tok::eof) || (sawAnyAttributes && isStartOfSwiftDecl()));
43514351
}
43524352

43534353
// If we have a decl modifying keyword, check if the next token is a valid

lib/Parse/ParseIfConfig.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,10 @@ bool Parser::skipIfConfigOfAttributes(bool &sawAnyAttributes) {
962962
break;
963963
}
964964

965+
// If we ran out of tokens, say we consumed the rest.
966+
if (Tok.is(tok::eof))
967+
return true;
968+
965969
return Tok.isAtStartOfLine() && consumeIf(tok::pound_endif);
966970
}
967971

0 commit comments

Comments
 (0)