https://github.com/vbvictor updated https://github.com/llvm/llvm-project/pull/154012
>From 09a1f8e854f95eedb8cf064f980711390290b3e5 Mon Sep 17 00:00:00 2001 From: Victor Baranov <bar.victor.2...@gmail.com> Date: Sun, 17 Aug 2025 14:16:36 +0300 Subject: [PATCH 1/3] [clang-tidy] Improve "-quiet" option by suppressing warnings count --- clang-tools-extra/clang-tidy/ClangTidy.cpp | 12 ++++++++---- clang-tools-extra/clang-tidy/ClangTidy.h | 3 ++- .../clang-tidy/tool/ClangTidyMain.cpp | 2 +- clang-tools-extra/docs/ReleaseNotes.rst | 3 +++ .../infrastructure/file-filter-symlinks.cpp | 2 +- .../test/clang-tidy/infrastructure/quiet-flag.cpp | 14 ++++++++++++++ 6 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 clang-tools-extra/test/clang-tidy/infrastructure/quiet-flag.cpp diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp b/clang-tools-extra/clang-tidy/ClangTidy.cpp index 4ae2864d310d0..8f5728dea8c2a 100644 --- a/clang-tools-extra/clang-tidy/ClangTidy.cpp +++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp @@ -540,7 +540,7 @@ runClangTidy(clang::tidy::ClangTidyContext &Context, ArrayRef<std::string> InputFiles, llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> BaseFS, bool ApplyAnyFix, bool EnableCheckProfile, - llvm::StringRef StoreCheckProfile) { + llvm::StringRef StoreCheckProfile, bool Quiet) { ClangTool Tool(Compilations, InputFiles, std::make_shared<PCHContainerOperations>(), BaseFS); @@ -577,8 +577,9 @@ runClangTidy(clang::tidy::ClangTidyContext &Context, class ActionFactory : public FrontendActionFactory { public: ActionFactory(ClangTidyContext &Context, - IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> BaseFS) - : ConsumerFactory(Context, std::move(BaseFS)) {} + IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> BaseFS, + bool Quiet) + : ConsumerFactory(Context, std::move(BaseFS)), Quiet(Quiet) {} std::unique_ptr<FrontendAction> create() override { return std::make_unique<Action>(&ConsumerFactory); } @@ -589,6 +590,8 @@ runClangTidy(clang::tidy::ClangTidyContext &Context, DiagnosticConsumer *DiagConsumer) override { // Explicitly ask to define __clang_analyzer__ macro. Invocation->getPreprocessorOpts().SetUpStaticAnalyzer = true; + if (Quiet) + Invocation->getDiagnosticOpts().ShowCarets = false; return FrontendActionFactory::runInvocation( Invocation, Files, PCHContainerOps, DiagConsumer); } @@ -607,9 +610,10 @@ runClangTidy(clang::tidy::ClangTidyContext &Context, }; ClangTidyASTConsumerFactory ConsumerFactory; + bool Quiet; }; - ActionFactory Factory(Context, std::move(BaseFS)); + ActionFactory Factory(Context, std::move(BaseFS), Quiet); Tool.run(&Factory); return DiagConsumer.take(); } diff --git a/clang-tools-extra/clang-tidy/ClangTidy.h b/clang-tools-extra/clang-tidy/ClangTidy.h index 454261bbd6840..d37d68ec0a5b9 100644 --- a/clang-tools-extra/clang-tidy/ClangTidy.h +++ b/clang-tools-extra/clang-tidy/ClangTidy.h @@ -94,7 +94,8 @@ runClangTidy(clang::tidy::ClangTidyContext &Context, ArrayRef<std::string> InputFiles, llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> BaseFS, bool ApplyAnyFix, bool EnableCheckProfile = false, - llvm::StringRef StoreCheckProfile = StringRef()); + llvm::StringRef StoreCheckProfile = StringRef(), + bool Quiet = false); /// Controls what kind of fixes clang-tidy is allowed to apply. enum FixBehaviour { diff --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp index df3a8b22b1e24..bef3b938b5afd 100644 --- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp +++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp @@ -717,7 +717,7 @@ int clangTidyMain(int argc, const char **argv) { EnableModuleHeadersParsing); std::vector<ClangTidyError> Errors = runClangTidy(Context, OptionsParser->getCompilations(), PathList, BaseFS, - FixNotes, EnableCheckProfile, ProfilePrefix); + FixNotes, EnableCheckProfile, ProfilePrefix, Quiet); bool FoundErrors = llvm::any_of(Errors, [](const ClangTidyError &E) { return E.DiagLevel == ClangTidyError::Error; }); diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index b481c56c262c4..e4b470026ef08 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -112,6 +112,9 @@ Improvements to clang-tidy - Improved documentation of the `-line-filter` command-line flag of :program:`clang-tidy` and :program:`run-clang-tidy.py`. +- Improved :program:`clang-tidy` option `quiet` to suppresses diagnostic count + messages. + New checks ^^^^^^^^^^ diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/file-filter-symlinks.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/file-filter-symlinks.cpp index 7efa7d070f69f..58f3b23cb1dbf 100644 --- a/clang-tools-extra/test/clang-tidy/infrastructure/file-filter-symlinks.cpp +++ b/clang-tools-extra/test/clang-tidy/infrastructure/file-filter-symlinks.cpp @@ -10,7 +10,7 @@ // RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='header_alias\.h' %s -- -I %t 2>&1 | FileCheck --check-prefix=CHECK_HEADER_ALIAS %s // RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='header_alias\.h' -quiet %s -- -I %t 2>&1 | FileCheck --check-prefix=CHECK_HEADER_ALIAS %s // RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='header\.h' %s -- -I %t 2>&1 | FileCheck --check-prefix=CHECK_HEADER %s -// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='header\.h' -quiet %s -- -I %t 2>&1 | FileCheck --check-prefix=CHECK_HEADER %s +// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='header\.h' -quiet %s -- -I %t 2>&1 | FileCheck --check-prefix=CHECK_HEADER --allow-empty %s // Check that `-header-filter` operates on the same file paths as paths in // diagnostics printed by ClangTidy. diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/quiet-flag.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/quiet-flag.cpp new file mode 100644 index 0000000000000..0e3d6164163a4 --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/infrastructure/quiet-flag.cpp @@ -0,0 +1,14 @@ +// RUN: clang-tidy -checks=-*,readability-magic-numbers %t.cpp -- 2>&1 | FileCheck %s --check-prefix=CHECK-NORMAL +// RUN: clang-tidy -checks=-*,readability-magic-numbers -quiet %t.cpp -- 2>&1 | FileCheck %s --check-prefix=CHECK-QUIET + +// Normal mode should show warning count +// CHECK-NORMAL: 1 warning generated +// CHECK-NORMAL: warning: 42 is a magic number + +// Quiet mode should suppress warning count +// CHECK-QUIET-NOT: 1 warning generated +// CHECK-QUIET: warning: 42 is a magic number + +int main() { + int x = 42; +} >From d4f3ed2512c021dd849bb70b77a6bf20998ad040 Mon Sep 17 00:00:00 2001 From: Victor Baranov <bar.victor.2...@gmail.com> Date: Sun, 17 Aug 2025 14:31:07 +0300 Subject: [PATCH 2/3] [clang-tidy] improve release notes of "-quiet" --- clang-tools-extra/docs/ReleaseNotes.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index e4b470026ef08..8a6d7d12bd65e 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -112,8 +112,8 @@ Improvements to clang-tidy - Improved documentation of the `-line-filter` command-line flag of :program:`clang-tidy` and :program:`run-clang-tidy.py`. -- Improved :program:`clang-tidy` option `quiet` to suppresses diagnostic count - messages. +- Improved :program:`clang-tidy` option `-quiet` by suppressing diagnostic + count messages. New checks ^^^^^^^^^^ >From 3f410e8238c067a2e844d4a146acf29b1f7a1ea8 Mon Sep 17 00:00:00 2001 From: Victor Baranov <bar.victor.2...@gmail.com> Date: Sun, 17 Aug 2025 15:07:39 +0300 Subject: [PATCH 3/3] fix test --- .../test/clang-tidy/infrastructure/quiet-flag.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/quiet-flag.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/quiet-flag.cpp index 0e3d6164163a4..fc31fb524fc86 100644 --- a/clang-tools-extra/test/clang-tidy/infrastructure/quiet-flag.cpp +++ b/clang-tools-extra/test/clang-tidy/infrastructure/quiet-flag.cpp @@ -1,14 +1,14 @@ -// RUN: clang-tidy -checks=-*,readability-magic-numbers %t.cpp -- 2>&1 | FileCheck %s --check-prefix=CHECK-NORMAL -// RUN: clang-tidy -checks=-*,readability-magic-numbers -quiet %t.cpp -- 2>&1 | FileCheck %s --check-prefix=CHECK-QUIET +// RUN: clang-tidy -checks=-*,readability-magic-numbers %s -- 2>&1 | FileCheck %s --check-prefix=CHECK-NORMAL +// RUN: clang-tidy -checks=-*,readability-magic-numbers -quiet %s -- 2>&1 | FileCheck %s --check-prefix=CHECK-QUIET // Normal mode should show warning count // CHECK-NORMAL: 1 warning generated // CHECK-NORMAL: warning: 42 is a magic number -// Quiet mode should suppress warning count -// CHECK-QUIET-NOT: 1 warning generated +// Quiet mode should suppress warning count but show diagnostic // CHECK-QUIET: warning: 42 is a magic number +// CHECK-QUIET-NOT: {{[0-9]+}} warning{{s?}} generated int main() { - int x = 42; + int x = 42; // This will trigger readability-magic-numbers } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits