Author: Haojian Wu Date: 2020-11-19T15:51:53+01:00 New Revision: 734d2f98f64940b1f545d677729d213a954c7a3f
URL: https://github.com/llvm/llvm-project/commit/734d2f98f64940b1f545d677729d213a954c7a3f DIFF: https://github.com/llvm/llvm-project/commit/734d2f98f64940b1f545d677729d213a954c7a3f.diff LOG: [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 Added: Modified: clang-tools-extra/clangd/Compiler.cpp clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clangd/Compiler.cpp b/clang-tools-extra/clangd/Compiler.cpp index c22585fc53f9..3d5c7113f852 100644 --- a/clang-tools-extra/clangd/Compiler.cpp +++ b/clang-tools-extra/clangd/Compiler.cpp @@ -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. diff --git a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp index 00303a28b92a..8f84d0ba4806 100644 --- a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp +++ b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp @@ -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( _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits