[clang-tools-extra] [clangd] don't lower severity of clang-tidy modernize-* checks to remarks (PR #75706)

Julian Schmidt via cfe-commits cfe-commits at lists.llvm.org
Sat Dec 16 09:11:48 PST 2023


https://github.com/5chmidti created https://github.com/llvm/llvm-project/pull/75706

Starting with a59b24be47ed6263c254d168567b9ebba391fac9, the severity of
diagnostics that have the 'Deprecated' tag is lowered to 'Remark'.
Because the `Deprecated` tag is applied to clang-tidy checks in
the modernize category, this leads to inconsistencies in reported
clang-tidy diagnostics.


>From fa6a69841102d529a31462affae5cdfabac417ff Mon Sep 17 00:00:00 2001
From: Julian Schmidt <44101708+5chmidti at users.noreply.github.com>
Date: Sat, 16 Dec 2023 18:05:34 +0100
Subject: [PATCH] [clangd] don't lower severity of clang-tidy modernize-*
 checks to remarks

Starting with a59b24be47ed6263c254d168567b9ebba391fac9, the severity of
diagnostics that have the 'Deprecated' tag is lowered to 'Remark'.
Because the `Deprecated` tag is applied to clang-tidy checks in
the modernize category, this leads to inconsistencies in reported
clang-tidy diagnostics.
---
 clang-tools-extra/clangd/Diagnostics.cpp           |  6 ++++--
 .../clangd/unittests/DiagnosticsTests.cpp          | 14 ++++++++++++--
 clang-tools-extra/docs/ReleaseNotes.rst            |  3 +++
 3 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/clang-tools-extra/clangd/Diagnostics.cpp b/clang-tools-extra/clangd/Diagnostics.cpp
index 704e61b1e4dd79..a56d450fb44da1 100644
--- a/clang-tools-extra/clangd/Diagnostics.cpp
+++ b/clang-tools-extra/clangd/Diagnostics.cpp
@@ -474,8 +474,10 @@ void toLSPDiags(
   // We downgrade severity for certain noisy warnings, like deprecated
   // declartions. These already have visible decorations inside the editor and
   // most users find the extra clutter in the UI (gutter, minimap, diagnostics
-  // views) overwhelming.
-  if (D.Severity == DiagnosticsEngine::Warning) {
+  // views) overwhelming. Because clang-tidy's modernize checks get the
+  // `Deprecated` tag, guard against lowering clang-tidy diagnostic levels.
+  if (D.Severity == DiagnosticsEngine::Warning &&
+      D.Source != Diag::DiagSource::ClangTidy) {
     if (llvm::is_contained(D.Tags, DiagnosticTag::Deprecated))
       Main.severity = getSeverity(DiagnosticsEngine::Remark);
   }
diff --git a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
index 37643e5afa2304..b4f7cb71f15e57 100644
--- a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -1811,10 +1811,10 @@ TEST(ParsedASTTest, ModuleSawDiag) {
   TestTU TU;
 
   auto AST = TU.build();
-        #if 0
+#if 0
   EXPECT_THAT(AST.getDiagnostics(),
               testing::Contains(Diag(Code.range(), KDiagMsg.str())));
-        #endif
+#endif
 }
 
 TEST(Preamble, EndsOnNonEmptyLine) {
@@ -1882,6 +1882,16 @@ TEST(Diagnostics, DeprecatedDiagsAreHints) {
   EXPECT_EQ(Diag->severity, getSeverity(DiagnosticsEngine::Remark));
   Diag.reset();
 
+  // Don't downgrade warnings from clang-tidy that have deprecated tags
+  D.Source = Diag::DiagSource::ClangTidy;
+  toLSPDiags(D, {}, Opts,
+             [&](clangd::Diagnostic LSPDiag, ArrayRef<clangd::Fix>) {
+               Diag = std::move(LSPDiag);
+             });
+  EXPECT_EQ(Diag->severity, getSeverity(DiagnosticsEngine::Warning));
+  D.Source = Diag::DiagSource::Unknown;
+  Diag.reset();
+
   // Preserve errors.
   D.Severity = DiagnosticsEngine::Error;
   toLSPDiags(D, {}, Opts,
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 6d91748e4cef18..2d8d57a535e4a8 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -54,6 +54,9 @@ Inlay hints
 Diagnostics
 ^^^^^^^^^^^
 
+- Fixed a bug where the severity of diagnostics from clang-tidy modernize-* checks were
+  lowered to remarks.
+
 Semantic Highlighting
 ^^^^^^^^^^^^^^^^^^^^^
 



More information about the cfe-commits mailing list