[clang] [CIR] Use ZeroAttr as zeroinitializer for ComplexType (PR #148033)
Amr Hesham via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 11 09:52:15 PDT 2025
https://github.com/AmrDeveloper updated https://github.com/llvm/llvm-project/pull/148033
>From 0f584ac188b3c6eb9cc61ffc44464741360ff9c0 Mon Sep 17 00:00:00 2001
From: AmrDeveloper <amr96 at programmer.net>
Date: Thu, 10 Jul 2025 20:52:04 +0200
Subject: [PATCH 1/2] [CIR] Use ZeroAttr as zeroinitializer for ComplexType
---
clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp | 8 ++------
clang/test/CIR/CodeGen/complex.cpp | 4 ++--
2 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
index 24a9bf13e1880..9564069901f0a 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 compleTy = cgf.convertType(e->getType());
+ return builder.getNullValue(compleTy, 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
>From dcc220191a686799776e58e0f3af24c9660203c6 Mon Sep 17 00:00:00 2001
From: AmrDeveloper <amr96 at programmer.net>
Date: Fri, 11 Jul 2025 18:51:49 +0200
Subject: [PATCH 2/2] Fix typo
---
clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
index 9564069901f0a..cb83691b4452d 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
@@ -291,8 +291,8 @@ mlir::Value ComplexExprEmitter::VisitInitListExpr(const InitListExpr *e) {
}
assert(e->getNumInits() == 0 && "Unexpected number of inits");
- mlir::Type compleTy = cgf.convertType(e->getType());
- return builder.getNullValue(compleTy, loc);
+ mlir::Type complexTy = cgf.convertType(e->getType());
+ return builder.getNullValue(complexTy, loc);
}
mlir::Value
More information about the cfe-commits
mailing list