diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2011-08-03 00:04:13 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2011-08-03 00:04:13 +0000 |
commit | 88710f22be1acb04b7d812aebe87bea56394c07c (patch) | |
tree | 647f722b97d3c9f51785c7d7d33d1ce4392d928c /lib/Lex/PPExpressions.cpp | |
parent | e164c180527354acc16c1b9b2c5a5ed4a1e484d4 (diff) |
A couple fixes for preprocessor expressions:
1. Be more tolerant of comments in -CC (comment-preserving) mode. We were missing a few cases.
2. Make sure to expand the second FOO in "#if defined FOO FOO". (See also
r97253, which addressed the case of "#if defined(FOO FOO".)
Fixes PR10286.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@136748 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex/PPExpressions.cpp')
-rw-r--r-- | lib/Lex/PPExpressions.cpp | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/lib/Lex/PPExpressions.cpp b/lib/Lex/PPExpressions.cpp index 25816923c8..7f00e6ee96 100644 --- a/lib/Lex/PPExpressions.cpp +++ b/lib/Lex/PPExpressions.cpp @@ -83,20 +83,20 @@ static bool EvaluateDefined(PPValue &Result, Token &PeekTok, DefinedTracker &DT, Result.setBegin(PeekTok.getLocation()); // Get the next token, don't expand it. - PP.LexUnexpandedToken(PeekTok); + PP.LexUnexpandedNonComment(PeekTok); // Two options, it can either be a pp-identifier or a (. SourceLocation LParenLoc; if (PeekTok.is(tok::l_paren)) { // Found a paren, remember we saw it and skip it. LParenLoc = PeekTok.getLocation(); - PP.LexUnexpandedToken(PeekTok); + PP.LexUnexpandedNonComment(PeekTok); } if (PeekTok.is(tok::code_completion)) { if (PP.getCodeCompletionHandler()) PP.getCodeCompletionHandler()->CodeCompleteMacroName(false); - PP.LexUnexpandedToken(PeekTok); + PP.LexUnexpandedNonComment(PeekTok); } // If we don't have a pp-identifier now, this is an error. @@ -115,12 +115,12 @@ static bool EvaluateDefined(PPValue &Result, Token &PeekTok, DefinedTracker &DT, PP.markMacroAsUsed(Macro); } - // Consume identifier. - Result.setEnd(PeekTok.getLocation()); - PP.LexUnexpandedToken(PeekTok); - // If we are in parens, ensure we have a trailing ). if (LParenLoc.isValid()) { + // Consume identifier. + Result.setEnd(PeekTok.getLocation()); + PP.LexUnexpandedNonComment(PeekTok); + if (PeekTok.isNot(tok::r_paren)) { PP.Diag(PeekTok.getLocation(), diag::err_pp_missing_rparen) << "defined"; PP.Diag(LParenLoc, diag::note_matching) << "("; @@ -129,6 +129,10 @@ static bool EvaluateDefined(PPValue &Result, Token &PeekTok, DefinedTracker &DT, // Consume the ). Result.setEnd(PeekTok.getLocation()); PP.LexNonComment(PeekTok); + } else { + // Consume identifier. + Result.setEnd(PeekTok.getLocation()); + PP.LexNonComment(PeekTok); } // Success, remember that we saw defined(X). @@ -152,7 +156,7 @@ static bool EvaluateValue(PPValue &Result, Token &PeekTok, DefinedTracker &DT, if (PeekTok.is(tok::code_completion)) { if (PP.getCodeCompletionHandler()) PP.getCodeCompletionHandler()->CodeCompletePreprocessorExpression(); - PP.LexUnexpandedToken(PeekTok); + PP.LexNonComment(PeekTok); } // If this token's spelling is a pp-identifier, check to see if it is @@ -712,7 +716,7 @@ EvaluateDirectiveExpression(IdentifierInfo *&IfNDefMacro) { // Peek ahead one token. Token Tok; - Lex(Tok); + LexNonComment(Tok); // C99 6.10.1p3 - All expressions are evaluated as intmax_t or uintmax_t. unsigned BitWidth = getTargetInfo().getIntMaxTWidth(); |