Author: d0k Date: Wed Oct 7 03:32:50 2015 New Revision: 249525 URL: http://llvm.org/viewvc/llvm-project?rev=249525&view=rev Log: [VFS] Also drop '.' when adding files to an in-memory FS.
Otherwise we won't be able to find them later. Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/VirtualFileSystem.cpp?rev=249525&r1=249524&r2=249525&view=diff ============================================================================== --- cfe/trunk/lib/Basic/VirtualFileSystem.cpp (original) +++ cfe/trunk/lib/Basic/VirtualFileSystem.cpp Wed Oct 7 03:32:50 2015 @@ -495,6 +495,13 @@ void InMemoryFileSystem::addFile(const T auto I = llvm::sys::path::begin(Path), E = llvm::sys::path::end(Path); while (true) { StringRef Name = *I; + // Skip over ".". + // FIXME: Also handle "..". + if (Name == ".") { + ++I; + continue; + } + detail::InMemoryNode *Node = Dir->getChild(Name); ++I; if (!Node) { Modified: cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp?rev=249525&r1=249524&r2=249525&view=diff ============================================================================== --- cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp (original) +++ cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp Wed Oct 7 03:32:50 2015 @@ -568,6 +568,7 @@ TEST_F(InMemoryFileSystemTest, OverlayFi TEST_F(InMemoryFileSystemTest, OpenFileForRead) { FS.addFile("/a", 0, MemoryBuffer::getMemBuffer("a")); + FS.addFile("././c", 0, MemoryBuffer::getMemBuffer("c")); auto File = FS.openFileForRead("/a"); ASSERT_EQ("a", (*(*File)->getBuffer("ignored"))->getBuffer()); File = FS.openFileForRead("/a"); // Open again. @@ -578,6 +579,8 @@ TEST_F(InMemoryFileSystemTest, OpenFileF ASSERT_EQ(File.getError(), errc::invalid_argument) << FS.toString(); File = FS.openFileForRead("/b"); ASSERT_EQ(File.getError(), errc::no_such_file_or_directory) << FS.toString(); + File = FS.openFileForRead("./c"); + ASSERT_EQ("c", (*(*File)->getBuffer("ignored"))->getBuffer()); } TEST_F(InMemoryFileSystemTest, DirectoryIteration) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits