summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-02-04 19:45:07 +0000
committerChris Lattner <sabre@nondot.org>2009-02-04 19:45:07 +0000
commit022923a22a616a97685af71862a7a9833af23b65 (patch)
tree94c9354ff645272c3ef7806c58955f13881cca6d
parent7ead0396f6fba6199ddebc1993a5e7d26d33181d (diff)
downloadbcm5719-llvm-022923a22a616a97685af71862a7a9833af23b65.tar.gz
bcm5719-llvm-022923a22a616a97685af71862a7a9833af23b65.zip
Fix PR3464 by searching for headers from the predefines
buffer as if the #include happened from the main file. llvm-svn: 63764
-rw-r--r--clang/lib/Lex/PPDirectives.cpp15
-rw-r--r--clang/test/Preprocessor/include-directive1.c5
-rw-r--r--clang/test/Preprocessor/include-directive3.c3
3 files changed, 16 insertions, 7 deletions
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 00cb62384e3..c38310b925f 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -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
diff --git a/clang/test/Preprocessor/include-directive1.c b/clang/test/Preprocessor/include-directive1.c
index 632760b7cd3..3e449c52689 100644
--- a/clang/test/Preprocessor/include-directive1.c
+++ b/clang/test/Preprocessor/include-directive1.c
@@ -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/clang/test/Preprocessor/include-directive3.c b/clang/test/Preprocessor/include-directive3.c
new file mode 100644
index 00000000000..9e22d5d4920
--- /dev/null
+++ b/clang/test/Preprocessor/include-directive3.c
@@ -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
+
OpenPOWER on IntegriCloud