[PATCH] D95206: [clangd][SwapIndex] ensure that the old index is alive while we are using it via the function returned by `SwapIndex::indexedFiles()` call

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 22 01:30:48 PST 2021


sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Thanks, I'd seen these crashes but not manage to track down yet!

LG with one fix



================
Comment at: clang-tools-extra/clangd/index/Index.cpp:81
 SwapIndex::indexedFiles() const {
-  return snapshot()->indexedFiles();
+  return [KeepAlive = snapshot(), IndexedFiles = snapshot()->indexedFiles()](
+             llvm::StringRef File) { return IndexedFiles(File); };
----------------
Calling snapshot() twice introduces a race - we may keep the wrong one alive.

Evaluate snapshot first into a variable, then call indexedFiles, then move both into the lambda?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95206/new/

https://reviews.llvm.org/D95206



More information about the cfe-commits mailing list