https://github.com/AmrDeveloper updated https://github.com/llvm/llvm-project/pull/147147
>From bb6602546c35f6a25a4a64141ec9d1edff65dd95 Mon Sep 17 00:00:00 2001 From: AmrDeveloper <am...@programmer.net> Date: Sat, 5 Jul 2025 15:56:31 +0200 Subject: [PATCH 1/2] [CIR] Implement functional cast to ComplexType --- clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp | 19 ++++++++++++++++++- clang/test/CIR/CodeGen/complex.cpp | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp index c000b225f31f3..82b6a74a54b6c 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp @@ -43,6 +43,7 @@ class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> { mlir::Value VisitBinAssign(const BinaryOperator *e); mlir::Value VisitBinComma(const BinaryOperator *e); mlir::Value VisitCallExpr(const CallExpr *e); + mlir::Value VisitCastExpr(CastExpr *e); mlir::Value VisitChooseExpr(ChooseExpr *e); mlir::Value VisitDeclRefExpr(DeclRefExpr *e); mlir::Value VisitGenericSelectionExpr(GenericSelectionExpr *e); @@ -83,12 +84,13 @@ LValue ComplexExprEmitter::emitBinAssignLValue(const BinaryOperator *e, mlir::Value ComplexExprEmitter::emitCast(CastKind ck, Expr *op, QualType destTy) { switch (ck) { + case CK_NoOp: case CK_LValueToRValue: return Visit(op); default: - cgf.cgm.errorNYI("ComplexType Cast"); break; } + cgf.cgm.errorNYI("ComplexType Cast"); return {}; } @@ -157,6 +159,21 @@ mlir::Value ComplexExprEmitter::VisitCallExpr(const CallExpr *e) { return cgf.emitCallExpr(e).getValue(); } +mlir::Value ComplexExprEmitter::VisitCastExpr(CastExpr *e) { + if (const auto *ece = dyn_cast<ExplicitCastExpr>(e)) { + // Bind VLAs in the cast type. + if (ece->getType()->isVariablyModifiedType()) { + cgf.cgm.errorNYI("VisitCastExpr Bind VLAs in the cast type"); + return {}; + } + } + + if (e->changesVolatileQualification()) + return emitLoadOfLValue(e); + + return emitCast(e->getCastKind(), e->getSubExpr(), e->getType()); +} + mlir::Value ComplexExprEmitter::VisitChooseExpr(ChooseExpr *e) { return Visit(e->getChosenSubExpr()); } diff --git a/clang/test/CIR/CodeGen/complex.cpp b/clang/test/CIR/CodeGen/complex.cpp index 09e0ca03aa540..5d75f0e8a77c4 100644 --- a/clang/test/CIR/CodeGen/complex.cpp +++ b/clang/test/CIR/CodeGen/complex.cpp @@ -654,3 +654,21 @@ void foo26(int _Complex* a) { // OGCG: %[[B_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_B]], i32 0, i32 1 // OGCG: store i32 %[[A_REAL]], ptr %[[B_REAL_PTR]], align 4 // OGCG: store i32 %[[A_IMAG]], ptr %[[B_IMAG_PTR]], align 4 + +void foo29() { + using IntComplex = int _Complex; + int _Complex a = IntComplex{}; +} + +// CIR: %[[INIT:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["a", init] +// CIR: %[[COMPLEX:.*]] = cir.const #cir.const_complex<#cir.int<0> : !s32i, #cir.int<0> : !s32i> : !cir.complex<!s32i> +// CIR: cir.store align(4) %[[COMPLEX]], %[[INIT]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>> + +// LLVM: %[[INIT:.*]] = alloca { i32, i32 }, i64 1, align 4 +// LLVM: store { i32, i32 } zeroinitializer, ptr %[[INIT]], align 4 + +// OGCG: %[[INIT:.*]] = alloca { i32, i32 }, align 4 +// OGCG: %[[INIT_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[INIT]], i32 0, i32 0 +// OGCG: %[[INIT_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[INIT]], i32 0, i32 1 +// OGCG: store i32 0, ptr %[[INIT_REAL_PTR]], align 4 +// OGCG: store i32 0, ptr %[[INIT_IMAG_PTR]], align 4 >From 79fb67dca19c4a5b1b1fb1ecd4201bff7ae183f4 Mon Sep 17 00:00:00 2001 From: AmrDeveloper <am...@programmer.net> Date: Sun, 6 Jul 2025 17:36:26 +0200 Subject: [PATCH 2/2] Replace align value with regex --- clang/test/CIR/CodeGen/complex.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/CIR/CodeGen/complex.cpp b/clang/test/CIR/CodeGen/complex.cpp index 5d75f0e8a77c4..25b00788ff016 100644 --- a/clang/test/CIR/CodeGen/complex.cpp +++ b/clang/test/CIR/CodeGen/complex.cpp @@ -662,7 +662,7 @@ void foo29() { // CIR: %[[INIT:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["a", init] // CIR: %[[COMPLEX:.*]] = cir.const #cir.const_complex<#cir.int<0> : !s32i, #cir.int<0> : !s32i> : !cir.complex<!s32i> -// CIR: cir.store align(4) %[[COMPLEX]], %[[INIT]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>> +// CIR: cir.store{{.*}} %[[COMPLEX]], %[[INIT]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>> // LLVM: %[[INIT:.*]] = alloca { i32, i32 }, i64 1, align 4 // LLVM: store { i32, i32 } zeroinitializer, ptr %[[INIT]], align 4 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits