Skip to content

Commit 8664393

Browse files
author
git apple-llvm automerger
committed
Merge commit 'ed2699397633' from llvm.org/main into next
2 parents eb5af1b + ed26993 commit 8664393

File tree

6 files changed

+41
-7
lines changed

6 files changed

+41
-7
lines changed

clang-tools-extra/clang-tidy/ClangTidy.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ runClangTidy(clang::tidy::ClangTidyContext &Context,
544544
ArrayRef<std::string> InputFiles,
545545
llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> BaseFS,
546546
bool ApplyAnyFix, bool EnableCheckProfile,
547-
llvm::StringRef StoreCheckProfile) {
547+
llvm::StringRef StoreCheckProfile, bool Quiet) {
548548
ClangTool Tool(Compilations, InputFiles,
549549
std::make_shared<PCHContainerOperations>(), BaseFS);
550550

@@ -581,8 +581,9 @@ runClangTidy(clang::tidy::ClangTidyContext &Context,
581581
class ActionFactory : public FrontendActionFactory {
582582
public:
583583
ActionFactory(ClangTidyContext &Context,
584-
IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> BaseFS)
585-
: ConsumerFactory(Context, std::move(BaseFS)) {}
584+
IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> BaseFS,
585+
bool Quiet)
586+
: ConsumerFactory(Context, std::move(BaseFS)), Quiet(Quiet) {}
586587
std::unique_ptr<FrontendAction> create() override {
587588
return std::make_unique<Action>(&ConsumerFactory);
588589
}
@@ -593,6 +594,8 @@ runClangTidy(clang::tidy::ClangTidyContext &Context,
593594
DiagnosticConsumer *DiagConsumer) override {
594595
// Explicitly ask to define __clang_analyzer__ macro.
595596
Invocation->getPreprocessorOpts().SetUpStaticAnalyzer = true;
597+
if (Quiet)
598+
Invocation->getDiagnosticOpts().ShowCarets = false;
596599
return FrontendActionFactory::runInvocation(
597600
Invocation, Files, PCHContainerOps, DiagConsumer);
598601
}
@@ -611,9 +614,10 @@ runClangTidy(clang::tidy::ClangTidyContext &Context,
611614
};
612615

613616
ClangTidyASTConsumerFactory ConsumerFactory;
617+
bool Quiet;
614618
};
615619

616-
ActionFactory Factory(Context, std::move(BaseFS));
620+
ActionFactory Factory(Context, std::move(BaseFS), Quiet);
617621
Tool.run(&Factory);
618622
return DiagConsumer.take();
619623
}

clang-tools-extra/clang-tidy/ClangTidy.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ runClangTidy(clang::tidy::ClangTidyContext &Context,
9494
ArrayRef<std::string> InputFiles,
9595
llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> BaseFS,
9696
bool ApplyAnyFix, bool EnableCheckProfile = false,
97-
llvm::StringRef StoreCheckProfile = StringRef());
97+
llvm::StringRef StoreCheckProfile = StringRef(),
98+
bool Quiet = false);
9899

99100
/// Controls what kind of fixes clang-tidy is allowed to apply.
100101
enum FixBehaviour {

clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ int clangTidyMain(int argc, const char **argv) {
717717
EnableModuleHeadersParsing);
718718
std::vector<ClangTidyError> Errors =
719719
runClangTidy(Context, OptionsParser->getCompilations(), PathList, BaseFS,
720-
FixNotes, EnableCheckProfile, ProfilePrefix);
720+
FixNotes, EnableCheckProfile, ProfilePrefix, Quiet);
721721
bool FoundErrors = llvm::any_of(Errors, [](const ClangTidyError &E) {
722722
return E.DiagLevel == ClangTidyError::Error;
723723
});

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ Improvements to clang-tidy
119119
- Improved documentation of the `-line-filter` command-line flag of
120120
:program:`clang-tidy` and :program:`run-clang-tidy.py`.
121121

122+
- Improved :program:`clang-tidy` option `-quiet` by suppressing diagnostic
123+
count messages.
124+
122125
New checks
123126
^^^^^^^^^^
124127

clang-tools-extra/test/clang-tidy/infrastructure/file-filter-symlinks.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='header_alias\.h' %s -- -I %t 2>&1 | FileCheck --check-prefix=CHECK_HEADER_ALIAS %s
1111
// 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
1212
// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='header\.h' %s -- -I %t 2>&1 | FileCheck --check-prefix=CHECK_HEADER %s
13-
// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='header\.h' -quiet %s -- -I %t 2>&1 | FileCheck --check-prefix=CHECK_HEADER %s
13+
// 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
1414

1515
// Check that `-header-filter` operates on the same file paths as paths in
1616
// diagnostics printed by ClangTidy.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// This test ensures that the --quiet flag only suppresses the "X warnings generated"
2+
// message while keeping all diagnostic information including caret indicators (^).
3+
4+
// RUN: clang-tidy -checks=-*,readability-magic-numbers,clang-diagnostic-sign-compare %s -- \
5+
// RUN: -Wsign-compare 2>&1 | FileCheck %s --check-prefix=CHECK-NORMAL
6+
// RUN: clang-tidy -checks=-*,readability-magic-numbers,clang-diagnostic-sign-compare -quiet %s -- \
7+
// RUN: -Wsign-compare 2>&1 | FileCheck %s --check-prefix=CHECK-QUIET
8+
9+
// CHECK-NORMAL: 2 warnings generated
10+
// CHECK-NORMAL-DAG: warning: 42 is a magic number
11+
// CHECK-NORMAL-DAG: {{[ ]*\^}}
12+
// CHECK-NORMAL-DAG: warning: comparison of integers of different signs
13+
// CHECK-NORMAL-DAG: {{[ ]*~ \^ ~}}
14+
15+
// CHECK-QUIET-NOT: {{[0-9]+}} warning{{s?}} generated
16+
// CHECK-QUIET-DAG: warning: 42 is a magic number
17+
// CHECK-QUIET-DAG: {{[ ]*\^}}
18+
// CHECK-QUIET-DAG: warning: comparison of integers of different signs
19+
// CHECK-QUIET-DAG: {{[ ]*~ \^ ~}}
20+
21+
int main() {
22+
const int CONST_VAL = 10;
23+
int x = 42; // trigger 'readability-magic-numbers' with caret: ^
24+
unsigned int y = CONST_VAL;
25+
return x < y; // trigger 'clang-diagnostic-sign-compare' with caret: ^
26+
}

0 commit comments

Comments
 (0)