[cfe-commits] r171939 - in /cfe/trunk: lib/Lex/PPMacroExpansion.cpp test/Preprocessor/has_include.c

Eli Friedman eli.friedman at gmail.com
Tue Jan 8 18:20:00 PST 2013


Author: efriedma
Date: Tue Jan  8 20:20:00 2013
New Revision: 171939

URL: http://llvm.org/viewvc/llvm-project?rev=171939&view=rev
Log:
Make __has_include a bit more resilient in the presence of macros.  <rdar://problem/12748859>.


Modified:
    cfe/trunk/lib/Lex/PPMacroExpansion.cpp
    cfe/trunk/test/Preprocessor/has_include.c

Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=171939&r1=171938&r2=171939&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Tue Jan  8 20:20:00 2013
@@ -985,8 +985,14 @@
     // 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.

Modified: cfe/trunk/test/Preprocessor/has_include.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/has_include.c?rev=171939&r1=171938&r2=171939&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/has_include.c (original)
+++ cfe/trunk/test/Preprocessor/has_include.c Tue Jan  8 20:20:00 2013
@@ -64,6 +64,33 @@
   #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)
 





More information about the cfe-commits mailing list