Skip to content

Commit

Permalink
[clangd] Skip extra round-trip in parsing args in debug builds. NFC
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sam-mccall committed May 9, 2022
1 parent bf9921a commit bb53eb1
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions clang-tools-extra/clangd/Compiler.cpp
Expand Up @@ -85,10 +85,16 @@ void disableUnsupportedOptions(CompilerInvocation &CI) {
std::unique_ptr<CompilerInvocation>
buildCompilerInvocation(const ParseInputs &Inputs, clang::DiagnosticConsumer &D,
std::vector<std::string> *CC1Args) {
if (Inputs.CompileCommand.CommandLine.empty())
llvm::ArrayRef<std::string> Argv = Inputs.CompileCommand.CommandLine;
if (Argv.empty())
return nullptr;
std::vector<const char *> 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;
Expand Down

0 comments on commit bb53eb1

Please sign in to comment.