https://github.com/AmrDeveloper created 
https://github.com/llvm/llvm-project/pull/223252

Make Clang emit an error message instead of crashing when using matrix logical 
operations on non-HLSL targets.

Issue #222381

>From e356858b07fc9018861c8a30244e649666ed6f8a Mon Sep 17 00:00:00 2001
From: Amr Hesham <[email protected]>
Date: Sun, 13 Sep 2026 12:44:05 +0200
Subject: [PATCH] [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 72b7f9116c3f9..92824085626c0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -14357,4 +14357,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}}
+}

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to