ArcsinX created this revision. ArcsinX added reviewers: sammccall, kadircet. Herald added subscribers: usaxena95, arphaman. ArcsinX requested review of this revision. Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov. Herald added a project: clang-tools-extra.
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 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' Repository: rG LLVM Github Monorepo 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. + elog("Failed to prepare a compiler instance: {0}", + ASTDiags.getNumErrors() + ? static_cast<DiagBase &>(ASTDiags.take().back()).Message + : "unknown error"); return None; + } auto Action = std::make_unique<ClangdFrontendAction>(); const FrontendInputFile &MainInput = Clang->getFrontendOpts().Inputs[0];
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. + elog("Failed to prepare a compiler instance: {0}", + ASTDiags.getNumErrors() + ? static_cast<DiagBase &>(ASTDiags.take().back()).Message + : "unknown error"); return None; + } auto Action = std::make_unique<ClangdFrontendAction>(); const FrontendInputFile &MainInput = Clang->getFrontendOpts().Inputs[0];
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits