Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions clang-tools-extra/clang-tidy/ClangTidy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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();
}
Expand Down
3 changes: 2 additions & 1 deletion clang-tools-extra/clang-tidy/ClangTidy.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down
3 changes: 3 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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` by suppressing diagnostic
count messages.

New checks
^^^^^^^^^^

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
26 changes: 26 additions & 0 deletions clang-tools-extra/test/clang-tidy/infrastructure/quiet-flag.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// This test ensures that the --quiet flag only suppresses the "X warnings generated"
// message while keeping all diagnostic information including caret indicators (^).

// RUN: clang-tidy -checks=-*,readability-magic-numbers,clang-diagnostic-sign-compare %s -- \
// RUN: -Wsign-compare 2>&1 | FileCheck %s --check-prefix=CHECK-NORMAL
// RUN: clang-tidy -checks=-*,readability-magic-numbers,clang-diagnostic-sign-compare -quiet %s -- \
// RUN: -Wsign-compare 2>&1 | FileCheck %s --check-prefix=CHECK-QUIET

// CHECK-NORMAL: 2 warnings generated
// CHECK-NORMAL-DAG: warning: 42 is a magic number
// CHECK-NORMAL-DAG: {{[ ]*\^}}
// CHECK-NORMAL-DAG: warning: comparison of integers of different signs
// CHECK-NORMAL-DAG: {{[ ]*~ \^ ~}}

// CHECK-QUIET-NOT: {{[0-9]+}} warning{{s?}} generated
// CHECK-QUIET-DAG: warning: 42 is a magic number
// CHECK-QUIET-DAG: {{[ ]*\^}}
// CHECK-QUIET-DAG: warning: comparison of integers of different signs
// CHECK-QUIET-DAG: {{[ ]*~ \^ ~}}

int main() {
const int CONST_VAL = 10;
int x = 42; // trigger 'readability-magic-numbers' with caret: ^
unsigned int y = CONST_VAL;
return x < y; // trigger 'clang-diagnostic-sign-compare' with caret: ^
}