[clang] fa189b0 - [clang][bytecode] Reject matrix lvalue-to-rvalue casts in non-HLSL (#227305)

via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 30 04:45:55 PDT 2026


Author: Timm Baeder
Date: 2026-09-30T13:45:46+02:00
New Revision: fa189b0b2a0324a56e41fb8908cfee1211fa4244

URL: https://github.com/llvm/llvm-project/commit/fa189b0b2a0324a56e41fb8908cfee1211fa4244
DIFF: https://github.com/llvm/llvm-project/commit/fa189b0b2a0324a56e41fb8908cfee1211fa4244.diff

LOG: [clang][bytecode] Reject matrix lvalue-to-rvalue casts in non-HLSL (#227305)

To fix test/CodeGen/AArch64/abi-classify-return-types.c.

The code path in the existing tests in
`test/SemaHLSL/Types/BuiltinMatrix/MatrixConstantExpr.hlsl` don't go
though `CheckLiteralType()`, so aren't rejected.

Added: 
    clang/test/AST/ByteCode/matrix.c

Modified: 
    clang/lib/AST/ByteCode/Compiler.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 8ac06578bf54b..dcc00c0e14945 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -458,6 +458,11 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *E) {
 
   switch (E->getCastKind()) {
   case CK_LValueToRValue: {
+    // This *could* work I guess, but the current interpreter rejects (via
+    // checkLiteralType).
+    if (!Ctx.getLangOpts().HLSL && E->getType()->isConstantMatrixType())
+      return false;
+
     if (ToLValue && E->getType()->isPointerType()) {
       assert(!DiscardResult);
       if (!this->visit(SubExpr))

diff  --git a/clang/test/AST/ByteCode/matrix.c b/clang/test/AST/ByteCode/matrix.c
new file mode 100644
index 0000000000000..1ca513f4a0195
--- /dev/null
+++ b/clang/test/AST/ByteCode/matrix.c
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -fenable-matrix %s -verify -fexperimental-new-constant-interpreter
+// RUN: %clang_cc1 -fenable-matrix %s -verify
+
+typedef float fx2x2_t __attribute__((matrix_type(2, 2)));
+fx2x2_t ret_matrix() { return (fx2x2_t){1.0f, 2.0f, 3.0f, 4.0f}; } // expected-warning {{excess elements in matrix initializer}}


        


More information about the cfe-commits mailing list