]> granicus.if.org Git - clang/commitdiff
Make __has_include a bit more resilient in the presence of macros. <rdar://problem...
authorEli Friedman <eli.friedman@gmail.com>
Wed, 9 Jan 2013 02:20:00 +0000 (02:20 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Wed, 9 Jan 2013 02:20:00 +0000 (02:20 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171939 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/PPMacroExpansion.cpp
test/Preprocessor/has_include.c

index 3de6cdb39dd30fbee71dfbb68b10c9cc6a248692..1b8fcbac3317aa01433c464923d76df240487488 100644 (file)
@@ -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.
index 10f7795fc34a64be75d2781e34e73245c2233e5f..985501a2151f1e97f3bce33f11ad32236ee594d2 100644 (file)
   #error "defined(__has_include_next) failed (8)."
 #endif
 
+// Fun with macros
+#define MACRO1 __has_include(<stdint.h>)
+#define MACRO2 ("stdint.h")
+#define MACRO3 ("blahblah.h")
+#define MACRO4 blahblah.h>)
+#define MACRO5 <stdint.h>
+
+#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(<MACRO4
+  #error "__has_include with macro failed (4)."
+#endif
+
+#if !__has_include(MACRO5)
+  #error "__has_include with macro failed (2)."
+#endif
+
 // Try badly formed expressions.
 // FIXME: We can recover better in almost all of these cases. (PR13335)