Author: Amr Hesham Date: 2026-02-28T16:16:56+01:00 New Revision: 3d086f573dc410a11bd11b1cdfba1ed2b80a95cb
URL: https://github.com/llvm/llvm-project/commit/3d086f573dc410a11bd11b1cdfba1ed2b80a95cb DIFF: https://github.com/llvm/llvm-project/commit/3d086f573dc410a11bd11b1cdfba1ed2b80a95cb.diff LOG: [CIR] Implement ImplicitValueInitExpr for ComplexType (#183836) Implement ImplicitValueInitExpr for ComplexType Added: Modified: clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp clang/test/CIR/CodeGen/implicit-value-init-expr.cpp Removed: ################################################################################ diff --git a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp index 64b9aa369e1d3..3a9f68ece29c9 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp @@ -223,9 +223,9 @@ class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> { return builder.getNullValue(complexTy, loc); } mlir::Value VisitImplicitValueInitExpr(ImplicitValueInitExpr *e) { - cgf.cgm.errorNYI(e->getExprLoc(), - "ComplexExprEmitter VisitImplicitValueInitExpr"); - return {}; + mlir::Location loc = cgf.getLoc(e->getExprLoc()); + mlir::Type complexTy = cgf.convertType(e->getType()); + return builder.getNullValue(complexTy, loc); } struct BinOpInfo { diff --git a/clang/test/CIR/CodeGen/implicit-value-init-expr.cpp b/clang/test/CIR/CodeGen/implicit-value-init-expr.cpp index ad9f430411fba..3babc7fb6e763 100644 --- a/clang/test/CIR/CodeGen/implicit-value-init-expr.cpp +++ b/clang/test/CIR/CodeGen/implicit-value-init-expr.cpp @@ -33,3 +33,28 @@ void test(void *p) { // OGCG-NEXT: %[[P1:.*]] = load ptr, ptr %[[P]], align 8 // OGCG-NEXT: store i32 0, ptr %[[P1]], align 4 // OGCG-NEXT: ret void + +void test_complex(void *p) { new (p) int _Complex(); } + +// CIR: cir.func{{.*}} @_Z12test_complexPv +// CIR: %[[P_ADDR:.*]] = cir.alloca !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>, ["p", init] +// CIR: cir.store %[[ARG_0:.*]], %[[P_ADDR:.*]] : !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>> +// CIR: %[[TMP_P:.*]] = cir.load {{.*}} %[[P_ADDR]] : !cir.ptr<!cir.ptr<!void>>, !cir.ptr<!void> +// CIR: %[[P_COMPLEX:.*]] = cir.cast bitcast %[[TMP_P:.*]] : !cir.ptr<!void> -> !cir.ptr<!cir.complex<!s32i>> +// CIR: %[[CONST_0:.*]] = cir.const #cir.zero : !cir.complex<!s32i> +// CIR: cir.store {{.*}} %[[CONST_0]], %[[P_COMPLEX]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>> + +// LLVM: define{{.*}} void @_Z12test_complexPv(ptr{{.*}} %[[ARG_0:.*]]) +// LLVM: %[[P_ADDR:.*]] = alloca ptr +// LLVM: store ptr %[[ARG_0]], ptr %[[P_ADDR]], align 8 +// LLVM: %[[TMP_P:.*]] = load ptr, ptr %[[P_ADDR]], align 8 +// LLVM: store { i32, i32 } zeroinitializer, ptr %[[TMP_P]], align 4 + +// OGCG: define{{.*}} void @_Z12test_complexPv(ptr{{.*}} %[[ARG_0:.*]]) +// OGCG: %[[P_ADDR:.*]] = alloca ptr, align 8 +// OGCG: store ptr %[[ARG_0]], ptr %[[P_ADDR]], align 8 +// OGCG: %[[TMP_P:.*]] = load ptr, ptr %[[P_ADDR]], align 8 +// OGCG: %[[P_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[TMP_P]], i32 0, i32 0 +// OGCG: %[[P_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[TMP_P]], i32 0, i32 1 +// OGCG: store i32 0, ptr %[[P_REAL_PTR]], align 4 +// OGCG: store i32 0, ptr %[[P_IMAG_PTR]], align 4 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
