From: Rafael Espindola Date: Thu, 25 Jul 2013 02:11:20 +0000 (+0000) Subject: Avoid recursions when the parser finds out that it has too many brackets. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d66bf94f527c6bd24089615ee3a0b74a2ec35310;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@187097 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp index 2c6d6b329d..036278f72e 100644 --- a/lib/Parse/Parser.cpp +++ b/lib/Parse/Parser.cpp @@ -279,6 +279,16 @@ bool Parser::SkipUntil(ArrayRef 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; }