https://github.com/vbvictor updated https://github.com/llvm/llvm-project/pull/153870
>From a2e29274393a1adf00093a31c16706b7323a0240 Mon Sep 17 00:00:00 2001 From: Victor Baranov <bar.victor.2...@gmail.com> Date: Fri, 15 Aug 2025 23:18:22 +0300 Subject: [PATCH 1/2] [clang-tidy] Rename "clang-diagnostic-error" to "clang-compiler-error" --- .../clang-tidy/ClangTidyDiagnosticConsumer.cpp | 8 ++++---- clang-tools-extra/docs/ReleaseNotes.rst | 4 ++++ .../struct-pack-align-invalid-decl-no-crash.cpp | 2 +- .../checkers/altera/struct-pack-align-no-crash.cpp | 2 +- .../bugprone/branch-clone-unknown-expr.cpp | 6 +++--- .../bugprone/suspicious-semicolon-fail.cpp | 2 +- .../checkers/cppcoreguidelines/init-variables.cpp | 2 +- .../pro-type-member-init-no-crash.cpp | 2 +- .../checkers/misc/misplaced-const-cxx17.cpp | 2 +- .../checkers/misc/unused-using-decls-errors.cpp | 2 +- .../checkers/modernize/use-noexcept-error.cpp | 2 +- .../performance/noexcept-move-constructor.cpp | 4 ++-- .../unnecessary-value-param-incomplete-type.cpp | 2 +- .../isolate-declaration-no-infinite-loop.cpp | 2 +- .../test/clang-tidy/infrastructure/diagnostic.cpp | 14 +++++++------- .../infrastructure/export-diagnostics.cpp | 12 ++++++------ .../infrastructure/serialize-diagnostics.cpp | 2 +- 17 files changed, 37 insertions(+), 33 deletions(-) diff --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp index fac6e0418d163..34f29a5a953f1 100644 --- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp +++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp @@ -409,16 +409,16 @@ void ClangTidyDiagnosticConsumer::HandleDiagnostic( switch (DiagLevel) { case DiagnosticsEngine::Error: case DiagnosticsEngine::Fatal: - CheckName = "clang-diagnostic-error"; + CheckName = "clang-compiler-error"; break; case DiagnosticsEngine::Warning: - CheckName = "clang-diagnostic-warning"; + CheckName = "clang-compiler-warning"; break; case DiagnosticsEngine::Remark: - CheckName = "clang-diagnostic-remark"; + CheckName = "clang-compiler-remark"; break; default: - CheckName = "clang-diagnostic-unknown"; + CheckName = "clang-compiler-unknown"; break; } } diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 1553f461634d0..4354fbb464d4d 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -115,6 +115,10 @@ 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` by renaming ``clang-diagnostic-error`` + diagnostic to ``clang-compiler-error`` to better distinguish :program:`clang` + hard compiler errors from diagnostics coming from compiler flags. + New checks ^^^^^^^^^^ diff --git a/clang-tools-extra/test/clang-tidy/checkers/altera/struct-pack-align-invalid-decl-no-crash.cpp b/clang-tools-extra/test/clang-tidy/checkers/altera/struct-pack-align-invalid-decl-no-crash.cpp index 5688c03ca0e16..342adbc0910aa 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/altera/struct-pack-align-invalid-decl-no-crash.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/altera/struct-pack-align-invalid-decl-no-crash.cpp @@ -3,4 +3,4 @@ struct Foo { member; // no-crash }; -// CHECK-MESSAGES: :[[@LINE-2]]:3: error: a type specifier is required for all declarations [clang-diagnostic-error] +// CHECK-MESSAGES: :[[@LINE-2]]:3: error: a type specifier is required for all declarations [clang-compiler-error] diff --git a/clang-tools-extra/test/clang-tidy/checkers/altera/struct-pack-align-no-crash.cpp b/clang-tools-extra/test/clang-tidy/checkers/altera/struct-pack-align-no-crash.cpp index 660addcbe8039..e4e819e25444b 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/altera/struct-pack-align-no-crash.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/altera/struct-pack-align-no-crash.cpp @@ -3,5 +3,5 @@ struct A; struct B { A a; -// CHECK-MESSAGES: :[[@LINE-1]]:5: error: field has incomplete type 'A' [clang-diagnostic-error] +// CHECK-MESSAGES: :[[@LINE-1]]:5: error: field has incomplete type 'A' [clang-compiler-error] }; diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-unknown-expr.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-unknown-expr.cpp index d2641523750c9..2fcb490bea094 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-unknown-expr.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-unknown-expr.cpp @@ -1,9 +1,9 @@ // RUN: %check_clang_tidy -expect-clang-tidy-error %s bugprone-branch-clone %t int test_unknown_expression() { - if (unknown_expression_1) { // CHECK-MESSAGES: :[[@LINE]]:7: error: use of undeclared identifier 'unknown_expression_1' [clang-diagnostic-error] - function1(unknown_expression_2); // CHECK-MESSAGES: :[[@LINE]]:15: error: use of undeclared identifier 'unknown_expression_2' [clang-diagnostic-error] + if (unknown_expression_1) { // CHECK-MESSAGES: :[[@LINE]]:7: error: use of undeclared identifier 'unknown_expression_1' [clang-compiler-error] + function1(unknown_expression_2); // CHECK-MESSAGES: :[[@LINE]]:15: error: use of undeclared identifier 'unknown_expression_2' [clang-compiler-error] } else { - function2(unknown_expression_3); // CHECK-MESSAGES: :[[@LINE]]:15: error: use of undeclared identifier 'unknown_expression_3' [clang-diagnostic-error] + function2(unknown_expression_3); // CHECK-MESSAGES: :[[@LINE]]:15: error: use of undeclared identifier 'unknown_expression_3' [clang-compiler-error] } } diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-semicolon-fail.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-semicolon-fail.cpp index 45fa2262f6de7..0768682585873 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-semicolon-fail.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-semicolon-fail.cpp @@ -18,7 +18,7 @@ void f() { // CHECK-WERROR: :[[@LINE-1]]:11: warning: potentially unintended semicolon [bugprone-suspicious-semicolon] #if ERROR int a - // CHECK-ERROR: :[[@LINE-1]]:8: error: expected ';' at end of declaration [clang-diagnostic-error] + // CHECK-ERROR: :[[@LINE-1]]:8: error: expected ';' at end of declaration [clang-compiler-error] #elif WERROR int a; // CHECK-WERROR: :[[@LINE-1]]:7: error: unused variable 'a' [clang-diagnostic-unused-variable] diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp index 824431c1bf52f..966d314d2b6d0 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/init-variables.cpp @@ -131,7 +131,7 @@ void test_clang_diagnostic_error() { // CHECK-FIXES: {{^}} int a = 0;{{$}} UnknownType b; - // CHECK-MESSAGES: :[[@LINE-1]]:3: error: unknown type name 'UnknownType' [clang-diagnostic-error] + // CHECK-MESSAGES: :[[@LINE-1]]:3: error: unknown type name 'UnknownType' [clang-compiler-error] // CHECK-FIXES-NOT: {{^}} UnknownType b = 0;{{$}} } diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init-no-crash.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init-no-crash.cpp index 2e2964dda1daf..b4a063599fcf0 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init-no-crash.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init-no-crash.cpp @@ -2,7 +2,7 @@ struct X { X x; - // CHECK-MESSAGES: :[[@LINE-1]]:5: error: field has incomplete type 'X' [clang-diagnostic-error] + // CHECK-MESSAGES: :[[@LINE-1]]:5: error: field has incomplete type 'X' [clang-compiler-error] int a = 10; }; diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/misplaced-const-cxx17.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/misplaced-const-cxx17.cpp index 7816a091d7adb..c2a3a59504d70 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/misc/misplaced-const-cxx17.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/misc/misplaced-const-cxx17.cpp @@ -3,7 +3,7 @@ // This test previously would cause a failed assertion because the structured // binding declaration had no valid type associated with it. This ensures the // expected clang diagnostic is generated instead. -// CHECK-MESSAGES: :[[@LINE+1]]:6: error: decomposition declaration '[x]' requires an initializer [clang-diagnostic-error] +// CHECK-MESSAGES: :[[@LINE+1]]:6: error: decomposition declaration '[x]' requires an initializer [clang-compiler-error] auto [x]; struct S { int a; }; diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls-errors.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls-errors.cpp index 1c26a6961aad2..9b4fede68ace2 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls-errors.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls-errors.cpp @@ -8,5 +8,5 @@ using n::C; void f() { for (C *p : unknown()) {} - // CHECK-MESSAGES: :[[@LINE-1]]:15: error: use of undeclared identifier 'unknown' [clang-diagnostic-error] + // CHECK-MESSAGES: :[[@LINE-1]]:15: error: use of undeclared identifier 'unknown' [clang-compiler-error] } diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-noexcept-error.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-noexcept-error.cpp index 9a80b075d65ed..1065f0cb9a632 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-noexcept-error.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-noexcept-error.cpp @@ -3,4 +3,4 @@ // We're not interested in the check issuing a warning here, just making sure // clang-tidy doesn't assert. undefined_type doesThrow() throw(); -// CHECK-MESSAGES: :[[@LINE-1]]:1: error: unknown type name 'undefined_type' [clang-diagnostic-error] +// CHECK-MESSAGES: :[[@LINE-1]]:1: error: unknown type name 'undefined_type' [clang-compiler-error] diff --git a/clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-move-constructor.cpp b/clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-move-constructor.cpp index 4df0927b62af5..994e0a3509e06 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-move-constructor.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/performance/noexcept-move-constructor.cpp @@ -408,8 +408,8 @@ template <typename value_type> class set { #ifdef ENABLE_ERROR set(initializer_list<value_type> __l) {}; - // CHECK-MESSAGES-ERR: :[[@LINE-1]]:7: error: member 'initializer_list' cannot have template arguments [clang-diagnostic-error] - // CHECK-MESSAGES-ERR: :[[@LINE-2]]:36: error: expected ')' [clang-diagnostic-error] + // CHECK-MESSAGES-ERR: :[[@LINE-1]]:7: error: member 'initializer_list' cannot have template arguments [clang-compiler-error] + // CHECK-MESSAGES-ERR: :[[@LINE-2]]:36: error: expected ')' [clang-compiler-error] #endif }; diff --git a/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-value-param-incomplete-type.cpp b/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-value-param-incomplete-type.cpp index e46163a3e2315..f626093ff0e30 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-value-param-incomplete-type.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-value-param-incomplete-type.cpp @@ -4,6 +4,6 @@ // clang-tidy diagnostic about IncompleteType being expensive to copy. struct IncompleteType; void NegativeForIncompleteType(IncompleteType I) { - // CHECK-MESSAGES: [[@LINE-1]]:47: error: variable has incomplete type 'IncompleteType' [clang-diagnostic-error] + // CHECK-MESSAGES: [[@LINE-1]]:47: error: variable has incomplete type 'IncompleteType' [clang-compiler-error] } diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/isolate-declaration-no-infinite-loop.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/isolate-declaration-no-infinite-loop.cpp index 78a8ec738800e..908d0c57523b5 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/readability/isolate-declaration-no-infinite-loop.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/readability/isolate-declaration-no-infinite-loop.cpp @@ -3,5 +3,5 @@ int main(){ int a, b // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability - // CHECK-MESSAGES: [[@LINE-2]]:11: error: expected ';' at end of declaration [clang-diagnostic-error] + // CHECK-MESSAGES: [[@LINE-2]]:11: error: expected ';' at end of declaration [clang-compiler-error] } diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/diagnostic.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/diagnostic.cpp index a9d140bc9318e..5fb0d45784831 100644 --- a/clang-tools-extra/test/clang-tidy/infrastructure/diagnostic.cpp +++ b/clang-tools-extra/test/clang-tidy/infrastructure/diagnostic.cpp @@ -27,12 +27,12 @@ // RUN: clang-tidy -checks='-*,modernize-use-override,clang-diagnostic-macro-redefined,clang-diagnostic-literal-conversion' %s -- -DMACRO_FROM_COMMAND_LINE -std=c++20 -Wno-macro-redefined | FileCheck --check-prefix=CHECK7 -implicit-check-not='{{warning:|error:}}' %s // RUN: clang-tidy -checks='-*,modernize-use-override' %s -- -std=c++20 -DPR64602 -// CHECK1: error: no input files [clang-diagnostic-error] -// CHECK1: error: no such file or directory: '{{.*}}nonexistent.cpp' [clang-diagnostic-error] -// CHECK1: error: unable to handle compilation{{.*}} [clang-diagnostic-error] -// CHECK2: error: unknown argument: '-fan-unknown-option' [clang-diagnostic-error] -// CHECK3: error: unknown argument: '-fan-unknown-option' [clang-diagnostic-error] -// CHECK5: error: unknown argument: '-fan-option-from-compilation-database' [clang-diagnostic-error] +// CHECK1: error: no input files [clang-compiler-error] +// CHECK1: error: no such file or directory: '{{.*}}nonexistent.cpp' [clang-compiler-error] +// CHECK1: error: unable to handle compilation{{.*}} [clang-compiler-error] +// CHECK2: error: unknown argument: '-fan-unknown-option' [clang-compiler-error] +// CHECK3: error: unknown argument: '-fan-unknown-option' [clang-compiler-error] +// CHECK5: error: unknown argument: '-fan-option-from-compilation-database' [clang-compiler-error] // CHECK7: :[[@LINE+4]]:9: warning: implicit conversion from 'double' to 'int' changes value from 1.5 to 1 [clang-diagnostic-literal-conversion] // CHECK2: :[[@LINE+3]]:9: warning: implicit conversion from 'double' to 'int' changes value from 1.5 to 1 [clang-diagnostic-literal-conversion] @@ -52,7 +52,7 @@ class A { A(int) {} }; #ifdef COMPILATION_ERROR void f(int a) { &(a + 1); - // CHECK6: :[[@LINE-1]]:3: error: cannot take the address of an rvalue of type 'int' [clang-diagnostic-error] + // CHECK6: :[[@LINE-1]]:3: error: cannot take the address of an rvalue of type 'int' [clang-compiler-error] } #endif diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/export-diagnostics.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/export-diagnostics.cpp index ca2184332f9a4..fa41d471ab7a1 100644 --- a/clang-tools-extra/test/clang-tidy/infrastructure/export-diagnostics.cpp +++ b/clang-tools-extra/test/clang-tidy/infrastructure/export-diagnostics.cpp @@ -18,10 +18,10 @@ struct Foo { // CHECK-MESSAGES: {{^}}note: expanded from here{{$}} // CHECK-MESSAGES: -input.cpp:2:1: note: declare 'static' if the function is not intended to be used outside of this translation unit // CHECK-MESSAGES: -input.cpp:1:14: note: expanded from macro 'X' -// CHECK-MESSAGES: -input.cpp:3:7: error: 'a' declared as an array with a negative size [clang-diagnostic-error] +// CHECK-MESSAGES: -input.cpp:3:7: error: 'a' declared as an array with a negative size [clang-compiler-error] // CHECK-MESSAGES: -input.cpp:4:7: warning: zero size arrays are an extension [clang-diagnostic-zero-length-array] -// CHECK-MESSAGES: -input.cpp:6:11: error: unknown type name 'x' [clang-diagnostic-error] -// CHECK-MESSAGES: -input.cpp:8:3: error: a type specifier is required for all declarations [clang-diagnostic-error] +// CHECK-MESSAGES: -input.cpp:6:11: error: unknown type name 'x' [clang-compiler-error] +// CHECK-MESSAGES: -input.cpp:8:3: error: a type specifier is required for all declarations [clang-compiler-error] // CHECK-MESSAGES: -input.cpp:9:3: error: single-argument constructors must be marked explicit to avoid unintentional implicit conversions [google-explicit-constructor,-warnings-as-errors] // CHECK-YAML: --- @@ -56,7 +56,7 @@ struct Foo { // CHECK-YAML-NEXT: Replacements: [] // CHECK-YAML-NEXT: Level: Error // CHECK-YAML-NEXT: BuildDirectory: '{{.*}}' -// CHECK-YAML-NEXT: - DiagnosticName: clang-diagnostic-error +// CHECK-YAML-NEXT: - DiagnosticName: clang-compiler-error // CHECK-YAML-NEXT: DiagnosticMessage: // CHECK-YAML-NEXT: Message: '''a'' declared as an array with a negative size' // CHECK-YAML-NEXT: FilePath: '{{.*}}-input.cpp' @@ -80,7 +80,7 @@ struct Foo { // CHECK-YAML-NEXT: Length: 1 // CHECK-YAML-NEXT: Level: Warning // CHECK-YAML-NEXT: BuildDirectory: '{{.*}}' -// CHECK-YAML-NEXT: - DiagnosticName: clang-diagnostic-error +// CHECK-YAML-NEXT: - DiagnosticName: clang-compiler-error // CHECK-YAML-NEXT: DiagnosticMessage: // CHECK-YAML-NEXT: Message: 'unknown type name ''x''' // CHECK-YAML-NEXT: FilePath: '{{.*}}-input.cpp' @@ -88,7 +88,7 @@ struct Foo { // CHECK-YAML-NEXT: Replacements: [] // CHECK-YAML-NEXT: Level: Error // CHECK-YAML-NEXT: BuildDirectory: '{{.*}}' -// CHECK-YAML-NEXT: - DiagnosticName: clang-diagnostic-error +// CHECK-YAML-NEXT: - DiagnosticName: clang-compiler-error // CHECK-YAML-NEXT: DiagnosticMessage: // CHECK-YAML-NEXT: Message: a type specifier is required for all declarations // CHECK-YAML-NEXT: FilePath: '{{.*}}-input.cpp' diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/serialize-diagnostics.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/serialize-diagnostics.cpp index 8b0895af795a0..4bdcef722a3ed 100644 --- a/clang-tools-extra/test/clang-tidy/infrastructure/serialize-diagnostics.cpp +++ b/clang-tools-extra/test/clang-tidy/infrastructure/serialize-diagnostics.cpp @@ -1,3 +1,3 @@ // RUN: not clang-tidy -checks=-*,llvm-namespace-comment %s -- -serialize-diagnostics %t | FileCheck %s -// CHECK: :[[@LINE+1]]:12: error: expected ';' after struct [clang-diagnostic-error] +// CHECK: :[[@LINE+1]]:12: error: expected ';' after struct [clang-compiler-error] struct A {} >From c8e0fa4ccd4a50540d99aed4fe6feca15dfaaed0 Mon Sep 17 00:00:00 2001 From: Victor Baranov <bar.victor.2...@gmail.com> Date: Fri, 15 Aug 2025 23:37:30 +0300 Subject: [PATCH 2/2] [clang-tidy] add docs about "clang-compiler-error" --- clang-tools-extra/docs/clang-tidy/index.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/clang-tools-extra/docs/clang-tidy/index.rst b/clang-tools-extra/docs/clang-tidy/index.rst index e8ce903fcb076..c6d436bee9922 100644 --- a/clang-tools-extra/docs/clang-tidy/index.rst +++ b/clang-tools-extra/docs/clang-tidy/index.rst @@ -111,6 +111,13 @@ Diagnostics which have a corresponding warning option, are named ``-Wliteral-conversion`` will be reported with check name ``clang-diagnostic-literal-conversion``. +Clang compiler errors (such as syntax errors, semantic errors, or other failures +that prevent Clang from compiling the code) are reported with the check name +``clang-compiler-error``. These represent fundamental compilation failures that +must be fixed before :program:`clang-tidy` can perform its analysis. Unlike other +diagnostics, ``clang-compiler-error`` cannot be disabled, as :program:`clang-tidy` +requires valid code to function. + The ``-fix`` flag instructs :program:`clang-tidy` to fix found errors if supported by corresponding checks. _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits