[clangd] No crash on "-verify" mode.

If there is a "-verify" flag in the compile command, clangd will crash
(hit the assertion) inside the `~VerifyDiagnosticConsumer` (Looks like our
compiler invocation doesn't setup correctly?).

This patch disables the verify mode as it is rarely useful in clangd.

Differential Revision: https://reviews.llvm.org/D91777
This commit is contained in:
Haojian Wu 2020-11-19 11:02:14 +01:00
parent 7a0ea120e2
commit 734d2f98f6
2 changed files with 13 additions and 0 deletions

View File

@ -60,6 +60,10 @@ buildCompilerInvocation(const ParseInputs &Inputs, clang::DiagnosticConsumer &D,
CI->getFrontendOpts().DisableFree = false;
CI->getLangOpts()->CommentOpts.ParseAllComments = true;
CI->getLangOpts()->RetainCommentsFromSystemHeaders = true;
// Disable "clang -verify" diagnostics, they are rarely useful in clangd, and
// our compiler invocation set-up doesn't seem to work with it (leading
// assertions in VerifyDiagnosticConsumer).
CI->getDiagnosticOpts().VerifyDiagnostics = false;
// Disable any dependency outputting, we don't want to generate files or write
// to stdout/stderr.

View File

@ -491,6 +491,15 @@ TEST(DiagnosticsTest, Preprocessor) {
ElementsAre(Diag(Test.range(), "use of undeclared identifier 'b'")));
}
TEST(DiagnosticsTest, IgnoreVerify) {
auto TU = TestTU::withCode(R"cpp(
int a; // expected-error {{}}
)cpp");
TU.ExtraArgs.push_back("-Xclang");
TU.ExtraArgs.push_back("-verify");
EXPECT_THAT(TU.build().getDiagnostics(), IsEmpty());
}
// Recursive main-file include is diagnosed, and doesn't crash.
TEST(DiagnosticsTest, RecursivePreamble) {
auto TU = TestTU::withCode(R"cpp(