]> granicus.if.org Git - clang/commitdiff
Fix PR3464 by searching for headers from the predefines
authorChris Lattner <sabre@nondot.org>
Wed, 4 Feb 2009 19:45:07 +0000 (19:45 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 4 Feb 2009 19:45:07 +0000 (19:45 +0000)
buffer as if the #include happened from the main file.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63764 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/PPDirectives.cpp
test/Preprocessor/include-directive1.c
test/Preprocessor/include-directive3.c [new file with mode: 0644]

index 00cb62384e3502f559e96c024c84deab740f0c5f..c38310b925f93502c3f2c99682dba78c320ea139 100644 (file)
@@ -399,13 +399,24 @@ const FileEntry *Preprocessor::LookupFile(const char *FilenameStart,
   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
index 632760b7cd3c346da4b7e33d7f26aa46529936bd..3e449c526895c6058efea1b36f2e1b6fb255f2de 100644 (file)
@@ -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
-
diff --git a/test/Preprocessor/include-directive3.c b/test/Preprocessor/include-directive3.c
new file mode 100644 (file)
index 0000000..9e22d5d
--- /dev/null
@@ -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
+