diff options
| author | 2019-06-23 21:36:31 +0000 | |
|---|---|---|
| committer | 2019-06-23 21:36:31 +0000 | |
| commit | 23f101f37937a1bd4a29726cab2f76e0fb038b35 (patch) | |
| tree | f7da7d6b32c2e07114da399150bfa88d72187012 /gnu/llvm/tools/clang/lib/Basic/FileManager.cpp | |
| parent | sort previous; ok deraadt (diff) | |
| download | wireguard-openbsd-23f101f37937a1bd4a29726cab2f76e0fb038b35.tar.xz wireguard-openbsd-23f101f37937a1bd4a29726cab2f76e0fb038b35.zip | |
Import LLVM 8.0.0 release including clang, lld and lldb.
Diffstat (limited to 'gnu/llvm/tools/clang/lib/Basic/FileManager.cpp')
| -rw-r--r-- | gnu/llvm/tools/clang/lib/Basic/FileManager.cpp | 70 |
1 files changed, 26 insertions, 44 deletions
diff --git a/gnu/llvm/tools/clang/lib/Basic/FileManager.cpp b/gnu/llvm/tools/clang/lib/Basic/FileManager.cpp index d339b972ae8..01ec1d69cde 100644 --- a/gnu/llvm/tools/clang/lib/Basic/FileManager.cpp +++ b/gnu/llvm/tools/clang/lib/Basic/FileManager.cpp @@ -49,7 +49,7 @@ using namespace clang; //===----------------------------------------------------------------------===// FileManager::FileManager(const FileSystemOptions &FSO, - IntrusiveRefCntPtr<vfs::FileSystem> FS) + IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS) : FS(std::move(FS)), FileSystemOpts(FSO), SeenDirEntries(64), SeenFileEntries(64), NextFileUID(0) { NumDirLookups = NumFileLookups = 0; @@ -58,49 +58,17 @@ FileManager::FileManager(const FileSystemOptions &FSO, // If the caller doesn't provide a virtual file system, just grab the real // file system. if (!this->FS) - this->FS = vfs::getRealFileSystem(); + this->FS = llvm::vfs::getRealFileSystem(); } FileManager::~FileManager() = default; -void FileManager::addStatCache(std::unique_ptr<FileSystemStatCache> statCache, - bool AtBeginning) { +void FileManager::setStatCache(std::unique_ptr<FileSystemStatCache> statCache) { assert(statCache && "No stat cache provided?"); - if (AtBeginning || !StatCache.get()) { - statCache->setNextStatCache(std::move(StatCache)); - StatCache = std::move(statCache); - return; - } - - FileSystemStatCache *LastCache = StatCache.get(); - while (LastCache->getNextStatCache()) - LastCache = LastCache->getNextStatCache(); - - LastCache->setNextStatCache(std::move(statCache)); + StatCache = std::move(statCache); } -void FileManager::removeStatCache(FileSystemStatCache *statCache) { - if (!statCache) - return; - - if (StatCache.get() == statCache) { - // This is the first stat cache. - StatCache = StatCache->takeNextStatCache(); - return; - } - - // Find the stat cache in the list. - FileSystemStatCache *PrevCache = StatCache.get(); - while (PrevCache && PrevCache->getNextStatCache() != statCache) - PrevCache = PrevCache->getNextStatCache(); - - assert(PrevCache && "Stat cache not found for removal"); - PrevCache->setNextStatCache(statCache->takeNextStatCache()); -} - -void FileManager::clearStatCaches() { - StatCache.reset(); -} +void FileManager::clearStatCache() { StatCache.reset(); } /// Retrieve the directory that the given file name resides in. /// Filename can point to either a real file or a virtual file. @@ -252,7 +220,7 @@ const FileEntry *FileManager::getFile(StringRef Filename, bool openFile, // FIXME: This will reduce the # syscalls. // Nope, there isn't. Check to see if the file exists. - std::unique_ptr<vfs::File> F; + std::unique_ptr<llvm::vfs::File> F; FileData Data; if (getStatValue(InterndFileName, Data, true, openFile ? &F : nullptr)) { // There's no real file at the given path. @@ -315,9 +283,11 @@ const FileEntry *FileManager::getFile(StringRef Filename, bool openFile, UFE.InPCH = Data.InPCH; UFE.File = std::move(F); UFE.IsValid = true; - if (UFE.File) - if (auto RealPathName = UFE.File->getName()) - UFE.RealPathName = *RealPathName; + + if (UFE.File) { + if (auto PathName = UFE.File->getName()) + fillRealPathName(&UFE, *PathName); + } return &UFE; } @@ -373,6 +343,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) { @@ -415,6 +386,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) { @@ -465,7 +447,7 @@ FileManager::getBufferForFile(StringRef Filename, bool isVolatile) { /// false if it's an existent real file. If FileDescriptor is NULL, /// do directory look-up instead of file look-up. bool FileManager::getStatValue(StringRef Path, FileData &Data, bool isFile, - std::unique_ptr<vfs::File> *F) { + std::unique_ptr<llvm::vfs::File> *F) { // FIXME: FileSystemOpts shouldn't be passed in here, all paths should be // absolute! if (FileSystemOpts.WorkingDir.empty()) @@ -479,11 +461,11 @@ bool FileManager::getStatValue(StringRef Path, FileData &Data, bool isFile, } bool FileManager::getNoncachedStatValue(StringRef Path, - vfs::Status &Result) { + llvm::vfs::Status &Result) { SmallString<128> FilePath(Path); FixupRelativePath(FilePath); - llvm::ErrorOr<vfs::Status> S = FS->status(FilePath.c_str()); + llvm::ErrorOr<llvm::vfs::Status> S = FS->status(FilePath.c_str()); if (!S) return true; Result = *S; |
