From 11e6a210f2ee64e6f4a165c73ccdf48fedfc68d8 Mon Sep 17 00:00:00 2001 From: mencotton Date: Mon, 23 Feb 2026 17:29:17 +0900 Subject: [PATCH 1/3] [CIR] Guard CK_VectorSplat on failed scalar emission --- clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp | 5 ++++- .../CIR/CodeGenHLSL/matrix-element-expr-load.hlsl | 12 ++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp index d523aa2fdb7371..e5f17d720ee86f 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp @@ -2371,9 +2371,12 @@ mlir::Value ScalarExprEmitter::VisitCastExpr(CastExpr *ce) { case CK_VectorSplat: { // Create a vector object and fill all elements with the same scalar value. assert(destTy->isVectorType() && "CK_VectorSplat to non-vector type"); + mlir::Value scalar = Visit(subExpr); + if (!scalar) + return {}; return cir::VecSplatOp::create(builder, cgf.getLoc(subExpr->getSourceRange()), - cgf.convertType(destTy), Visit(subExpr)); + cgf.convertType(destTy), scalar); } case CK_FunctionToPointerDecay: return cgf.emitLValue(subExpr).getPointer(); diff --git a/clang/test/CIR/CodeGenHLSL/matrix-element-expr-load.hlsl b/clang/test/CIR/CodeGenHLSL/matrix-element-expr-load.hlsl index 279075a6dab604..f3c6d1fefd1f0e 100644 --- a/clang/test/CIR/CodeGenHLSL/matrix-element-expr-load.hlsl +++ b/clang/test/CIR/CodeGenHLSL/matrix-element-expr-load.hlsl @@ -1,8 +1,8 @@ -// RUN: not %clang_cc1 -x hlsl -finclude-default-header -triple spirv-unknown-vulkan-compute %s \ -// RUN: -fclangir -emit-cir -disable-llvm-passes 2>&1 | FileCheck %s +// RUN: %clang_cc1 -x hlsl -finclude-default-header -triple spirv-unknown-vulkan-compute %s \ +// RUN: -fclangir -emit-cir -disable-llvm-passes -verify -// CHECK: ClangIR code gen Not Yet Implemented: processing of type: ConstantMatrix -float1 test_zero_indexed(float2x2 M) { - // CHECK: ClangIR code gen Not Yet Implemented: ScalarExprEmitter: matrix element - return M._m00; +// expected-error@*:* {{ClangIR code gen Not Yet Implemented: processing of type: ConstantMatrix}} +float1 test_zero_indexed(float2x2 M) { + // expected-error@+1 {{ClangIR code gen Not Yet Implemented: ScalarExprEmitter: matrix element}} + return M._m00; } From a19edee38f7c946d37a568aa131faa46055da8f9 Mon Sep 17 00:00:00 2001 From: mencotton Date: Wed, 25 Feb 2026 20:13:40 +0900 Subject: [PATCH 2/3] revert the change on CIRGenExprScalar.cpp --- clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp index 5b4eb7b923e557..c74fbbad488d59 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp @@ -2379,12 +2379,9 @@ mlir::Value ScalarExprEmitter::VisitCastExpr(CastExpr *ce) { case CK_VectorSplat: { // Create a vector object and fill all elements with the same scalar value. assert(destTy->isVectorType() && "CK_VectorSplat to non-vector type"); - mlir::Value scalar = Visit(subExpr); - if (!scalar) - return {}; return cir::VecSplatOp::create(builder, cgf.getLoc(subExpr->getSourceRange()), - cgf.convertType(destTy), scalar); + cgf.convertType(destTy), Visit(subExpr)); } case CK_FunctionToPointerDecay: return cgf.emitLValue(subExpr).getPointer(); From 3272bd46192c7938ed434c200daaa9d890ecc168 Mon Sep 17 00:00:00 2001 From: mencotton Date: Wed, 25 Feb 2026 20:42:46 +0900 Subject: [PATCH 3/3] add an error match --- clang/test/CIR/CodeGenHLSL/matrix-element-expr-load.hlsl | 1 + 1 file changed, 1 insertion(+) diff --git a/clang/test/CIR/CodeGenHLSL/matrix-element-expr-load.hlsl b/clang/test/CIR/CodeGenHLSL/matrix-element-expr-load.hlsl index 32fba67df9f620..68ad4f94a248d2 100644 --- a/clang/test/CIR/CodeGenHLSL/matrix-element-expr-load.hlsl +++ b/clang/test/CIR/CodeGenHLSL/matrix-element-expr-load.hlsl @@ -2,6 +2,7 @@ // RUN: -fclangir -emit-cir -disable-llvm-passes -verify // expected-error@*:* {{ClangIR code gen Not Yet Implemented: processing of type: ConstantMatrix}} +// expected-error@*:* {{ClangIR code gen Not Yet Implemented: Matrix type conversion}} float test_zero_indexed(float2x2 M) { // expected-error@+1 {{ClangIR code gen Not Yet Implemented: ScalarExprEmitter: matrix element}} return M._m00;