[clang] [Clang][Sema] Add Diagnostic for using matrix logical on non HLSL targets (PR #223252)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Sep 13 08:14:12 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Amr Hesham (AmrDeveloper)
<details>
<summary>Changes</summary>
Make Clang emit an error message instead of crashing when using matrix logical operations on non-HLSL targets.
Issue #<!-- -->222381
---
Full diff: https://github.com/llvm/llvm-project/pull/223252.diff
4 Files Affected:
- (modified) clang/docs/ReleaseNotes.md (+2)
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+3)
- (modified) clang/lib/Sema/SemaExpr.cpp (+1-1)
- (modified) clang/test/SemaCXX/matrix-type.cpp (+6)
``````````diff
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}}
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/223252
More information about the cfe-commits
mailing list