Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ComplexType>()->getElementType();
return Builder.getZero(CGF.getLoc(E->getExprLoc()), CGF.convertType(Ty));
mlir::Location loc = CGF.getLoc(E->getExprLoc());
QualType complexElemTy =
E->getType()->castAs<clang::ComplexType>()->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<cir::ConstantOp>(loc, complexAttr);
}

mlir::Value CIRGenFunction::emitPromotedComplexExpr(const Expr *E,
Expand Down
4 changes: 4 additions & 0 deletions clang/test/CIR/CodeGen/complex.c
Original file line number Diff line number Diff line change
Expand Up @@ -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<!s32i>
Loading