From a0f2d02d166880e5d826074b6c2ecbf64f8ca70d Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Wed, 9 Jan 2013 02:20:00 +0000 Subject: [PATCH] Make __has_include a bit more resilient in the presence of macros. . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171939 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Lex/PPMacroExpansion.cpp | 10 ++++++++-- test/Preprocessor/has_include.c | 27 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/lib/Lex/PPMacroExpansion.cpp b/lib/Lex/PPMacroExpansion.cpp index 3de6cdb39d..1b8fcbac33 100644 --- a/lib/Lex/PPMacroExpansion.cpp +++ b/lib/Lex/PPMacroExpansion.cpp @@ -985,8 +985,14 @@ static bool EvaluateHasIncludeCommon(Token &Tok, // Save '(' location for possible missing ')' message. LParenLoc = Tok.getLocation(); - // Get the file name. - PP.getCurrentLexer()->LexIncludeFilename(Tok); + if (PP.getCurrentLexer()) { + // Get the file name. + PP.getCurrentLexer()->LexIncludeFilename(Tok); + } else { + // We're in a macro, so we can't use LexIncludeFilename; just + // grab the next token. + PP.Lex(Tok); + } } // Reserve a buffer to get the spelling. diff --git a/test/Preprocessor/has_include.c b/test/Preprocessor/has_include.c index 10f7795fc3..985501a215 100644 --- a/test/Preprocessor/has_include.c +++ b/test/Preprocessor/has_include.c @@ -64,6 +64,33 @@ #error "defined(__has_include_next) failed (8)." #endif +// Fun with macros +#define MACRO1 __has_include() +#define MACRO2 ("stdint.h") +#define MACRO3 ("blahblah.h") +#define MACRO4 blahblah.h>) +#define MACRO5 + +#if !MACRO1 + #error "__has_include with macro failed (1)." +#endif + +#if !__has_include MACRO2 + #error "__has_include with macro failed (2)." +#endif + +#if __has_include MACRO3 + #error "__has_include with macro failed (3)." +#endif + +#if __has_include(