diff --git a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp index 38ab983f6955..9c5708067402 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp @@ -864,10 +864,16 @@ mlir::Value ComplexExprEmitter::VisitInitListExpr(InitListExpr *E) { if (E->getNumInits() == 1) return Visit(E->getInit(0)); - // Empty init list initializes to null assert(E->getNumInits() == 0 && "Unexpected number of inits"); - QualType Ty = E->getType()->castAs()->getElementType(); - return Builder.getZero(CGF.getLoc(E->getExprLoc()), CGF.convertType(Ty)); + mlir::Location loc = CGF.getLoc(E->getExprLoc()); + QualType complexElemTy = + E->getType()->castAs()->getElementType(); + mlir::Type complexElemLLVMTy = CGF.convertType(complexElemTy); + mlir::TypedAttr defaultValue = Builder.getZeroInitAttr(complexElemLLVMTy); + auto complexTy = cir::ComplexType::get(complexElemLLVMTy); + auto complexAttr = + cir::ComplexAttr::get(complexTy, defaultValue, defaultValue); + return Builder.create(loc, complexAttr); } mlir::Value CIRGenFunction::emitPromotedComplexExpr(const Expr *E, diff --git a/clang/test/CIR/CodeGen/complex.c b/clang/test/CIR/CodeGen/complex.c index 27924f813394..9b19b39c578f 100644 --- a/clang/test/CIR/CodeGen/complex.c +++ b/clang/test/CIR/CodeGen/complex.c @@ -335,3 +335,7 @@ void extract_imag() { // LLVM: %{{.+}} = load double, ptr getelementptr inbounds nuw (i8, ptr @c, i64 8), align 8 // LLVM: %{{.+}} = load i32, ptr getelementptr inbounds nuw (i8, ptr @ci, i64 4), align 4 // LLVM: } + +void complex_with_empty_init() { int _Complex c = {}; } + +// CHECK: {{.*}} = cir.const #cir.complex<#cir.int<0> : !s32i, #cir.int<0> : !s32i> : !cir.complex