[clang] [Clang][Sema] Add Diagnostic for using matrix logical on non HLSL targets (PR #223252)
Amr Hesham via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 15 08:47:31 PDT 2026
https://github.com/AmrDeveloper updated https://github.com/llvm/llvm-project/pull/223252
>From bc49d28221f51136606c4a9bf7fa3cc4ae5f4875 Mon Sep 17 00:00:00 2001
From: Amr Hesham <amr96 at programmer.net>
Date: Sun, 13 Sep 2026 12:44:05 +0200
Subject: [PATCH 1/3] [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 d719114b5cff6..48b4e3440892f 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -497,6 +497,8 @@ features cannot lower the translation-unit ABI level;
inline-defined friend function shares the name of a non-static class
member variable. (#GH221190)
+- 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 e221e5d53bb0836439c4cf631ffaf9f38ccaac19 Mon Sep 17 00:00:00 2001
From: Amr Hesham <amr96 at programmer.net>
Date: Mon, 14 Sep 2026 17:50:54 +0200
Subject: [PATCH 2/3] Update the diagnostic message
---
clang/include/clang/Basic/DiagnosticSemaKinds.td | 6 +++---
clang/lib/Sema/SemaExpr.cpp | 2 +-
clang/test/SemaCXX/matrix-type.cpp | 2 +-
3 files changed, 5 insertions(+), 5 deletions(-)
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}}
}
>From 4b8dd9e683f0b83be716a3efe36ac7f152069cb0 Mon Sep 17 00:00:00 2001
From: Amr Hesham <amr96 at programmer.net>
Date: Mon, 14 Sep 2026 17:52:49 +0200
Subject: [PATCH 3/3] Update releasenote
---
clang/docs/ReleaseNotes.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 48b4e3440892f..f37bcda179c95 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -497,7 +497,7 @@ features cannot lower the translation-unit ABI level;
inline-defined friend function shares the name of a non-static class
member variable. (#GH221190)
-- Clang now diagnoses matrix logical operations on unsupported targets. (GH222381)
+- Clang now diagnoses matrix logical operations are only supported for HLSL. (GH222381)
### Improvements to Clang's time-trace
More information about the cfe-commits
mailing list