diff options
author | Kadir Cetinkaya <kadircet@google.com> | 2018-11-30 17:10:11 +0000 |
---|---|---|
committer | Kadir Cetinkaya <kadircet@google.com> | 2018-11-30 17:10:11 +0000 |
commit | e9870c0c9145a2b261054348c7979333b8ed6655 (patch) | |
tree | f5a7a63a32ed572f52ab85696a0c71dcb619cb57 /clang/lib/Basic/FileManager.cpp | |
parent | 5399552da165f40f21910f088aa9270086dcc89a (diff) | |
download | bcm5719-llvm-e9870c0c9145a2b261054348c7979333b8ed6655.tar.gz bcm5719-llvm-e9870c0c9145a2b261054348c7979333b8ed6655.zip |
[clang] Fill RealPathName for virtual files.
Summary:
Absolute path information for virtual files were missing even if we
have already stat'd the files. This patch puts that information for virtual
files that can succesffully be stat'd.
Reviewers: ilya-biryukov
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D55054
llvm-svn: 348006
Diffstat (limited to 'clang/lib/Basic/FileManager.cpp')
-rw-r--r-- | clang/lib/Basic/FileManager.cpp | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp index 21cb92d51c2..455d25c100a 100644 --- a/clang/lib/Basic/FileManager.cpp +++ b/clang/lib/Basic/FileManager.cpp @@ -293,16 +293,8 @@ const FileEntry *FileManager::getFile(StringRef Filename, bool openFile, // If we opened the file for the first time, record the resulting info. // Do this even if the cache entry was valid, maybe we didn't previously open. if (F && !UFE.File) { - if (auto PathName = F->getName()) { - llvm::SmallString<128> AbsPath(*PathName); - // This is not the same as `VFS::getRealPath()`, which resolves symlinks - // but can be very expensive on real file systems. - // FIXME: the semantic of RealPathName is unclear, and the name might be - // misleading. We need to clean up the interface here. - makeAbsolutePath(AbsPath); - llvm::sys::path::remove_dots(AbsPath, /*remove_dot_dot=*/true); - UFE.RealPathName = AbsPath.str(); - } + if (auto PathName = F->getName()) + fillRealPathName(&UFE, *PathName); UFE.File = std::move(F); assert(!UFE.DeferredOpen && "we just opened it!"); } @@ -395,6 +387,7 @@ FileManager::getVirtualFile(StringRef Filename, off_t Size, UFE->UniqueID = Data.UniqueID; UFE->IsNamedPipe = Data.IsNamedPipe; UFE->InPCH = Data.InPCH; + fillRealPathName(UFE, Data.Name); } if (!UFE) { @@ -438,6 +431,17 @@ bool FileManager::makeAbsolutePath(SmallVectorImpl<char> &Path) const { return Changed; } +void FileManager::fillRealPathName(FileEntry *UFE, llvm::StringRef FileName) { + llvm::SmallString<128> AbsPath(FileName); + // This is not the same as `VFS::getRealPath()`, which resolves symlinks + // but can be very expensive on real file systems. + // FIXME: the semantic of RealPathName is unclear, and the name might be + // misleading. We need to clean up the interface here. + makeAbsolutePath(AbsPath); + llvm::sys::path::remove_dots(AbsPath, /*remove_dot_dot=*/true); + UFE->RealPathName = AbsPath.str(); +} + llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> FileManager::getBufferForFile(const FileEntry *Entry, bool isVolatile, bool ShouldCloseOpenFile) { |