From 7a8f65592753b954def00a7ad632c6c4307cd1e2 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Wed, 9 Nov 2016 10:52:22 +0000 Subject: [PATCH] [VFS] Replace TimeValue usage with std::chrono Summary: NFCI Reviewers: benlangmuir, zturner Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D25948 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@286356 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/VirtualFileSystem.h | 8 +++---- lib/Basic/FileSystemStatCache.cpp | 2 +- lib/Basic/VirtualFileSystem.cpp | 27 ++++++++++++----------- lib/Frontend/ASTUnit.cpp | 7 +++--- lib/Serialization/ModuleManager.cpp | 2 +- unittests/Basic/VirtualFileSystemTest.cpp | 15 ++++++++----- 6 files changed, 33 insertions(+), 28 deletions(-) diff --git a/include/clang/Basic/VirtualFileSystem.h b/include/clang/Basic/VirtualFileSystem.h index 84db321c2e..770288fdcc 100644 --- a/include/clang/Basic/VirtualFileSystem.h +++ b/include/clang/Basic/VirtualFileSystem.h @@ -16,10 +16,10 @@ #include "clang/Basic/LLVM.h" #include "llvm/ADT/IntrusiveRefCntPtr.h" #include "llvm/ADT/Optional.h" +#include "llvm/Support/Chrono.h" #include "llvm/Support/ErrorOr.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/SourceMgr.h" -#include "llvm/Support/TimeValue.h" #include "llvm/Support/raw_ostream.h" #include @@ -34,7 +34,7 @@ namespace vfs { class Status { std::string Name; llvm::sys::fs::UniqueID UID; - llvm::sys::TimeValue MTime; + llvm::sys::TimePoint<> MTime; uint32_t User; uint32_t Group; uint64_t Size; @@ -48,7 +48,7 @@ public: Status() : Type(llvm::sys::fs::file_type::status_error) {} Status(const llvm::sys::fs::file_status &Status); Status(StringRef Name, llvm::sys::fs::UniqueID UID, - llvm::sys::TimeValue MTime, uint32_t User, uint32_t Group, + llvm::sys::TimePoint<> MTime, uint32_t User, uint32_t Group, uint64_t Size, llvm::sys::fs::file_type Type, llvm::sys::fs::perms Perms); @@ -64,7 +64,7 @@ public: /// @{ llvm::sys::fs::file_type getType() const { return Type; } llvm::sys::fs::perms getPermissions() const { return Perms; } - llvm::sys::TimeValue getLastModificationTime() const { return MTime; } + llvm::sys::TimePoint<> getLastModificationTime() const { return MTime; } llvm::sys::fs::UniqueID getUniqueID() const { return UID; } uint32_t getUser() const { return User; } uint32_t getGroup() const { return Group; } diff --git a/lib/Basic/FileSystemStatCache.cpp b/lib/Basic/FileSystemStatCache.cpp index 33b8676e74..799df1d3c3 100644 --- a/lib/Basic/FileSystemStatCache.cpp +++ b/lib/Basic/FileSystemStatCache.cpp @@ -23,7 +23,7 @@ static void copyStatusToFileData(const vfs::Status &Status, FileData &Data) { Data.Name = Status.getName(); Data.Size = Status.getSize(); - Data.ModTime = Status.getLastModificationTime().toEpochTime(); + Data.ModTime = llvm::sys::toTimeT(Status.getLastModificationTime()); Data.UniqueID = Status.getUniqueID(); Data.IsDirectory = Status.isDirectory(); Data.IsNamedPipe = Status.getType() == llvm::sys::fs::file_type::fifo_file; diff --git a/lib/Basic/VirtualFileSystem.cpp b/lib/Basic/VirtualFileSystem.cpp index a56c9115fb..88d08b4b66 100644 --- a/lib/Basic/VirtualFileSystem.cpp +++ b/lib/Basic/VirtualFileSystem.cpp @@ -47,7 +47,7 @@ Status::Status(const file_status &Status) User(Status.getUser()), Group(Status.getGroup()), Size(Status.getSize()), Type(Status.type()), Perms(Status.permissions()), IsVFSMapped(false) {} -Status::Status(StringRef Name, UniqueID UID, sys::TimeValue MTime, +Status::Status(StringRef Name, UniqueID UID, sys::TimePoint<> MTime, uint32_t User, uint32_t Group, uint64_t Size, file_type Type, perms Perms) : Name(Name), UID(UID), MTime(MTime), User(User), Group(Group), Size(Size), @@ -494,8 +494,8 @@ public: InMemoryFileSystem::InMemoryFileSystem(bool UseNormalizedPaths) : Root(new detail::InMemoryDirectory( - Status("", getNextVirtualUniqueID(), llvm::sys::TimeValue::MinTime(), - 0, 0, 0, llvm::sys::fs::file_type::directory_file, + Status("", getNextVirtualUniqueID(), llvm::sys::TimePoint<>(), 0, 0, + 0, llvm::sys::fs::file_type::directory_file, llvm::sys::fs::perms::all_all))), UseNormalizedPaths(UseNormalizedPaths) {} @@ -532,7 +532,7 @@ bool InMemoryFileSystem::addFile(const Twine &P, time_t ModificationTime, // End of the path, create a new file. // FIXME: expose the status details in the interface. Status Stat(P.str(), getNextVirtualUniqueID(), - llvm::sys::TimeValue(ModificationTime, 0), 0, 0, + llvm::sys::toTimePoint(ModificationTime), 0, 0, Buffer->getBufferSize(), llvm::sys::fs::file_type::regular_file, llvm::sys::fs::all_all); @@ -545,9 +545,9 @@ bool InMemoryFileSystem::addFile(const Twine &P, time_t ModificationTime, // FIXME: expose the status details in the interface. Status Stat( StringRef(Path.str().begin(), Name.end() - Path.str().begin()), - getNextVirtualUniqueID(), llvm::sys::TimeValue(ModificationTime, 0), - 0, 0, Buffer->getBufferSize(), - llvm::sys::fs::file_type::directory_file, llvm::sys::fs::all_all); + getNextVirtualUniqueID(), llvm::sys::toTimePoint(ModificationTime), 0, + 0, Buffer->getBufferSize(), llvm::sys::fs::file_type::directory_file, + llvm::sys::fs::all_all); Dir = cast(Dir->addChild( Name, llvm::make_unique(std::move(Stat)))); continue; @@ -1073,8 +1073,9 @@ class RedirectingFileSystemParser { // ... or create a new one std::unique_ptr E = llvm::make_unique( - Name, Status("", getNextVirtualUniqueID(), sys::TimeValue::now(), 0, 0, - 0, file_type::directory_file, sys::fs::all_all)); + Name, + Status("", getNextVirtualUniqueID(), std::chrono::system_clock::now(), + 0, 0, 0, file_type::directory_file, sys::fs::all_all)); if (!ParentEntry) { // Add a new root to the overlay FS->Roots.push_back(std::move(E)); @@ -1275,8 +1276,8 @@ class RedirectingFileSystemParser { case EK_Directory: Result = llvm::make_unique( LastComponent, std::move(EntryArrayContents), - Status("", getNextVirtualUniqueID(), sys::TimeValue::now(), 0, 0, 0, - file_type::directory_file, sys::fs::all_all)); + Status("", getNextVirtualUniqueID(), std::chrono::system_clock::now(), + 0, 0, 0, file_type::directory_file, sys::fs::all_all)); break; } @@ -1292,8 +1293,8 @@ class RedirectingFileSystemParser { Entries.push_back(std::move(Result)); Result = llvm::make_unique( *I, std::move(Entries), - Status("", getNextVirtualUniqueID(), sys::TimeValue::now(), 0, 0, 0, - file_type::directory_file, sys::fs::all_all)); + Status("", getNextVirtualUniqueID(), std::chrono::system_clock::now(), + 0, 0, 0, file_type::directory_file, sys::fs::all_all)); } return Result; } diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp index 3acd64587b..32ce966f79 100644 --- a/lib/Frontend/ASTUnit.cpp +++ b/lib/Frontend/ASTUnit.cpp @@ -1392,7 +1392,8 @@ ASTUnit::getMainBufferWithPrecompiledPreamble( } OverriddenFiles[Status.getUniqueID()] = PreambleFileHash::createForFile( - Status.getSize(), Status.getLastModificationTime().toEpochTime()); + Status.getSize(), + llvm::sys::toTimeT(Status.getLastModificationTime())); } for (const auto &RB : PreprocessorOpts.RemappedFileBuffers) { @@ -1433,8 +1434,8 @@ ASTUnit::getMainBufferWithPrecompiledPreamble( // The file was not remapped; check whether it has changed on disk. if (Status.getSize() != uint64_t(F->second.Size) || - Status.getLastModificationTime().toEpochTime() != - uint64_t(F->second.ModTime)) + llvm::sys::toTimeT(Status.getLastModificationTime()) != + F->second.ModTime) AnyFileChanged = true; } diff --git a/lib/Serialization/ModuleManager.cpp b/lib/Serialization/ModuleManager.cpp index e50dcaab2f..722b547e80 100644 --- a/lib/Serialization/ModuleManager.cpp +++ b/lib/Serialization/ModuleManager.cpp @@ -102,7 +102,7 @@ ModuleManager::addModule(StringRef FileName, ModuleKind Type, // A cached stat value would be fine as well. if (!FileMgr.getNoncachedStatValue(TimestampFilename, Status)) ModuleEntry->InputFilesValidationTimestamp = - Status.getLastModificationTime().toEpochTime(); + llvm::sys::toTimeT(Status.getLastModificationTime()); } // Load the contents of the module diff --git a/unittests/Basic/VirtualFileSystemTest.cpp b/unittests/Basic/VirtualFileSystemTest.cpp index 547cba159b..580343d93e 100644 --- a/unittests/Basic/VirtualFileSystemTest.cpp +++ b/unittests/Basic/VirtualFileSystemTest.cpp @@ -115,20 +115,23 @@ public: } void addRegularFile(StringRef Path, sys::fs::perms Perms = sys::fs::all_all) { - vfs::Status S(Path, UniqueID(FSID, FileID++), sys::TimeValue::now(), 0, 0, - 1024, sys::fs::file_type::regular_file, Perms); + vfs::Status S(Path, UniqueID(FSID, FileID++), + std::chrono::system_clock::now(), 0, 0, 1024, + sys::fs::file_type::regular_file, Perms); addEntry(Path, S); } void addDirectory(StringRef Path, sys::fs::perms Perms = sys::fs::all_all) { - vfs::Status S(Path, UniqueID(FSID, FileID++), sys::TimeValue::now(), 0, 0, - 0, sys::fs::file_type::directory_file, Perms); + vfs::Status S(Path, UniqueID(FSID, FileID++), + std::chrono::system_clock::now(), 0, 0, 0, + sys::fs::file_type::directory_file, Perms); addEntry(Path, S); } void addSymlink(StringRef Path) { - vfs::Status S(Path, UniqueID(FSID, FileID++), sys::TimeValue::now(), 0, 0, - 0, sys::fs::file_type::symlink_file, sys::fs::all_all); + vfs::Status S(Path, UniqueID(FSID, FileID++), + std::chrono::system_clock::now(), 0, 0, 0, + sys::fs::file_type::symlink_file, sys::fs::all_all); addEntry(Path, S); } }; -- 2.40.0