From: Sam McCall Date: Sat, 7 May 2022 15:31:52 +0000 (+0200) Subject: [clangd] Skip extra round-trip in parsing args in debug builds. NFC X-Git-Tag: upstream/15.0.7~8265 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bb53eb1ef4369fa7ae13d693eb219665c2cecd24;p=platform%2Fupstream%2Fllvm.git [clangd] Skip extra round-trip in parsing args in debug builds. NFC This is a clever cross-cutting sanity test for clang's arg parsing I suppose. But clangd creates thousands of invocations, ~all with identical trivial arguments, and problems with these would be caught by clang's tests. This overhead accounts for 10% of total unittest time! Differential Revision: https://reviews.llvm.org/D125169 --- diff --git a/clang-tools-extra/clangd/Compiler.cpp b/clang-tools-extra/clangd/Compiler.cpp index 2cf2eb8..04ec045 100644 --- a/clang-tools-extra/clangd/Compiler.cpp +++ b/clang-tools-extra/clangd/Compiler.cpp @@ -85,10 +85,16 @@ void disableUnsupportedOptions(CompilerInvocation &CI) { std::unique_ptr buildCompilerInvocation(const ParseInputs &Inputs, clang::DiagnosticConsumer &D, std::vector *CC1Args) { - if (Inputs.CompileCommand.CommandLine.empty()) + llvm::ArrayRef Argv = Inputs.CompileCommand.CommandLine; + if (Argv.empty()) return nullptr; std::vector ArgStrs; - for (const auto &S : Inputs.CompileCommand.CommandLine) + ArgStrs.reserve(Argv.size() + 1); + // In asserts builds, CompilerInvocation redundantly reads/parses cc1 args as + // a sanity test. This is not useful to clangd, and costs 10% of test time. + // To avoid mismatches between assert/production builds, disable it always. + ArgStrs = {Argv.front().c_str(), "-Xclang", "-no-round-trip-args"}; + for (const auto &S : Argv.drop_front()) ArgStrs.push_back(S.c_str()); CreateInvocationOptions CIOpts;