[PATCH] D146520: [clang-tidy] Fix checks filter with warnings-as-errors

Piotr Zegar via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Jul 22 07:13:27 PDT 2023


PiotrZSL updated this revision to Diff 543185.
PiotrZSL edited the summary of this revision.
PiotrZSL added a comment.

Add test & release notes.
Cleanup commit description.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146520/new/

https://reviews.llvm.org/D146520

Files:
  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


Index: clang-tools-extra/test/clang-tidy/infrastructure/warnings-as-errors-diagnostics.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/infrastructure/warnings-as-errors-diagnostics.cpp
+++ 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 @@
 // 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).
Index: clang-tools-extra/docs/ReleaseNotes.rst
===================================================================
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -106,6 +106,11 @@
 - 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, using `Checks` (`--checks=`) as the filter. Use
+  `-Werror=<warning>` on the compiler command-line for custom error promotion
+  irrespective of `Checks` (`--checks=`) settings.
+
 New checks
 ^^^^^^^^^^
 
Index: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
===================================================================
--- clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -421,8 +421,6 @@
 
     bool IsWarningAsError = DiagLevel == DiagnosticsEngine::Warning &&
                             Context.treatAsError(CheckName);
-    if (IsWarningAsError)
-      Level = ClangTidyError::Error;
     Errors.emplace_back(CheckName, Level, Context.getCurrentBuildDirectory(),
                         IsWarningAsError);
   }
Index: clang-tools-extra/clang-tidy/ClangTidy.cpp
===================================================================
--- clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -620,6 +620,8 @@
   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);
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146520.543185.patch
Type: text/x-patch
Size: 3930 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230722/f931f71c/attachment.bin>


More information about the cfe-commits mailing list