summaryrefslogtreecommitdiffstats
path: root/clang/lib/Parse/Parser.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2013-07-25 02:11:20 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2013-07-25 02:11:20 +0000
commit885a0c494d2ba8776f43c7b0585cd629c8000286 (patch)
tree0ec0d4aad3e2a6cd2636b0be5b5df38a7a493891 /clang/lib/Parse/Parser.cpp
parentad3ab2ae61a105fb33454bf503032447a2e96e4f (diff)
downloadbcm5719-llvm-885a0c494d2ba8776f43c7b0585cd629c8000286.tar.gz
bcm5719-llvm-885a0c494d2ba8776f43c7b0585cd629c8000286.zip
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
Diffstat (limited to 'clang/lib/Parse/Parser.cpp')
-rw-r--r--clang/lib/Parse/Parser.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 2c6d6b329dd..036278f72ed 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -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;
}
OpenPOWER on IntegriCloud