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. llvm-svn: 177345
This commit is contained in:
parent
008322f2b0
commit
1dc4a3dfd6
|
@ -2082,7 +2082,6 @@ void Preprocessor::HandleIfdefDirective(Token &Result, bool isIfndef,
|
|||
///
|
||||
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(Token &Result) {
|
|||
/// 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.
|
||||
|
|
|
@ -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(PPValue &LHS, unsigned MinPrec,
|
|||
/// 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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue