[clang] 44baef9 - [CIR] Use ZeroAttr as zeroinitializer for ComplexType (#148033)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 11 10:57:25 PDT 2025
Author: Amr Hesham
Date: 2025-07-11T19:57:21+02:00
New Revision: 44baef98431e21309a4b364fa7b3704a7b687ad6
URL: https://github.com/llvm/llvm-project/commit/44baef98431e21309a4b364fa7b3704a7b687ad6
DIFF: https://github.com/llvm/llvm-project/commit/44baef98431e21309a4b364fa7b3704a7b687ad6.diff
LOG: [CIR] Use ZeroAttr as zeroinitializer for ComplexType (#148033)
Use ZeroAttr as a zeroinitializer for ComplexType, similar to what we
did in CXXScalarValueInitExpr
https://github.com/llvm/llvm-project/issues/141365
Added:
Modified:
clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
clang/test/CIR/CodeGen/complex.cpp
Removed:
################################################################################
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
index 24a9bf13e1880..cb83691b4452d 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
@@ -291,12 +291,8 @@ mlir::Value ComplexExprEmitter::VisitInitListExpr(const InitListExpr *e) {
}
assert(e->getNumInits() == 0 && "Unexpected number of inits");
- QualType complexElemTy =
- e->getType()->castAs<clang::ComplexType>()->getElementType();
- mlir::Type complexElemLLVMTy = cgf.convertType(complexElemTy);
- mlir::TypedAttr defaultValue = builder.getZeroInitAttr(complexElemLLVMTy);
- auto complexAttr = cir::ConstComplexAttr::get(defaultValue, defaultValue);
- return builder.create<cir::ConstantOp>(loc, complexAttr);
+ mlir::Type complexTy = cgf.convertType(e->getType());
+ return builder.getNullValue(complexTy, loc);
}
mlir::Value
diff --git a/clang/test/CIR/CodeGen/complex.cpp b/clang/test/CIR/CodeGen/complex.cpp
index 6e7e889df146f..f33909150044e 100644
--- a/clang/test/CIR/CodeGen/complex.cpp
+++ b/clang/test/CIR/CodeGen/complex.cpp
@@ -31,7 +31,7 @@ float _Complex cf2 = { 1.0f, 2.0f };
void foo() { int _Complex c = {}; }
// CIR: %[[INIT:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["c", init]
-// CIR: %[[COMPLEX:.*]] = cir.const #cir.const_complex<#cir.int<0> : !s32i, #cir.int<0> : !s32i> : !cir.complex<!s32i>
+// CIR: %[[COMPLEX:.*]] = cir.const #cir.zero : !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
@@ -741,7 +741,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: %[[COMPLEX:.*]] = cir.const #cir.zero : !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
More information about the cfe-commits
mailing list