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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177345 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp
index 8379ca8..e19eb31 100644
--- a/lib/Lex/PPDirectives.cpp
+++ b/lib/Lex/PPDirectives.cpp
@@ -2082,7 +2082,6 @@
///
void Preprocessor::HandleIfDirective(Token &IfToken,
bool ReadAnyTokensBeforeDirective) {
- SaveAndRestore<bool> PPDir(ParsingIfOrElifDirective, true);
++NumIf;
// Parse and evaluate the conditional expression.
@@ -2174,7 +2173,6 @@
/// 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.
diff --git a/lib/Lex/PPExpressions.cpp b/lib/Lex/PPExpressions.cpp
index 49f4cbf..27ad7b4 100644
--- a/lib/Lex/PPExpressions.cpp
+++ b/lib/Lex/PPExpressions.cpp
@@ -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 @@
/// 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
diff --git a/test/Preprocessor/has_include.c b/test/Preprocessor/has_include.c
index 7cc67fa..131e519 100644
--- a/test/Preprocessor/has_include.c
+++ b/test/Preprocessor/has_include.c
@@ -176,3 +176,12 @@
#else
#error "__has_include failed (9)."
#endif
+
+#if FOO
+#elif __has_include(<foo>)
+#endif
+
+// PR15539
+#ifdef FOO
+#elif __has_include(<foo>)
+#endif