[clang-tools-extra] a62579f - [clangd][nfc] Show more information in logs when compiler instance prepare fails
Aleksandr Platonov via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 30 13:59:15 PDT 2021
Author: Aleksandr Platonov
Date: 2021-06-30T21:58:33+01:00
New Revision: a62579fc008e22b6c9e1544788644f5fceef15ce
URL: https://github.com/llvm/llvm-project/commit/a62579fc008e22b6c9e1544788644f5fceef15ce
DIFF: https://github.com/llvm/llvm-project/commit/a62579fc008e22b6c9e1544788644f5fceef15ce.diff
LOG: [clangd][nfc] Show more information in logs when compiler instance prepare fails
Without this patch clangd silently process compiler instance prepare failure and only LSP errors "Invalid AST" could be found in logs.
E.g. the reason of the problem https://github.com/clangd/clangd/issues/734 is impossible to understand without verbose logs or with disabled background index.
This patch adds more information into logs to help understand the reason of such failures.
Logs without this patch:
```
E[...] Could not build a preamble for file test.cpp version 1
```
Logs with this patch:
```
E[...] Could not build a preamble for file test.cpp version 1: CreateTargetInfo() return null
..
E[...] Failed to prepare a compiler instance: unknown target ABI 'lp64'
```
Reviewed By: sammccall
Differential Revision: https://reviews.llvm.org/D104056
Added:
Modified:
clang-tools-extra/clangd/ParsedAST.cpp
clang-tools-extra/clangd/Preamble.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/ParsedAST.cpp b/clang-tools-extra/clangd/ParsedAST.cpp
index 0d7e4631d660..cb8ad5a8fa9f 100644
--- a/clang-tools-extra/clangd/ParsedAST.cpp
+++ b/clang-tools-extra/clangd/ParsedAST.cpp
@@ -289,8 +289,15 @@ ParsedAST::build(llvm::StringRef Filename, const ParseInputs &Inputs,
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];
diff --git a/clang-tools-extra/clangd/Preamble.cpp b/clang-tools-extra/clangd/Preamble.cpp
index e003af6e0dfa..9173dcda513a 100644
--- a/clang-tools-extra/clangd/Preamble.cpp
+++ b/clang-tools-extra/clangd/Preamble.cpp
@@ -390,8 +390,8 @@ buildPreamble(PathRef FileName, CompilerInvocation CI,
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;
}
}
More information about the cfe-commits
mailing list