Skip to content

Commit 44baef9

Browse files
authored
[CIR] Use ZeroAttr as zeroinitializer for ComplexType (#148033)
Use ZeroAttr as a zeroinitializer for ComplexType, similar to what we did in CXXScalarValueInitExpr #141365
1 parent 3ab95e4 commit 44baef9

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,8 @@ mlir::Value ComplexExprEmitter::VisitInitListExpr(const InitListExpr *e) {
291291
}
292292

293293
assert(e->getNumInits() == 0 && "Unexpected number of inits");
294-
QualType complexElemTy =
295-
e->getType()->castAs<clang::ComplexType>()->getElementType();
296-
mlir::Type complexElemLLVMTy = cgf.convertType(complexElemTy);
297-
mlir::TypedAttr defaultValue = builder.getZeroInitAttr(complexElemLLVMTy);
298-
auto complexAttr = cir::ConstComplexAttr::get(defaultValue, defaultValue);
299-
return builder.create<cir::ConstantOp>(loc, complexAttr);
294+
mlir::Type complexTy = cgf.convertType(e->getType());
295+
return builder.getNullValue(complexTy, loc);
300296
}
301297

302298
mlir::Value

clang/test/CIR/CodeGen/complex.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ float _Complex cf2 = { 1.0f, 2.0f };
3131
void foo() { int _Complex c = {}; }
3232

3333
// CIR: %[[INIT:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["c", init]
34-
// CIR: %[[COMPLEX:.*]] = cir.const #cir.const_complex<#cir.int<0> : !s32i, #cir.int<0> : !s32i> : !cir.complex<!s32i>
34+
// CIR: %[[COMPLEX:.*]] = cir.const #cir.zero : !cir.complex<!s32i>
3535
// CIR: cir.store{{.*}} %[[COMPLEX]], %[[INIT]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>
3636

3737
// LLVM: %[[INIT:.*]] = alloca { i32, i32 }, i64 1, align 4
@@ -741,7 +741,7 @@ void foo29() {
741741
}
742742

743743
// CIR: %[[INIT:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["a", init]
744-
// CIR: %[[COMPLEX:.*]] = cir.const #cir.const_complex<#cir.int<0> : !s32i, #cir.int<0> : !s32i> : !cir.complex<!s32i>
744+
// CIR: %[[COMPLEX:.*]] = cir.const #cir.zero : !cir.complex<!s32i>
745745
// CIR: cir.store{{.*}} %[[COMPLEX]], %[[INIT]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>
746746

747747
// LLVM: %[[INIT:.*]] = alloca { i32, i32 }, i64 1, align 4

0 commit comments

Comments
 (0)