Index: clangd/index/Background.cpp =================================================================== --- clangd/index/Background.cpp +++ clangd/index/Background.cpp @@ -510,8 +510,12 @@ if (!AbsolutePath) continue; // Add file as dependency if haven't seen before. - if (InQueue.try_emplace(*AbsolutePath).second) + if (InQueue.try_emplace(*AbsolutePath).second) { Dependencies.emplace_back(*AbsolutePath, true); + // The insertion above might invalidate the reference, so update it as + // well. + CurDependencyPath = Dependencies[CurrentDependency].Path; + } // The node contains symbol information only for current file, the rest is // just edges. if (*AbsolutePath != CurDependencyPath)