[clang-tools-extra] 57b12e8 - [clangd] Improve robustness when clang-tidy check names contain leading spaces. (#109421)

via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 20 06:54:43 PDT 2024


Author: Haojian Wu
Date: 2024-09-20T15:54:39+02:00
New Revision: 57b12e8fbc9bb29ebe8f9d2a0f2c5085b38c2454

URL: https://github.com/llvm/llvm-project/commit/57b12e8fbc9bb29ebe8f9d2a0f2c5085b38c2454
DIFF: https://github.com/llvm/llvm-project/commit/57b12e8fbc9bb29ebe8f9d2a0f2c5085b38c2454.diff

LOG: [clangd] Improve robustness when clang-tidy check names contain leading spaces. (#109421)

The current logic assumes that check names do not have leading spaces.

In cases like "-*, clang-diagnostic*", when processing the second check
" clang-diagnostics-*" (with a leading space), the check fails on
`CDPrefix.starts_with(Check)`, resulting in all diagnostics remaining
disabled.

Added: 
    

Modified: 
    clang-tools-extra/clangd/ParsedAST.cpp
    clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/ParsedAST.cpp b/clang-tools-extra/clangd/ParsedAST.cpp
index 4491be9aa0362b..5cf1691ce39617 100644
--- a/clang-tools-extra/clangd/ParsedAST.cpp
+++ b/clang-tools-extra/clangd/ParsedAST.cpp
@@ -280,6 +280,8 @@ class TidyDiagnosticGroups {
     llvm::StringRef Check;
     while (!Checks.empty()) {
       std::tie(Check, Checks) = Checks.split(',');
+      Check = Check.trim();
+
       if (Check.empty())
         continue;
 

diff  --git a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
index 096f77e414f5a5..efb2e5ed2fbe1d 100644
--- a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -748,6 +748,10 @@ TEST(DiagnosticTest, ClangTidyEnablesClangWarning) {
   TU.ExtraArgs = {"-Wunused"};
   TU.ClangTidyProvider = addClangArgs({"-Wno-unused"}, {});
   EXPECT_THAT(TU.build().getDiagnostics(), IsEmpty());
+
+  TU.ExtraArgs = {"-Wno-unused"};
+  TU.ClangTidyProvider = addClangArgs({"-Wunused"}, {"-*, clang-diagnostic-*"});
+  EXPECT_THAT(TU.build().getDiagnostics(), SizeIs(1));
 }
 
 TEST(DiagnosticTest, LongFixMessages) {


        


More information about the cfe-commits mailing list