https://github.com/Men-cotton created https://github.com/llvm/llvm-project/pull/182817
In `ScalarExprEmitter::VisitCastExpr`, guard `CK_VectorSplat` so `cir::VecSplatOp` is only created for a valid scalar value. Update clang/test/CIR/CodeGenHLSL/matrix-element-expr-load.hlsl to use `-verify` with expected CIR NYI diagnostics. >From 11e6a210f2ee64e6f4a165c73ccdf48fedfc68d8 Mon Sep 17 00:00:00 2001 From: mencotton <[email protected]> Date: Mon, 23 Feb 2026 17:29:17 +0900 Subject: [PATCH] [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 d523aa2fdb737..e5f17d720ee86 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 279075a6dab60..f3c6d1fefd1f0 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; } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
