From b4c9f62cc5a8be4903a3eae7b7bac6ea25dfedd3 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Wed, 7 Oct 2015 08:32:50 +0000 Subject: [PATCH] [VFS] Also drop '.' when adding files to an in-memory FS. Otherwise we won't be able to find them later. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@249525 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Basic/VirtualFileSystem.cpp | 7 +++++++ unittests/Basic/VirtualFileSystemTest.cpp | 3 +++ 2 files changed, 10 insertions(+) diff --git a/lib/Basic/VirtualFileSystem.cpp b/lib/Basic/VirtualFileSystem.cpp index b3805b2ff9..b5bf33fee8 100644 --- a/lib/Basic/VirtualFileSystem.cpp +++ b/lib/Basic/VirtualFileSystem.cpp @@ -495,6 +495,13 @@ void InMemoryFileSystem::addFile(const Twine &P, time_t ModificationTime, 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) { diff --git a/unittests/Basic/VirtualFileSystemTest.cpp b/unittests/Basic/VirtualFileSystemTest.cpp index cca99a9473..6ed811f22f 100644 --- a/unittests/Basic/VirtualFileSystemTest.cpp +++ b/unittests/Basic/VirtualFileSystemTest.cpp @@ -568,6 +568,7 @@ TEST_F(InMemoryFileSystemTest, OverlayFileNoOwn) { 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, OpenFileForRead) { 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) { -- 2.40.0