[PATCH] D104056: [clangd][nfc] Show more information in logs when compiler instance prepare fails

Aleksandr Platonov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 29 15:43:09 PDT 2021


ArcsinX updated this revision to Diff 355389.
ArcsinX added a comment.

Check ASTDiags.take() for empty instead of ASTDiags.getNumErrors() value check


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104056

Files:
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/Preamble.cpp


Index: clang-tools-extra/clangd/Preamble.cpp
===================================================================
--- clang-tools-extra/clangd/Preamble.cpp
+++ clang-tools-extra/clangd/Preamble.cpp
@@ -390,8 +390,8 @@
         SerializedDeclsCollector.takeMacros(), std::move(StatCache),
         SerializedDeclsCollector.takeCanonicalIncludes());
   } else {
-    elog("Could not build a preamble for file {0} version {1}", FileName,
-         Inputs.Version);
+    elog("Could not build a preamble for file {0} version {1}: {2}", FileName,
+         Inputs.Version, BuiltPreamble.getError().message());
     return nullptr;
   }
 }
Index: clang-tools-extra/clangd/ParsedAST.cpp
===================================================================
--- clang-tools-extra/clangd/ParsedAST.cpp
+++ clang-tools-extra/clangd/ParsedAST.cpp
@@ -289,8 +289,15 @@
       std::move(CI), PreamblePCH,
       llvm::MemoryBuffer::getMemBufferCopy(Inputs.Contents, Filename), VFS,
       ASTDiags);
-  if (!Clang)
+  if (!Clang) {
+    // The last diagnostic contains information about the reason of this
+    // failure.
+    std::vector<Diag> Diags(ASTDiags.take());
+    elog("Failed to prepare a compiler instance: {0}",
+         !Diags.empty() ? static_cast<DiagBase &>(Diags.back()).Message
+                        : "unknown error");
     return None;
+  }
 
   auto Action = std::make_unique<ClangdFrontendAction>();
   const FrontendInputFile &MainInput = Clang->getFrontendOpts().Inputs[0];


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104056.355389.patch
Type: text/x-patch
Size: 1488 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210629/f0cb0ee1/attachment-0001.bin>


More information about the cfe-commits mailing list