summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/include/clang/Basic/FileManager.h5
-rw-r--r--clang/lib/Basic/FileManager.cpp7
-rw-r--r--clang/lib/Lex/HeaderSearch.cpp15
3 files changed, 17 insertions, 10 deletions
diff --git a/clang/include/clang/Basic/FileManager.h b/clang/include/clang/Basic/FileManager.h
index 57f7d71660d..40f6d865636 100644
--- a/clang/include/clang/Basic/FileManager.h
+++ b/clang/include/clang/Basic/FileManager.h
@@ -176,10 +176,11 @@ public:
///
const DirectoryEntry *getDirectory(llvm::StringRef DirName);
- /// getFile - Lookup, cache, and verify the specified file (real or
+ /// \brief Lookup, cache, and verify the specified file (real or
/// virtual). This returns NULL if the file doesn't exist.
///
- const FileEntry *getFile(llvm::StringRef Filename);
+ /// \param openFile if true and the file exists, it will be opened.
+ const FileEntry *getFile(llvm::StringRef Filename, bool openFile = false);
/// \brief Retrieve a file entry for a "virtual" file that acts as
/// if there were a file with the given name on disk. The file
diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp
index 9ad6e51a837..1a8b01938ed 100644
--- a/clang/lib/Basic/FileManager.cpp
+++ b/clang/lib/Basic/FileManager.cpp
@@ -313,7 +313,7 @@ const DirectoryEntry *FileManager::getDirectory(llvm::StringRef DirName) {
/// getFile - Lookup, cache, and verify the specified file (real or
/// virtual). This returns NULL if the file doesn't exist.
///
-const FileEntry *FileManager::getFile(llvm::StringRef Filename) {
+const FileEntry *FileManager::getFile(llvm::StringRef Filename, bool openFile) {
++NumFileLookups;
// See if there is already an entry in the map.
@@ -354,6 +354,11 @@ const FileEntry *FileManager::getFile(llvm::StringRef Filename) {
return 0;
}
+ if (FileDescriptor != -1 && !openFile) {
+ close(FileDescriptor);
+ FileDescriptor = -1;
+ }
+
// It exists. See if we have already opened a file with the same inode.
// This occurs when one dir is symlinked to another, for example.
FileEntry &UFE = UniqueRealFiles.getFile(InterndFileName, StatBuf);
diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp
index bb4ff60480f..db91ba4e78f 100644
--- a/clang/lib/Lex/HeaderSearch.cpp
+++ b/clang/lib/Lex/HeaderSearch.cpp
@@ -126,7 +126,7 @@ const FileEntry *DirectoryLookup::LookupFile(
TmpDir.append(Filename.begin(), Filename.end());
if (RawPath != NULL)
*RawPath = TmpDir;
- return HS.getFileMgr().getFile(TmpDir.str());
+ return HS.getFileMgr().getFile(TmpDir.str(), /*openFile=*/true);
}
if (isFramework())
@@ -192,7 +192,8 @@ const FileEntry *DirectoryLookup::DoFrameworkLookup(
FrameworkName += "Headers/";
FrameworkName.append(Filename.begin()+SlashPos+1, Filename.end());
- if (const FileEntry *FE = FileMgr.getFile(FrameworkName.str())) {
+ if (const FileEntry *FE = FileMgr.getFile(FrameworkName.str(),
+ /*openFile=*/true)) {
if (RawPath != NULL)
*RawPath = FrameworkName;
return FE;
@@ -204,7 +205,7 @@ const FileEntry *DirectoryLookup::DoFrameworkLookup(
Private+strlen(Private));
if (RawPath != NULL)
*RawPath = FrameworkName;
- return FileMgr.getFile(FrameworkName.str());
+ return FileMgr.getFile(FrameworkName.str(), /*openFile=*/true);
}
@@ -235,7 +236,7 @@ const FileEntry *HeaderSearch::LookupFile(
if (RawPath != NULL)
llvm::Twine(Filename).toVector(*RawPath);
// Otherwise, just return the file.
- return FileMgr.getFile(Filename);
+ return FileMgr.getFile(Filename, /*openFile=*/true);
}
// Step #0, unless disabled, check to see if the file is in the #includer's
@@ -250,7 +251,7 @@ const FileEntry *HeaderSearch::LookupFile(
TmpDir += CurFileEnt->getDir()->getName();
TmpDir.push_back('/');
TmpDir.append(Filename.begin(), Filename.end());
- if (const FileEntry *FE = FileMgr.getFile(TmpDir.str())) {
+ if (const FileEntry *FE = FileMgr.getFile(TmpDir.str(),/*openFile=*/true)) {
// Leave CurDir unset.
// This file is a system header or C++ unfriendly if the old file is.
//
@@ -376,13 +377,13 @@ LookupSubframeworkHeader(llvm::StringRef Filename,
llvm::SmallString<1024> HeadersFilename(FrameworkName);
HeadersFilename += "Headers/";
HeadersFilename.append(Filename.begin()+SlashPos+1, Filename.end());
- if (!(FE = FileMgr.getFile(HeadersFilename.str()))) {
+ if (!(FE = FileMgr.getFile(HeadersFilename.str(), /*openFile=*/true))) {
// Check ".../Frameworks/HIToolbox.framework/PrivateHeaders/HIToolbox.h"
HeadersFilename = FrameworkName;
HeadersFilename += "PrivateHeaders/";
HeadersFilename.append(Filename.begin()+SlashPos+1, Filename.end());
- if (!(FE = FileMgr.getFile(HeadersFilename.str())))
+ if (!(FE = FileMgr.getFile(HeadersFilename.str(), /*openFile=*/true)))
return 0;
}
if (RawPath != NULL)
OpenPOWER on IntegriCloud