Author: Sam McCall Date: 2019-11-29T11:00:01+01:00 New Revision: 407ac2eb5f136af5ddd213b8bcca176481ec5198
URL: https://github.com/llvm/llvm-project/commit/407ac2eb5f136af5ddd213b8bcca176481ec5198 DIFF: https://github.com/llvm/llvm-project/commit/407ac2eb5f136af5ddd213b8bcca176481ec5198.diff LOG: [clangd] Log cc1 args at verbose level. Summary: This will help debugging driver issues. Reviewers: kbobyrev Subscribers: ilya-biryukov, javed.absar, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70832 Added: Modified: clang-tools-extra/clangd/Compiler.cpp clang-tools-extra/clangd/Compiler.h clang-tools-extra/clangd/TUScheduler.cpp clang/include/clang/Frontend/Utils.h clang/lib/Frontend/CreateInvocationFromCommandLine.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clangd/Compiler.cpp b/clang-tools-extra/clangd/Compiler.cpp index 795fd0082594..eae753b5c9b3 100644 --- a/clang-tools-extra/clangd/Compiler.cpp +++ b/clang-tools-extra/clangd/Compiler.cpp @@ -42,7 +42,8 @@ void IgnoreDiagnostics::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, std::unique_ptr<CompilerInvocation> buildCompilerInvocation(const ParseInputs &Inputs, - clang::DiagnosticConsumer &D) { + clang::DiagnosticConsumer &D, + std::vector<std::string> *CC1Args) { std::vector<const char *> ArgStrs; for (const auto &S : Inputs.CompileCommand.CommandLine) ArgStrs.push_back(S.c_str()); @@ -57,7 +58,7 @@ buildCompilerInvocation(const ParseInputs &Inputs, CompilerInstance::createDiagnostics(new DiagnosticOptions, &D, false); std::unique_ptr<CompilerInvocation> CI = createInvocationFromCommandLine( ArgStrs, CommandLineDiagsEngine, Inputs.FS, - /*ShouldRecoverOnErrors=*/true); + /*ShouldRecoverOnErrors=*/true, CC1Args); if (!CI) return nullptr; // createInvocationFromCommandLine sets DisableFree. diff --git a/clang-tools-extra/clangd/Compiler.h b/clang-tools-extra/clangd/Compiler.h index 6ab1b0f075f9..51414c37fc04 100644 --- a/clang-tools-extra/clangd/Compiler.h +++ b/clang-tools-extra/clangd/Compiler.h @@ -52,8 +52,8 @@ struct ParseInputs { /// Builds compiler invocation that could be used to build AST or preamble. std::unique_ptr<CompilerInvocation> -buildCompilerInvocation(const ParseInputs &Inputs, - clang::DiagnosticConsumer &D); +buildCompilerInvocation(const ParseInputs &Inputs, clang::DiagnosticConsumer &D, + std::vector<std::string> *CC1Args = nullptr); /// Creates a compiler instance, configured so that: /// - Contents of the parsed file are remapped to \p MainFile. diff --git a/clang-tools-extra/clangd/TUScheduler.cpp b/clang-tools-extra/clangd/TUScheduler.cpp index d740c3873695..b51221d7d903 100644 --- a/clang-tools-extra/clangd/TUScheduler.cpp +++ b/clang-tools-extra/clangd/TUScheduler.cpp @@ -407,8 +407,12 @@ void ASTWorker::update(ParseInputs Inputs, WantDiagnostics WantDiags) { llvm::join(Inputs.CompileCommand.CommandLine, " ")); // Rebuild the preamble and the AST. StoreDiags CompilerInvocationDiagConsumer; + std::vector<std::string> CC1Args; std::unique_ptr<CompilerInvocation> Invocation = buildCompilerInvocation(Inputs, CompilerInvocationDiagConsumer); + // Log cc1 args even (especially!) if creating invocation failed. + if (!CC1Args.empty()) + vlog("cc1 args: {0}", llvm::join(CC1Args, " ")); std::vector<Diag> CompilerInvocationDiags = CompilerInvocationDiagConsumer.take(); if (!Invocation) { diff --git a/clang/include/clang/Frontend/Utils.h b/clang/include/clang/Frontend/Utils.h index 0f9b17ee5089..2b142122cb66 100644 --- a/clang/include/clang/Frontend/Utils.h +++ b/clang/include/clang/Frontend/Utils.h @@ -217,14 +217,18 @@ createChainedIncludesSource(CompilerInstance &CI, /// non-null (and possibly incorrect) CompilerInvocation if any errors were /// encountered. When this flag is false, always return null on errors. /// -/// \return A CompilerInvocation, or 0 if none was built for the given +/// \param CC1Args - if non-null, will be populated with the args to cc1 +/// expanded from \p Args. May be set even if nullptr is returned. +/// +/// \return A CompilerInvocation, or nullptr if none was built for the given /// argument vector. std::unique_ptr<CompilerInvocation> createInvocationFromCommandLine( ArrayRef<const char *> Args, IntrusiveRefCntPtr<DiagnosticsEngine> Diags = IntrusiveRefCntPtr<DiagnosticsEngine>(), IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS = nullptr, - bool ShouldRecoverOnErrors = false); + bool ShouldRecoverOnErrors = false, + std::vector<std::string> *CC1Args = nullptr); /// Return the value of the last argument as an integer, or a default. If Diags /// is non-null, emits an error if the argument is given, but non-integral. diff --git a/clang/lib/Frontend/CreateInvocationFromCommandLine.cpp b/clang/lib/Frontend/CreateInvocationFromCommandLine.cpp index ab62b633cda3..18c4814bbd5c 100644 --- a/clang/lib/Frontend/CreateInvocationFromCommandLine.cpp +++ b/clang/lib/Frontend/CreateInvocationFromCommandLine.cpp @@ -26,7 +26,8 @@ using namespace llvm::opt; std::unique_ptr<CompilerInvocation> clang::createInvocationFromCommandLine( ArrayRef<const char *> ArgList, IntrusiveRefCntPtr<DiagnosticsEngine> Diags, - IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS, bool ShouldRecoverOnErorrs) { + IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS, bool ShouldRecoverOnErorrs, + std::vector<std::string> *CC1Args) { if (!Diags.get()) { // No diagnostics engine was provided, so create our own diagnostics object // with the default options. @@ -89,6 +90,8 @@ std::unique_ptr<CompilerInvocation> clang::createInvocationFromCommandLine( } const ArgStringList &CCArgs = Cmd.getArguments(); + if (CC1Args) + *CC1Args = {CCArgs.begin(), CCArgs.end()}; auto CI = std::make_unique<CompilerInvocation>(); if (!CompilerInvocation::CreateFromArgs(*CI, CCArgs, *Diags) && !ShouldRecoverOnErorrs) _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits