sammccall created this revision. sammccall added a reviewer: kbobyrev. Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous, MaskRay, javed.absar, ilya-biryukov. Herald added a project: clang.
This will help debugging driver issues. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D70832 Files: 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
Index: clang/lib/Frontend/CreateInvocationFromCommandLine.cpp =================================================================== --- clang/lib/Frontend/CreateInvocationFromCommandLine.cpp +++ clang/lib/Frontend/CreateInvocationFromCommandLine.cpp @@ -26,7 +26,8 @@ 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 @@ } 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) Index: clang/include/clang/Frontend/Utils.h =================================================================== --- clang/include/clang/Frontend/Utils.h +++ clang/include/clang/Frontend/Utils.h @@ -217,14 +217,18 @@ /// 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. Index: clang-tools-extra/clangd/TUScheduler.cpp =================================================================== --- clang-tools-extra/clangd/TUScheduler.cpp +++ clang-tools-extra/clangd/TUScheduler.cpp @@ -407,8 +407,12 @@ 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) { Index: clang-tools-extra/clangd/Compiler.h =================================================================== --- clang-tools-extra/clangd/Compiler.h +++ clang-tools-extra/clangd/Compiler.h @@ -68,7 +68,8 @@ std::unique_ptr<CompilerInstance> prepareCompilerInstance( std::unique_ptr<clang::CompilerInvocation>, const PrecompiledPreamble *, std::unique_ptr<llvm::MemoryBuffer> MainFile, - IntrusiveRefCntPtr<llvm::vfs::FileSystem>, DiagnosticConsumer &); + IntrusiveRefCntPtr<llvm::vfs::FileSystem>, DiagnosticConsumer &, + std::vector<std::string> *CC1Args = nullptr); } // namespace clangd } // namespace clang Index: clang-tools-extra/clangd/Compiler.cpp =================================================================== --- clang-tools-extra/clangd/Compiler.cpp +++ clang-tools-extra/clangd/Compiler.cpp @@ -42,7 +42,8 @@ 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 @@ 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.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits