https://github.com/AmrDeveloper updated https://github.com/llvm/llvm-project/pull/223252
>From dde70112043db2922fc9f2200c197ac2c5d5251c Mon Sep 17 00:00:00 2001 From: Amr Hesham <[email protected]> Date: Sun, 13 Sep 2026 12:44:05 +0200 Subject: [PATCH 1/2] [Clang][Sema] Add Diagnostic for using matrix logical on non HLSL targets --- clang/docs/ReleaseNotes.md | 2 ++ clang/include/clang/Basic/DiagnosticSemaKinds.td | 3 +++ clang/lib/Sema/SemaExpr.cpp | 2 +- clang/test/SemaCXX/matrix-type.cpp | 6 ++++++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index 043a0ddae2a6c..8c4296c506b9f 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -493,6 +493,8 @@ features cannot lower the translation-unit ABI level; `operator delete`, since such a delete expression never invokes the destructor. (#GH65524) +- Clang now diagnoses matrix logical operations on unsupported targets. (GH222381) + ### Improvements to Clang's time-trace ### Improvements to Coverage Mapping diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 0e09f7cfba7e1..bf4eee539021d 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -14350,4 +14350,7 @@ def err_cuda_device_kernel_launch_not_supported def err_cuda_device_kernel_launch_require_rdc : Error<"kernel launch from __device__ or __global__ function requires " "relocatable device code (i.e. requires -fgpu-rdc)">; + +def err_matrix_logical_operations_unsupported : Error< + "matix logical operations are not supported on the current target">; } // end of sema component. diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 7186aa86fae1e..0faa34a3b5196 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -13866,7 +13866,7 @@ QualType Sema::CheckMatrixLogicalOperands(ExprResult &LHS, ExprResult &RHS, BinaryOperatorKind Opc) { if (!getLangOpts().HLSL) { - assert(false && "Logical operands are not supported in C\\C++"); + SemaRef.Diag(Loc, diag::err_matrix_logical_operations_unsupported); return QualType(); } diff --git a/clang/test/SemaCXX/matrix-type.cpp b/clang/test/SemaCXX/matrix-type.cpp index 0f9bff868adbe..87ecdcbb35af8 100644 --- a/clang/test/SemaCXX/matrix-type.cpp +++ b/clang/test/SemaCXX/matrix-type.cpp @@ -39,3 +39,9 @@ void matrix_unsupported_bit_int() { using m6 = _BitInt(64) __attribute__((matrix_type(4, 4))); using m7 = _BitInt(256) __attribute__((matrix_type(4, 4))); } + +void matrix_logical_op() { + matrix_int_t a; + matrix_int_t b; + matrix_int_t c = a && b; // expected-error{{matix logical operations are not supported on the current target}} +} >From c63a88947b1b0704a1a15a3961288b6a1bc1ddf7 Mon Sep 17 00:00:00 2001 From: Amr Hesham <[email protected]> Date: Mon, 14 Sep 2026 17:50:54 +0200 Subject: [PATCH 2/2] Update the diagnostic message --- clang/docs/ReleaseNotes.md | 2 +- clang/include/clang/Basic/DiagnosticSemaKinds.td | 6 +++--- clang/lib/Sema/SemaExpr.cpp | 2 +- clang/test/SemaCXX/matrix-type.cpp | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index 8c4296c506b9f..78652b625d2e1 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -493,7 +493,7 @@ features cannot lower the translation-unit ABI level; `operator delete`, since such a delete expression never invokes the destructor. (#GH65524) -- Clang now diagnoses matrix logical operations on unsupported targets. (GH222381) +- Clang now diagnoses matrix logical operations are only support for HLSL. (GH222381) ### Improvements to Clang's time-trace diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index bf4eee539021d..fa9b748bda39f 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -13831,6 +13831,9 @@ def err_hlsl_gathercmp_invalid_component def err_hlsl_resource_member_array_access_not_constant : Error<"index for struct array inside cbuffer that contains resources must be a constant integer expression">; +def err_matrix_logical_operations_supported_for_hlsl : Error< + "matix logical operations are only supported for HLSL">; + // Layout randomization diagnostics. def err_non_designated_init_used : Error< "a randomized struct can only be initialized with a designated initializer">; @@ -14350,7 +14353,4 @@ def err_cuda_device_kernel_launch_not_supported def err_cuda_device_kernel_launch_require_rdc : Error<"kernel launch from __device__ or __global__ function requires " "relocatable device code (i.e. requires -fgpu-rdc)">; - -def err_matrix_logical_operations_unsupported : Error< - "matix logical operations are not supported on the current target">; } // end of sema component. diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 0faa34a3b5196..7444fe0e71fd8 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -13866,7 +13866,7 @@ QualType Sema::CheckMatrixLogicalOperands(ExprResult &LHS, ExprResult &RHS, BinaryOperatorKind Opc) { if (!getLangOpts().HLSL) { - SemaRef.Diag(Loc, diag::err_matrix_logical_operations_unsupported); + SemaRef.Diag(Loc, diag::err_matrix_logical_operations_supported_for_hlsl); return QualType(); } diff --git a/clang/test/SemaCXX/matrix-type.cpp b/clang/test/SemaCXX/matrix-type.cpp index 87ecdcbb35af8..3b3b22dea741a 100644 --- a/clang/test/SemaCXX/matrix-type.cpp +++ b/clang/test/SemaCXX/matrix-type.cpp @@ -43,5 +43,5 @@ void matrix_unsupported_bit_int() { void matrix_logical_op() { matrix_int_t a; matrix_int_t b; - matrix_int_t c = a && b; // expected-error{{matix logical operations are not supported on the current target}} + matrix_int_t c = a && b; // expected-error{{matix logical operations are only supported for HLSL}} } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
