Avoid recursions when the parser finds out that it has too many brackets.

BalancedDelimiterTracker::diagnoseOverflow calls P.SkipUntil, and before this
patch P.SkipUnti is recursive, causing problems on systems with small stacks.
This patch fixes it by making P.SkipUnti non recursive when just looking for
eof.

llvm-svn: 187097
This commit is contained in:
Rafael Espindola 2013-07-25 02:11:20 +00:00
parent ad3ab2ae61
commit 885a0c494d
1 changed files with 11 additions and 1 deletions

View File

@ -279,6 +279,16 @@ bool Parser::SkipUntil(ArrayRef<tok::TokenKind> Toks, bool StopAtSemi,
}
}
// Important special case: The caller has given up and just wants us to
// skip the rest of the file. Do this without recursing, since we can
// get here precisely because the caller detected too much recursion.
if (Toks.size() == 1 && Toks[0] == tok::eof && !StopAtSemi &&
!StopAtCodeCompletion) {
while (Tok.getKind() != tok::eof)
ConsumeAnyToken();
return true;
}
switch (Tok.getKind()) {
case tok::eof:
// Ran out of tokens.
@ -1908,7 +1918,7 @@ bool BalancedDelimiterTracker::diagnoseOverflow() {
P.Diag(P.Tok, diag::err_bracket_depth_exceeded)
<< P.getLangOpts().BracketDepth;
P.Diag(P.Tok, diag::note_bracket_depth);
P.SkipUntil(tok::eof, FinalToken);
P.SkipUntil(tok::eof, false);
return true;
}