summaryrefslogtreecommitdiffstats
path: root/clang/lib/Lex/HeaderSearch.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-08-06 12:06:13 +0000
committerDouglas Gregor <dgregor@apple.com>2010-08-06 12:06:13 +0000
commitd26129a98a04e40be415fe7b89898b2ff7abdd74 (patch)
treebe2bc2b5672dc7aa0b1bd4443ba544b29e4d46bf /clang/lib/Lex/HeaderSearch.cpp
parent2588691a6960362abb1258b59a3b75403d15806d (diff)
downloadbcm5719-llvm-d26129a98a04e40be415fe7b89898b2ff7abdd74.tar.gz
bcm5719-llvm-d26129a98a04e40be415fe7b89898b2ff7abdd74.zip
Fix the #include search path when reading from stdin, from Jon Simons!
Fixes PR4897. llvm-svn: 110440
Diffstat (limited to 'clang/lib/Lex/HeaderSearch.cpp')
-rw-r--r--clang/lib/Lex/HeaderSearch.cpp44
1 files changed, 24 insertions, 20 deletions
diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp
index 4554ababf76..dfd99cec5b5 100644
--- a/clang/lib/Lex/HeaderSearch.cpp
+++ b/clang/lib/Lex/HeaderSearch.cpp
@@ -203,14 +203,14 @@ const FileEntry *DirectoryLookup::DoFrameworkLookup(llvm::StringRef Filename,
/// LookupFile - Given a "foo" or <foo> reference, look up the indicated file,
/// return null on failure. isAngled indicates whether the file reference is
-/// for system #include's or not (i.e. using <> instead of ""). CurFileEnt, if
-/// non-null, indicates where the #including file is, in case a relative search
-/// is needed.
+/// for system #include's or not (i.e. using <> instead of ""). RelSearchDir,
+/// if non-empty, indicates where the #including file is, in case a relative
+/// search is needed.
const FileEntry *HeaderSearch::LookupFile(llvm::StringRef Filename,
bool isAngled,
const DirectoryLookup *FromDir,
const DirectoryLookup *&CurDir,
- const FileEntry *CurFileEnt) {
+ const llvm::sys::Path &RelPath) {
// If 'Filename' is absolute, check to see if it exists and no searching.
if (llvm::sys::Path::isAbsolute(Filename.begin(), Filename.size())) {
CurDir = 0;
@@ -223,25 +223,29 @@ const FileEntry *HeaderSearch::LookupFile(llvm::StringRef Filename,
}
// Step #0, unless disabled, check to see if the file is in the #includer's
- // directory. This has to be based on CurFileEnt, not CurDir, because
- // CurFileEnt could be a #include of a subdirectory (#include "foo/bar.h") and
+ // directory. This has to be based on RelPath, not CurDir, because
+ // RelPath could be a #include of a subdirectory (#include "foo/bar.h") and
// a subsequent include of "baz.h" should resolve to "whatever/foo/baz.h".
// This search is not done for <> headers.
- if (CurFileEnt && !isAngled && !NoCurDirSearch) {
- llvm::SmallString<1024> TmpDir;
- // Concatenate the requested file onto the directory.
- // FIXME: Portability. Filename concatenation should be in sys::Path.
- TmpDir += CurFileEnt->getDir()->getName();
- TmpDir.push_back('/');
- TmpDir.append(Filename.begin(), Filename.end());
- if (const FileEntry *FE = FileMgr.getFile(TmpDir.str())) {
+ if (!RelPath.isEmpty() && !isAngled && !NoCurDirSearch) {
+
+ // Default SrcMgr::CharacteristicKind
+ unsigned DirInfo = SrcMgr::C_User;
+ llvm::sys::Path TmpPath(RelPath);
+
+ // Update DirInfo if needed and remove filename from path if
+ // treating actual file (the non-stdin case)
+ if (!TmpPath.isDirectory()) {
+ const FileEntry *MainFile = FileMgr.getFile(TmpPath.c_str());
+ DirInfo = getFileInfo(MainFile).DirInfo;
+ TmpPath.eraseComponent();
+ }
+
+ // Formulate path to try
+ TmpPath.appendComponent(Filename);
+ llvm::StringRef RelSearchFilename(TmpPath.c_str());
+ if (const FileEntry *FE = FileMgr.getFile(RelSearchFilename)) {
// Leave CurDir unset.
- // This file is a system header or C++ unfriendly if the old file is.
- //
- // Note that the temporary 'DirInfo' is required here, as either call to
- // getFileInfo could resize the vector and we don't want to rely on order
- // of evaluation.
- unsigned DirInfo = getFileInfo(CurFileEnt).DirInfo;
getFileInfo(FE).DirInfo = DirInfo;
return FE;
}
OpenPOWER on IntegriCloud