diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2013-09-19 00:41:32 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2013-09-19 00:41:32 +0000 |
commit | d2f9308220af22bfc1bcd3bc2cad118dbd8be013 (patch) | |
tree | 3bff718c87a2ac543d1afd1bd223882c4795885e /lib/Lex/PTHLexer.cpp | |
parent | dce250be480d32c9ce8a705936ac6e3c94ded2cb (diff) |
Make Preprocessor::Lex non-recursive.
Before this patch, Lex() would recurse whenever the current lexer changed (e.g.
upon entry into a macro). This patch turns the recursion into a loop: the
various lex routines now don't return a token when the current lexer changes,
and at the top level Preprocessor::Lex() now loops until it finds a token.
Normally, the recursion wouldn't end up being very deep, but the recursion depth
can explode in edge cases like a bunch of consecutive macros which expand to
nothing (like in the testcase test/Preprocessor/macro_expand_empty.c in this
patch).
<rdar://problem/14569770>
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190980 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex/PTHLexer.cpp')
-rw-r--r-- | lib/Lex/PTHLexer.cpp | 25 |
1 files changed, 8 insertions, 17 deletions
diff --git a/lib/Lex/PTHLexer.cpp b/lib/Lex/PTHLexer.cpp index 32da92ad53..e2629a3b2c 100644 --- a/lib/Lex/PTHLexer.cpp +++ b/lib/Lex/PTHLexer.cpp @@ -43,9 +43,7 @@ PTHLexer::PTHLexer(Preprocessor &PP, FileID FID, const unsigned char *D, FileStartLoc = PP.getSourceManager().getLocForStartOfFile(FID); } -void PTHLexer::Lex(Token& Tok) { -LexNextToken: - +bool PTHLexer::Lex(Token& Tok) { //===--------------------------------------==// // Read the raw token data. //===--------------------------------------==// @@ -90,8 +88,9 @@ LexNextToken: Tok.setKind(II->getTokenID()); if (II->isHandleIdentifierCase()) - PP->HandleIdentifier(Tok); - return; + return PP->HandleIdentifier(Tok); + + return true; } //===--------------------------------------==// @@ -101,16 +100,10 @@ LexNextToken: // Save the end-of-file token. EofToken = Tok; - // Save 'PP' to 'PPCache' as LexEndOfFile can delete 'this'. - Preprocessor *PPCache = PP; - assert(!ParsingPreprocessorDirective); assert(!LexingRawMode); - - if (LexEndOfFile(Tok)) - return; - return PPCache->Lex(Tok); + return LexEndOfFile(Tok); } if (TKind == tok::hash && Tok.isAtStartOfLine()) { @@ -118,19 +111,17 @@ LexNextToken: assert(!LexingRawMode); PP->HandleDirective(Tok); - if (PP->isCurrentLexer(this)) - goto LexNextToken; - - return PP->Lex(Tok); + return false; } if (TKind == tok::eod) { assert(ParsingPreprocessorDirective); ParsingPreprocessorDirective = false; - return; + return true; } MIOpt.ReadToken(); + return true; } bool PTHLexer::LexEndOfFile(Token &Result) { |