diff options
author | Ben Langmuir <blangmuir@apple.com> | 2015-12-10 23:41:39 +0000 |
---|---|---|
committer | Ben Langmuir <blangmuir@apple.com> | 2015-12-10 23:41:39 +0000 |
commit | f13302e63ff0c858ecac7cc30ea2201c523a43ba (patch) | |
tree | 368c35038f8ff52ee23b47dbcfc79dcae74cc226 /clang/unittests/Basic/VirtualFileSystemTest.cpp | |
parent | 83760378617dfa9670ce9439e9bfdcf2a5c81b90 (diff) | |
download | bcm5719-llvm-f13302e63ff0c858ecac7cc30ea2201c523a43ba.tar.gz bcm5719-llvm-f13302e63ff0c858ecac7cc30ea2201c523a43ba.zip |
[VFS] Fix status() of opened redirected file
Make RedirectedFileSystem::openFilForRead(path)->status() the same as
RedirectedFileSystem::status(path). Previously we would just get the
status of the underlying real file, which would not have the IsVFSMapped
bit set.
This fixes rebuilding a module that has an include that is relative to
the includer where we will lookup the real path of that file before we
lookup the VFS location.
rdar://problem/23640339
llvm-svn: 255312
Diffstat (limited to 'clang/unittests/Basic/VirtualFileSystemTest.cpp')
-rw-r--r-- | clang/unittests/Basic/VirtualFileSystemTest.cpp | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/clang/unittests/Basic/VirtualFileSystemTest.cpp b/clang/unittests/Basic/VirtualFileSystemTest.cpp index 96b8295acdb..ac07035d3e1 100644 --- a/clang/unittests/Basic/VirtualFileSystemTest.cpp +++ b/clang/unittests/Basic/VirtualFileSystemTest.cpp @@ -20,6 +20,18 @@ using namespace llvm; using llvm::sys::fs::UniqueID; namespace { +struct DummyFile : public vfs::File { + vfs::Status S; + explicit DummyFile(vfs::Status S) : S(S) {} + llvm::ErrorOr<vfs::Status> status() override { return S; } + llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> + getBuffer(const Twine &Name, int64_t FileSize, bool RequiresNullTerminator, + bool IsVolatile) override { + llvm_unreachable("unimplemented"); + } + virtual std::error_code close() override { return std::error_code(); } +}; + class DummyFileSystem : public vfs::FileSystem { int FSID; // used to produce UniqueIDs int FileID; // used to produce UniqueIDs @@ -42,7 +54,10 @@ public: } ErrorOr<std::unique_ptr<vfs::File>> openFileForRead(const Twine &Path) override { - llvm_unreachable("unimplemented"); + auto S = status(Path); + if (S) + return std::unique_ptr<vfs::File>(new DummyFile{*S}); + return S.getError(); } llvm::ErrorOr<std::string> getCurrentWorkingDirectory() const override { return std::string(); @@ -718,10 +733,20 @@ TEST_F(VFSFromYAMLTest, MappedFiles) { ErrorOr<vfs::Status> S = O->status("//root/file1"); ASSERT_FALSE(S.getError()); EXPECT_EQ("//root/foo/bar/a", S->getName()); + EXPECT_TRUE(S->IsVFSMapped); ErrorOr<vfs::Status> SLower = O->status("//root/foo/bar/a"); EXPECT_EQ("//root/foo/bar/a", SLower->getName()); EXPECT_TRUE(S->equivalent(*SLower)); + EXPECT_FALSE(SLower->IsVFSMapped); + + // file after opening + auto OpenedF = O->openFileForRead("//root/file1"); + ASSERT_FALSE(OpenedF.getError()); + auto OpenedS = (*OpenedF)->status(); + ASSERT_FALSE(OpenedS.getError()); + EXPECT_EQ("//root/foo/bar/a", OpenedS->getName()); + EXPECT_TRUE(OpenedS->IsVFSMapped); // directory S = O->status("//root/"); |