[PATCH] D55054: [clang] Fill RealPathName for virtual files.
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 29 07:21:57 PST 2018
kadircet created this revision.
kadircet added a reviewer: ilya-biryukov.
Herald added a subscriber: cfe-commits.
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.
Repository:
rC Clang
https://reviews.llvm.org/D55054
Files:
include/clang/Basic/FileManager.h
lib/Basic/FileManager.cpp
Index: lib/Basic/FileManager.cpp
===================================================================
--- lib/Basic/FileManager.cpp
+++ lib/Basic/FileManager.cpp
@@ -293,16 +293,8 @@
// 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 @@
UFE->UniqueID = Data.UniqueID;
UFE->IsNamedPipe = Data.IsNamedPipe;
UFE->InPCH = Data.InPCH;
+ fillRealPathName(UFE, Data.Name);
}
if (!UFE) {
@@ -438,6 +431,18 @@
return Changed;
}
+bool 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.
+ bool Changed = makeAbsolutePath(AbsPath);
+ llvm::sys::path::remove_dots(AbsPath, /*remove_dot_dot=*/true);
+ UFE->RealPathName = AbsPath.str();
+ return Changed;
+}
+
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
FileManager::getBufferForFile(const FileEntry *Entry, bool isVolatile,
bool ShouldCloseOpenFile) {
Index: include/clang/Basic/FileManager.h
===================================================================
--- include/clang/Basic/FileManager.h
+++ include/clang/Basic/FileManager.h
@@ -173,6 +173,10 @@
/// or a directory) as virtual directories.
void addAncestorsAsVirtualDirs(StringRef Path);
+ /// Fills the RealPathName entry in UFE by converting the given filename to an
+ /// absolute path, returns true if FileName was modified.
+ bool fillRealPathName(FileEntry *UFE, llvm::StringRef FileName);
+
public:
FileManager(const FileSystemOptions &FileSystemOpts,
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS = nullptr);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55054.175868.patch
Type: text/x-patch
Size: 2696 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181129/bc11b728/attachment.bin>
More information about the cfe-commits
mailing list