[PATCH] D140617: [clangd] Fix a clangd crash when indexing the standard library.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 23 03:04:24 PST 2022


hokein created this revision.
hokein added a reviewer: sammccall.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
hokein requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Setup a current working directory (the build directoy) when creating a compile
instance. (otherwise clangd may die immediately when the VFS doesn't get input
files e.g. -fsanitize-ignorelist="../ignores.txt").


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140617

Files:
  clang-tools-extra/clangd/index/StdLib.cpp


Index: clang-tools-extra/clangd/index/StdLib.cpp
===================================================================
--- clang-tools-extra/clangd/index/StdLib.cpp
+++ clang-tools-extra/clangd/index/StdLib.cpp
@@ -224,10 +224,11 @@
   IgnoreDiagnostics IgnoreDiags;
   // CompilerInvocation is taken from elsewhere, and may map a dirty buffer.
   CI->getPreprocessorOpts().clearRemappedFiles();
+  std::string CWD = CI->getFileSystemOpts().WorkingDir;
   auto Clang = prepareCompilerInstance(
       std::move(CI), /*Preamble=*/nullptr,
       llvm::MemoryBuffer::getMemBuffer(HeaderSources, Input.getFile()),
-      TFS.view(/*CWD=*/std::nullopt), IgnoreDiags);
+      TFS.view(CWD), IgnoreDiags);
   if (!Clang) {
     elog("Standard Library Index: Couldn't build compiler instance");
     return Symbols;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140617.485074.patch
Type: text/x-patch
Size: 807 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221223/914786bd/attachment.bin>


More information about the cfe-commits mailing list