[clang-tools-extra] 4503cf5 - [clangd] Drop dangling relations while sharding

Kadir Cetinkaya via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 17 05:02:48 PDT 2020


Author: Kadir Cetinkaya
Date: 2020-04-17T13:57:32+02:00
New Revision: 4503cf5f231368d6e11af724b78f1371463d86a6

URL: https://github.com/llvm/llvm-project/commit/4503cf5f231368d6e11af724b78f1371463d86a6
DIFF: https://github.com/llvm/llvm-project/commit/4503cf5f231368d6e11af724b78f1371463d86a6.diff

LOG: [clangd] Drop dangling relations while sharding

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D78359

Added: 
    

Modified: 
    clang-tools-extra/clangd/index/FileIndex.cpp
    clang-tools-extra/clangd/unittests/FileIndexTests.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/index/FileIndex.cpp b/clang-tools-extra/clangd/index/FileIndex.cpp
index 91914be00148..590bf46ec01c 100644
--- a/clang-tools-extra/clangd/index/FileIndex.cpp
+++ b/clang-tools-extra/clangd/index/FileIndex.cpp
@@ -174,9 +174,9 @@ FileShardedIndex::FileShardedIndex(IndexFileIn Input, PathRef HintPath)
   // not have been indexed, see SymbolCollector::processRelations for details.
   if (Index.Relations) {
     for (const auto &R : *Index.Relations) {
-      auto *File = SymbolIDToFile.lookup(R.Subject);
-      assert(File && "unknown subject in relation");
-      File->Relations.insert(&R);
+      // FIXME: RelationSlab shouldn't contain dangling relations.
+      if (auto *File = SymbolIDToFile.lookup(R.Subject))
+        File->Relations.insert(&R);
     }
   }
   // Store only the direct includes of a file in a shard.

diff  --git a/clang-tools-extra/clangd/unittests/FileIndexTests.cpp b/clang-tools-extra/clangd/unittests/FileIndexTests.cpp
index dc39ad2acf25..328892f750de 100644
--- a/clang-tools-extra/clangd/unittests/FileIndexTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FileIndexTests.cpp
@@ -540,6 +540,8 @@ TEST(FileShardedIndexTest, Sharding) {
     B.insert(Relation{Sym1.ID, RelationKind::BaseOf, Sym2.ID});
     // Should be stored in b.h
     B.insert(Relation{Sym2.ID, RelationKind::BaseOf, Sym1.ID});
+    // Dangling relation should be dropped.
+    B.insert(Relation{symbol("3").ID, RelationKind::BaseOf, Sym1.ID});
     IF.Relations = std::move(B).build();
   }
 


        


More information about the cfe-commits mailing list