r177345 - PR15539: Record "evaluating if/elif condition" flag in the right place
David Blaikie
dblaikie at gmail.com
Mon Mar 18 16:22:28 PDT 2013
Author: dblaikie
Date: Mon Mar 18 18:22:28 2013
New Revision: 177345
URL: http://llvm.org/viewvc/llvm-project?rev=177345&view=rev
Log:
PR15539: Record "evaluating if/elif condition" flag in the right place
The previous implementation missed the case where the elif condition was
evaluated from the context of an #ifdef that was false causing PR15539.
Modified:
cfe/trunk/lib/Lex/PPDirectives.cpp
cfe/trunk/lib/Lex/PPExpressions.cpp
cfe/trunk/test/Preprocessor/has_include.c
Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=177345&r1=177344&r2=177345&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Mon Mar 18 18:22:28 2013
@@ -2082,7 +2082,6 @@ void Preprocessor::HandleIfdefDirective(
///
void Preprocessor::HandleIfDirective(Token &IfToken,
bool ReadAnyTokensBeforeDirective) {
- SaveAndRestore<bool> PPDir(ParsingIfOrElifDirective, true);
++NumIf;
// Parse and evaluate the conditional expression.
@@ -2174,7 +2173,6 @@ void Preprocessor::HandleElseDirective(T
/// HandleElifDirective - Implements the \#elif directive.
///
void Preprocessor::HandleElifDirective(Token &ElifToken) {
- SaveAndRestore<bool> PPDir(ParsingIfOrElifDirective, true);
++NumElse;
// #elif directive in a non-skipping conditional... start skipping.
Modified: cfe/trunk/lib/Lex/PPExpressions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPExpressions.cpp?rev=177345&r1=177344&r2=177345&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPExpressions.cpp (original)
+++ cfe/trunk/lib/Lex/PPExpressions.cpp Mon Mar 18 18:22:28 2013
@@ -24,6 +24,7 @@
#include "clang/Lex/MacroInfo.h"
#include "llvm/ADT/APSInt.h"
#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/SaveAndRestore.h"
using namespace clang;
namespace {
@@ -730,6 +731,7 @@ static bool EvaluateDirectiveSubExpr(PPV
/// to "!defined(X)" return X in IfNDefMacro.
bool Preprocessor::
EvaluateDirectiveExpression(IdentifierInfo *&IfNDefMacro) {
+ SaveAndRestore<bool> PPDir(ParsingIfOrElifDirective, true);
// Save the current state of 'DisableMacroExpansion' and reset it to false. If
// 'DisableMacroExpansion' is true, then we must be in a macro argument list
// in which case a directive is undefined behavior. We want macros to be able
Modified: cfe/trunk/test/Preprocessor/has_include.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/has_include.c?rev=177345&r1=177344&r2=177345&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/has_include.c (original)
+++ cfe/trunk/test/Preprocessor/has_include.c Mon Mar 18 18:22:28 2013
@@ -176,3 +176,12 @@ __has_include
#else
#error "__has_include failed (9)."
#endif
+
+#if FOO
+#elif __has_include(<foo>)
+#endif
+
+// PR15539
+#ifdef FOO
+#elif __has_include(<foo>)
+#endif
More information about the cfe-commits
mailing list