[clang-tools-extra] r355681 - [clangd] Remove ./ and ../ in the file paths

Kadir Cetinkaya via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 8 01:57:33 PST 2019


Author: kadircet
Date: Fri Mar  8 01:57:33 2019
New Revision: 355681

URL: http://llvm.org/viewvc/llvm-project?rev=355681&view=rev
Log:
[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

Modified:
    clang-tools-extra/trunk/clangd/index/Background.cpp
    clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp

Modified: clang-tools-extra/trunk/clangd/index/Background.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.cpp?rev=355681&r1=355680&r2=355681&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/index/Background.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Background.cpp Fri Mar  8 01:57:33 2019
@@ -121,6 +121,7 @@ llvm::SmallString<128> getAbsolutePath(c
   } else {
     AbsolutePath = Cmd.Directory;
     llvm::sys::path::append(AbsolutePath, Cmd.Filename);
+    llvm::sys::path::remove_dots(AbsolutePath, true);
   }
   return AbsolutePath;
 }

Modified: clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp?rev=355681&r1=355680&r2=355681&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp Fri Mar  8 01:57:33 2019
@@ -44,12 +44,14 @@ public:
   llvm::Error storeShard(llvm::StringRef ShardIdentifier,
                          IndexFileOut Shard) const override {
     std::lock_guard<std::mutex> Lock(StorageMu);
+    AccessedPaths.insert(ShardIdentifier);
     Storage[ShardIdentifier] = llvm::to_string(Shard);
     return llvm::Error::success();
   }
   std::unique_ptr<IndexFileIn>
   loadShard(llvm::StringRef ShardIdentifier) const override {
     std::lock_guard<std::mutex> Lock(StorageMu);
+    AccessedPaths.insert(ShardIdentifier);
     if (Storage.find(ShardIdentifier) == Storage.end()) {
       return nullptr;
     }
@@ -62,6 +64,8 @@ public:
     CacheHits++;
     return llvm::make_unique<IndexFileIn>(std::move(*IndexFile));
   }
+
+  mutable llvm::StringSet<> AccessedPaths;
 };
 
 class BackgroundIndexTest : public ::testing::Test {
@@ -428,5 +432,34 @@ TEST_F(BackgroundIndexTest, ShardStorage
               Contains(AllOf(Named("new_func"), Declared(), Not(Defined()))));
 }
 
+TEST_F(BackgroundIndexTest, NoDotsInAbsPath) {
+  MockFSProvider FS;
+  llvm::StringMap<std::string> 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




More information about the cfe-commits mailing list