kadircet created this revision.
kadircet added a reviewer: ilya-biryukov.
Herald added subscribers: cfe-commits, arphaman, jkorous, MaskRay.
Herald added a project: clang.
After rL360344 <https://reviews.llvm.org/rL360344>, BackgroundIndex expects 
symbols with zero refcounts.
Therefore existing index files are no longer valid.

Assertion regarding finding target of a reference was wrong, since
background-index might still be going on or we might've loaded only some part of
the shards and might be missing the declaring shards for the symbol.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D61734

Files:
  clang-tools-extra/clangd/index/FileIndex.cpp
  clang-tools-extra/clangd/index/Serialization.cpp


Index: clang-tools-extra/clangd/index/Serialization.cpp
===================================================================
--- clang-tools-extra/clangd/index/Serialization.cpp
+++ clang-tools-extra/clangd/index/Serialization.cpp
@@ -370,7 +370,7 @@
 // The current versioning scheme is simple - non-current versions are rejected.
 // If you make a breaking change, bump this version number to invalidate stored
 // data. Later we may want to support some backward compatibility.
-constexpr static uint32_t Version = 9;
+constexpr static uint32_t Version = 10;
 
 llvm::Expected<IndexFileIn> readRIFF(llvm::StringRef Data) {
   auto RIFF = riff::readFile(Data);
Index: clang-tools-extra/clangd/index/FileIndex.cpp
===================================================================
--- clang-tools-extra/clangd/index/FileIndex.cpp
+++ clang-tools-extra/clangd/index/FileIndex.cpp
@@ -138,7 +138,9 @@
     for (const RefSlab *Refs : MainFileRefs)
       for (const auto &Sym : *Refs) {
         auto It = Merged.find(Sym.first);
-        assert(It != Merged.end() && "Reference to unknown symbol");
+        // This might happen while background-index is still running.
+        if (It == Merged.end())
+          continue;
         It->getSecond().References += Sym.second.size();
       }
     SymsStorage.reserve(Merged.size());


Index: clang-tools-extra/clangd/index/Serialization.cpp
===================================================================
--- clang-tools-extra/clangd/index/Serialization.cpp
+++ clang-tools-extra/clangd/index/Serialization.cpp
@@ -370,7 +370,7 @@
 // The current versioning scheme is simple - non-current versions are rejected.
 // If you make a breaking change, bump this version number to invalidate stored
 // data. Later we may want to support some backward compatibility.
-constexpr static uint32_t Version = 9;
+constexpr static uint32_t Version = 10;
 
 llvm::Expected<IndexFileIn> readRIFF(llvm::StringRef Data) {
   auto RIFF = riff::readFile(Data);
Index: clang-tools-extra/clangd/index/FileIndex.cpp
===================================================================
--- clang-tools-extra/clangd/index/FileIndex.cpp
+++ clang-tools-extra/clangd/index/FileIndex.cpp
@@ -138,7 +138,9 @@
     for (const RefSlab *Refs : MainFileRefs)
       for (const auto &Sym : *Refs) {
         auto It = Merged.find(Sym.first);
-        assert(It != Merged.end() && "Reference to unknown symbol");
+        // This might happen while background-index is still running.
+        if (It == Merged.end())
+          continue;
         It->getSecond().References += Sym.second.size();
       }
     SymsStorage.reserve(Merged.size());
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to