simark created this revision. Herald added subscribers: cfe-commits, ioeric, ilya-biryukov.
InMemoryFileSystem::status behaves differently than RealFileSystem::status. The Name contained in the Status returned by RealFileSystem::status will be the path as requested by the caller, whereas InMemoryFileSystem::status returns the normalized path. For example, when requested the status for "../src/first.h", RealFileSystem returns a Status with "../src/first.h" as the Name. InMemoryFileSystem returns "/absolute/path/to/src/first.h". The reason for this change is that I want to make a unit test in the clangd testsuite (where we use an InMemoryFileSystem) to reproduce a bug I get with the clangd program (where a RealFileSystem is used). This difference in behavior "hides" the bug in the unit test version. Repository: rC Clang https://reviews.llvm.org/D48903 Files: lib/Basic/VirtualFileSystem.cpp Index: lib/Basic/VirtualFileSystem.cpp =================================================================== --- lib/Basic/VirtualFileSystem.cpp +++ lib/Basic/VirtualFileSystem.cpp @@ -508,10 +508,18 @@ class InMemoryFileAdaptor : public File { InMemoryFile &Node; + // The name to use when returning a Status for this file. + std::string RequestedName; + public: - explicit InMemoryFileAdaptor(InMemoryFile &Node) : Node(Node) {} + explicit InMemoryFileAdaptor(InMemoryFile &Node, std::string RequestedName) + : Node(Node), RequestedName (std::move (RequestedName)) + {} - llvm::ErrorOr<Status> status() override { return Node.getStatus(); } + llvm::ErrorOr<Status> status() override { + Status St = Node.getStatus(); + return Status::copyWithNewName(St, RequestedName); + } llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> getBuffer(const Twine &Name, int64_t FileSize, bool RequiresNullTerminator, @@ -711,7 +719,10 @@ llvm::ErrorOr<Status> InMemoryFileSystem::status(const Twine &Path) { auto Node = lookupInMemoryNode(*this, Root.get(), Path); if (Node) - return (*Node)->getStatus(); + { + Status St = (*Node)->getStatus(); + return Status::copyWithNewName(St, Path.str()); + } return Node.getError(); } @@ -724,7 +735,7 @@ // When we have a file provide a heap-allocated wrapper for the memory buffer // to match the ownership semantics for File. if (auto *F = dyn_cast<detail::InMemoryFile>(*Node)) - return std::unique_ptr<File>(new detail::InMemoryFileAdaptor(*F)); + return std::unique_ptr<File>(new detail::InMemoryFileAdaptor(*F, Path.str())); // FIXME: errc::not_a_file? return make_error_code(llvm::errc::invalid_argument);
Index: lib/Basic/VirtualFileSystem.cpp =================================================================== --- lib/Basic/VirtualFileSystem.cpp +++ lib/Basic/VirtualFileSystem.cpp @@ -508,10 +508,18 @@ class InMemoryFileAdaptor : public File { InMemoryFile &Node; + // The name to use when returning a Status for this file. + std::string RequestedName; + public: - explicit InMemoryFileAdaptor(InMemoryFile &Node) : Node(Node) {} + explicit InMemoryFileAdaptor(InMemoryFile &Node, std::string RequestedName) + : Node(Node), RequestedName (std::move (RequestedName)) + {} - llvm::ErrorOr<Status> status() override { return Node.getStatus(); } + llvm::ErrorOr<Status> status() override { + Status St = Node.getStatus(); + return Status::copyWithNewName(St, RequestedName); + } llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> getBuffer(const Twine &Name, int64_t FileSize, bool RequiresNullTerminator, @@ -711,7 +719,10 @@ llvm::ErrorOr<Status> InMemoryFileSystem::status(const Twine &Path) { auto Node = lookupInMemoryNode(*this, Root.get(), Path); if (Node) - return (*Node)->getStatus(); + { + Status St = (*Node)->getStatus(); + return Status::copyWithNewName(St, Path.str()); + } return Node.getError(); } @@ -724,7 +735,7 @@ // When we have a file provide a heap-allocated wrapper for the memory buffer // to match the ownership semantics for File. if (auto *F = dyn_cast<detail::InMemoryFile>(*Node)) - return std::unique_ptr<File>(new detail::InMemoryFileAdaptor(*F)); + return std::unique_ptr<File>(new detail::InMemoryFileAdaptor(*F, Path.str())); // FIXME: errc::not_a_file? return make_error_code(llvm::errc::invalid_argument);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits