diff --git a/clang-tools-extra/clangd/index/FileIndex.cpp b/clang-tools-extra/clangd/index/FileIndex.cpp --- a/clang-tools-extra/clangd/index/FileIndex.cpp +++ b/clang-tools-extra/clangd/index/FileIndex.cpp @@ -174,9 +174,9 @@ // 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 --- a/clang-tools-extra/clangd/unittests/FileIndexTests.cpp +++ b/clang-tools-extra/clangd/unittests/FileIndexTests.cpp @@ -540,6 +540,8 @@ 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(); }