From: Kadir Cetinkaya Date: Fri, 8 Mar 2019 09:57:33 +0000 (+0000) Subject: [clangd] Remove ./ and ../ in the file paths X-Git-Tag: llvmorg-10-init~10439 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=890dfddef0f94c71e76f2451b1fa443ae1f0e339;p=platform%2Fupstream%2Fllvm.git [clangd] Remove ./ and ../ in the file paths Reviewers: hokein Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D59084 llvm-svn: 355681 --- diff --git a/clang-tools-extra/clangd/index/Background.cpp b/clang-tools-extra/clangd/index/Background.cpp index 40ff8d7..79f2125 100644 --- a/clang-tools-extra/clangd/index/Background.cpp +++ b/clang-tools-extra/clangd/index/Background.cpp @@ -121,6 +121,7 @@ llvm::SmallString<128> getAbsolutePath(const tooling::CompileCommand &Cmd) { } else { AbsolutePath = Cmd.Directory; llvm::sys::path::append(AbsolutePath, Cmd.Filename); + llvm::sys::path::remove_dots(AbsolutePath, true); } return AbsolutePath; } diff --git a/clang-tools-extra/unittests/clangd/BackgroundIndexTests.cpp b/clang-tools-extra/unittests/clangd/BackgroundIndexTests.cpp index 09a117d..5f20cb0 100644 --- a/clang-tools-extra/unittests/clangd/BackgroundIndexTests.cpp +++ b/clang-tools-extra/unittests/clangd/BackgroundIndexTests.cpp @@ -44,12 +44,14 @@ public: llvm::Error storeShard(llvm::StringRef ShardIdentifier, IndexFileOut Shard) const override { std::lock_guard Lock(StorageMu); + AccessedPaths.insert(ShardIdentifier); Storage[ShardIdentifier] = llvm::to_string(Shard); return llvm::Error::success(); } std::unique_ptr loadShard(llvm::StringRef ShardIdentifier) const override { std::lock_guard Lock(StorageMu); + AccessedPaths.insert(ShardIdentifier); if (Storage.find(ShardIdentifier) == Storage.end()) { return nullptr; } @@ -62,6 +64,8 @@ public: CacheHits++; return llvm::make_unique(std::move(*IndexFile)); } + + mutable llvm::StringSet<> AccessedPaths; }; class BackgroundIndexTest : public ::testing::Test { @@ -428,5 +432,34 @@ TEST_F(BackgroundIndexTest, ShardStorageEmptyFile) { Contains(AllOf(Named("new_func"), Declared(), Not(Defined())))); } +TEST_F(BackgroundIndexTest, NoDotsInAbsPath) { + MockFSProvider FS; + llvm::StringMap Storage; + size_t CacheHits = 0; + MemoryShardStorage MSS(Storage, CacheHits); + OverlayCDB CDB(/*Base=*/nullptr); + BackgroundIndex Idx(Context::empty(), FS, CDB, + [&](llvm::StringRef) { return &MSS; }); + + tooling::CompileCommand Cmd; + FS.Files[testPath("root/A.cc")] = ""; + Cmd.Filename = "../A.cc"; + Cmd.Directory = testPath("root/build"); + Cmd.CommandLine = {"clang++", "../A.cc"}; + CDB.setCompileCommand(testPath("root/build/../A.cc"), Cmd); + + FS.Files[testPath("root/B.cc")] = ""; + Cmd.Filename = "./B.cc"; + Cmd.Directory = testPath("root"); + Cmd.CommandLine = {"clang++", "./B.cc"}; + CDB.setCompileCommand(testPath("root/./B.cc"), Cmd); + + ASSERT_TRUE(Idx.blockUntilIdleForTest()); + for (llvm::StringRef AbsPath : MSS.AccessedPaths.keys()) { + EXPECT_FALSE(AbsPath.contains("./")) << AbsPath; + EXPECT_FALSE(AbsPath.contains("../")) << AbsPath; + } +} + } // namespace clangd } // namespace clang