[cfe-commits] r63764 - in /cfe/trunk: lib/Lex/PPDirectives.cpp test/Preprocessor/include-directive1.c test/Preprocessor/include-directive3.c

Chris Lattner sabre at nondot.org
Wed Feb 4 11:45:07 PST 2009


Author: lattner
Date: Wed Feb  4 13:45:07 2009
New Revision: 63764

URL: http://llvm.org/viewvc/llvm-project?rev=63764&view=rev
Log:
Fix PR3464 by searching for headers from the predefines
buffer as if the #include happened from the main file.

Added:
    cfe/trunk/test/Preprocessor/include-directive3.c
Modified:
    cfe/trunk/lib/Lex/PPDirectives.cpp
    cfe/trunk/test/Preprocessor/include-directive1.c

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=63764&r1=63763&r2=63764&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Wed Feb  4 13:45:07 2009
@@ -399,13 +399,24 @@
   if (!FromDir) {
     FileID FID = getCurrentFileLexer()->getFileID();
     CurFileEnt = SourceMgr.getFileEntryForID(FID);
+    
+    // If there is no file entry associated with this file, it must be the
+    // predefines buffer.  Any other file is not lexed with a normal lexer, so
+    // it won't be scanned for preprocessor directives.   If we have the
+    // predefines buffer, resolve #include references (which come from the
+    // -include command line argument) as if they came from the main file, this
+    // affects file lookup etc.
+    if (CurFileEnt == 0) {
+      FID = SourceMgr.getMainFileID();
+      CurFileEnt = SourceMgr.getFileEntryForID(FID);
+    }
   }
   
   // Do a standard file entry lookup.
   CurDir = CurDirLookup;
   const FileEntry *FE =
-  HeaderInfo.LookupFile(FilenameStart, FilenameEnd,
-                        isAngled, FromDir, CurDir, CurFileEnt);
+    HeaderInfo.LookupFile(FilenameStart, FilenameEnd,
+                          isAngled, FromDir, CurDir, CurFileEnt);
   if (FE) return FE;
   
   // Otherwise, see if this is a subframework header.  If so, this is relative

Modified: cfe/trunk/test/Preprocessor/include-directive1.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/include-directive1.c?rev=63764&r1=63763&r2=63764&view=diff

==============================================================================
--- cfe/trunk/test/Preprocessor/include-directive1.c (original)
+++ cfe/trunk/test/Preprocessor/include-directive1.c Wed Feb  4 13:45:07 2009
@@ -1,4 +1,3 @@
-
 // RUN: clang -E %s -fno-caret-diagnostics 2>&1 >/dev/null | grep 'file successfully included' | count 3
 
 // XX expands to nothing.
@@ -13,7 +12,3 @@
 // normal include
 #include "file_to_include.h"
 
-// Expand and paste angled strings.
-#  define HEADER <file_to_include.h>
-#  include HEADER
-

Added: cfe/trunk/test/Preprocessor/include-directive3.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/include-directive3.c?rev=63764&view=auto

==============================================================================
--- cfe/trunk/test/Preprocessor/include-directive3.c (added)
+++ cfe/trunk/test/Preprocessor/include-directive3.c Wed Feb  4 13:45:07 2009
@@ -0,0 +1,3 @@
+// RUN: clang -include file_to_include.h -E %s -fno-caret-diagnostics 2>&1 >/dev/null | grep 'file successfully included' | count 1
+// PR3464
+





More information about the cfe-commits mailing list