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

Rafael Espindola rafael.espindola at gmail.com
Wed Jul 24 19:11:20 PDT 2013


Author: rafael
Date: Wed Jul 24 21:11:20 2013
New Revision: 187097

URL: http://llvm.org/viewvc/llvm-project?rev=187097&view=rev
Log:
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.

Modified:
    cfe/trunk/lib/Parse/Parser.cpp

Modified: cfe/trunk/lib/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=187097&r1=187096&r2=187097&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/Parser.cpp (original)
+++ cfe/trunk/lib/Parse/Parser.cpp Wed Jul 24 21:11:20 2013
@@ -279,6 +279,16 @@ bool Parser::SkipUntil(ArrayRef<tok::Tok
       }
     }
 
+    // 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::diagnoseO
   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;  
 }
 





More information about the cfe-commits mailing list