[clang-tools-extra] 9644368 - [clang-tidy] Fix checks filter with warnings-as-errors
Piotr Zegar via cfe-commits
cfe-commits at lists.llvm.org
Sat Jul 22 12:33:00 PDT 2023
Author: Piotr Zegar
Date: 2023-07-22T19:31:51Z
New Revision: 9644368f974a095472832bbf9cd475ef5c2c307f
URL: https://github.com/llvm/llvm-project/commit/9644368f974a095472832bbf9cd475ef5c2c307f
DIFF: https://github.com/llvm/llvm-project/commit/9644368f974a095472832bbf9cd475ef5c2c307f.diff
LOG: [clang-tidy] Fix checks filter with warnings-as-errors
Since commit 5d12b13b0b26bc58b02ee23c369da8b83240cceb, warnings are
internally classified as errors which skip the check filters.
One use-case is particularly affected: you cannot selectively disable
clang-analyzer-core checks, they are force-enabled because required by others.
So enabling warning as errors will show new (and unwanted) errors !
Co-authored-by: kiwixz <kiwixz at outlook.com>
Fixes: #61969
Reviewed By: carlosgalvezp
Differential Revision: https://reviews.llvm.org/D146520
Added:
Modified:
clang-tools-extra/clang-tidy/ClangTidy.cpp
clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/infrastructure/warnings-as-errors-diagnostics.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp b/clang-tools-extra/clang-tidy/ClangTidy.cpp
index 445d268cee5d38..bdead368195e33 100644
--- a/clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -620,6 +620,8 @@ void exportReplacements(const llvm::StringRef MainFilePath,
TUD.MainSourceFile = std::string(MainFilePath);
for (const auto &Error : Errors) {
tooling::Diagnostic Diag = Error;
+ if (Error.IsWarningAsError)
+ Diag.DiagLevel = tooling::Diagnostic::Error;
TUD.Diagnostics.insert(TUD.Diagnostics.end(), Diag);
}
diff --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
index 9d693bd94f40a0..57bd643c00139a 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -421,8 +421,6 @@ void ClangTidyDiagnosticConsumer::HandleDiagnostic(
bool IsWarningAsError = DiagLevel == DiagnosticsEngine::Warning &&
Context.treatAsError(CheckName);
- if (IsWarningAsError)
- Level = ClangTidyError::Error;
Errors.emplace_back(CheckName, Level, Context.getCurrentBuildDirectory(),
IsWarningAsError);
}
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 274759172689e8..3b4a9488e1206f 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -106,6 +106,11 @@ Improvements to clang-tidy
- Support specifying `SystemHeaders` in the `.clang-tidy` configuration file,
with the same functionality as the command-line option `--system-headers`.
+- `WarningsAsErrors` (`--warnings-as-errors=`) no longer promotes unlisted
+ warnings to errors. Only the warnings listed in `Checks` (`--checks=`) will
+ be promoted to errors. For custom error promotion, use `-Werror=<warning>`
+ on the compiler command-line, irrespective of `Checks` (`--checks=`) settings.
+
New checks
^^^^^^^^^^
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/warnings-as-errors-diagnostics.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/warnings-as-errors-diagnostics.cpp
index 9f90b62256e403..e57011b2bf0b85 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/warnings-as-errors-diagnostics.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/warnings-as-errors-diagnostics.cpp
@@ -1,12 +1,15 @@
-// RUN: clang-tidy %s -checks='-*,llvm-namespace-comment,clang-diagnostic*' \
+// RUN: clang-tidy %s --checks='-*,llvm-namespace-comment,clang-diagnostic*' \
// RUN: -- -Wunused-variable 2>&1 \
// RUN: | FileCheck %s --check-prefix=CHECK-WARN -implicit-check-not='{{warning|error}}:'
-// RUN: not clang-tidy %s -checks='-*,llvm-namespace-comment,clang-diagnostic*' \
-// RUN: -warnings-as-errors='clang-diagnostic*' -- -Wunused-variable 2>&1 \
+// RUN: not clang-tidy %s --checks='-*,llvm-namespace-comment,clang-diagnostic*' \
+// RUN: --warnings-as-errors='clang-diagnostic*' -- -Wunused-variable 2>&1 \
// RUN: | FileCheck %s --check-prefix=CHECK-WERR -implicit-check-not='{{warning|error}}:'
-// RUN: not clang-tidy %s -checks='-*,llvm-namespace-comment,clang-diagnostic*' \
-// RUN: -warnings-as-errors='clang-diagnostic*' -quiet -- -Wunused-variable 2>&1 \
+// RUN: not clang-tidy %s --checks='-*,llvm-namespace-comment,clang-diagnostic*' \
+// RUN: --warnings-as-errors='clang-diagnostic*' -quiet -- -Wunused-variable 2>&1 \
// RUN: | FileCheck %s --check-prefix=CHECK-WERR-QUIET -implicit-check-not='{{warning|error}}:'
+// RUN: clang-tidy %s --checks='-*,llvm-namespace-comment' --warnings-as-errors=* -- \
+// RUN: -Wunused-variable 2>&1 | FileCheck %s --check-prefix=CHECK-SUPPRESSED \
+// RUN: -implicit-check-not='{{warning|error}}:'
void f() { int i; }
// CHECK-WARN: warning: unused variable 'i' [clang-diagnostic-unused-variable]
@@ -16,3 +19,7 @@ void f() { int i; }
// CHECK-WARN-NOT: treated as
// CHECK-WERR: 1 warning treated as error
// CHECK-WERR-QUIET-NOT: treated as
+
+// CHECK-SUPPRESSED-NOT: unused variable 'i'
+// CHECK-SUPPRESSED: 1 warning generated.
+// CHECK-SUPPRESSED: Suppressed 1 warnings (1 with check filters).
More information about the cfe-commits
mailing list