https://github.com/AmrDeveloper updated 
https://github.com/llvm/llvm-project/pull/183836

>From ca940a35426a429b44989637d487f9f08ca729c6 Mon Sep 17 00:00:00 2001
From: Amr Hesham <[email protected]>
Date: Fri, 27 Feb 2026 22:21:28 +0100
Subject: [PATCH 1/2] [CIR] Implement ImplicitValueInitExpr for ComplexType

---
 clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp   |  6 ++---
 .../CIR/CodeGen/implicit-value-init-expr.cpp  | 25 +++++++++++++++++++
 2 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
index 64b9aa369e1d3..3a9f68ece29c9 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
@@ -223,9 +223,9 @@ class ComplexExprEmitter : public 
StmtVisitor<ComplexExprEmitter, mlir::Value> {
     return builder.getNullValue(complexTy, loc);
   }
   mlir::Value VisitImplicitValueInitExpr(ImplicitValueInitExpr *e) {
-    cgf.cgm.errorNYI(e->getExprLoc(),
-                     "ComplexExprEmitter VisitImplicitValueInitExpr");
-    return {};
+    mlir::Location loc = cgf.getLoc(e->getExprLoc());
+    mlir::Type complexTy = cgf.convertType(e->getType());
+    return builder.getNullValue(complexTy, loc);
   }
 
   struct BinOpInfo {
diff --git a/clang/test/CIR/CodeGen/implicit-value-init-expr.cpp 
b/clang/test/CIR/CodeGen/implicit-value-init-expr.cpp
index ad9f430411fba..1fa26fdc47a8c 100644
--- a/clang/test/CIR/CodeGen/implicit-value-init-expr.cpp
+++ b/clang/test/CIR/CodeGen/implicit-value-init-expr.cpp
@@ -33,3 +33,28 @@ void test(void *p) {
 // OGCG-NEXT:   %[[P1:.*]] = load ptr, ptr %[[P]], align 8
 // OGCG-NEXT:   store i32 0, ptr %[[P1]], align 4
 // OGCG-NEXT:   ret void
+
+void test_complex(void *p) { new (p) int _Complex(); }
+
+// CIR: cir.func{{.*}} @_Z12test_complexPv
+// CIR:   %[[P_ADDR:.*]] = cir.alloca !cir.ptr<!void>, 
!cir.ptr<!cir.ptr<!void>>, ["p", init]
+// CIR:   cir.store %[[ARG_0:.*]], %[[P_ADDR:.*]] : !cir.ptr<!void>, 
!cir.ptr<!cir.ptr<!void>>
+// CIR:   %[[TMP_P:.*]] = cir.load {{.*}} %[[P_ADDR]] : 
!cir.ptr<!cir.ptr<!void>>, !cir.ptr<!void>
+// CIR:   %[[P_COMPLEX:.*]] = cir.cast bitcast %[[TMP_P:.*]] : !cir.ptr<!void> 
-> !cir.ptr<!cir.complex<!s32i>>
+// CIR:   %[[CONST_0:.*]] = cir.const #cir.zero : !cir.complex<!s32i>
+// CIR:   cir.store {{.*}} %[[CONST_0]], %[[P_COMPLEX]] : !cir.complex<!s32i>, 
!cir.ptr<!cir.complex<!s32i>>
+
+// LLVM: define{{.*}} void @_Z12test_complexPv(ptr{{.*}} %[[ARG_0:.*]])
+// LLVM:   %[[P_ADDR:.*]] = alloca ptr, i64 1, align 8
+// LLVM:   store ptr %[[ARG_0]], ptr %[[P_ADDR]], align 8
+// LLVM:   %[[TMP_P:.*]] = load ptr, ptr %[[P_ADDR]], align 8
+// LLVM:   store { i32, i32 } zeroinitializer, ptr %[[TMP_P]], align 4
+
+// OGCG: define{{.*}} void @_Z12test_complexPv(ptr{{.*}} %[[ARG_0:.*]])
+// OGCG:   %[[P_ADDR:.*]] = alloca ptr, align 8
+// OGCG:   store ptr %[[ARG_0]], ptr %[[P_ADDR]], align 8
+// OGCG:   %[[TMP_P:.*]] = load ptr, ptr %[[P_ADDR]], align 8
+// OGCG:   %[[P_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr 
%[[TMP_P]], i32 0, i32 0
+// OGCG:   %[[P_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr 
%[[TMP_P]], i32 0, i32 1
+// OGCG:   store i32 0, ptr %[[P_REAL_PTR]], align 4
+// OGCG:   store i32 0, ptr %[[P_IMAG_PTR]], align 4

>From 2249a38b9b1a51bfb88e080a9848db5d355864da Mon Sep 17 00:00:00 2001
From: Amr Hesham <[email protected]>
Date: Fri, 27 Feb 2026 22:33:23 +0100
Subject: [PATCH 2/2] Remove alignments

---
 clang/test/CIR/CodeGen/implicit-value-init-expr.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/CIR/CodeGen/implicit-value-init-expr.cpp 
b/clang/test/CIR/CodeGen/implicit-value-init-expr.cpp
index 1fa26fdc47a8c..3babc7fb6e763 100644
--- a/clang/test/CIR/CodeGen/implicit-value-init-expr.cpp
+++ b/clang/test/CIR/CodeGen/implicit-value-init-expr.cpp
@@ -45,7 +45,7 @@ void test_complex(void *p) { new (p) int _Complex(); }
 // CIR:   cir.store {{.*}} %[[CONST_0]], %[[P_COMPLEX]] : !cir.complex<!s32i>, 
!cir.ptr<!cir.complex<!s32i>>
 
 // LLVM: define{{.*}} void @_Z12test_complexPv(ptr{{.*}} %[[ARG_0:.*]])
-// LLVM:   %[[P_ADDR:.*]] = alloca ptr, i64 1, align 8
+// LLVM:   %[[P_ADDR:.*]] = alloca ptr
 // LLVM:   store ptr %[[ARG_0]], ptr %[[P_ADDR]], align 8
 // LLVM:   %[[TMP_P:.*]] = load ptr, ptr %[[P_ADDR]], align 8
 // LLVM:   store { i32, i32 } zeroinitializer, ptr %[[TMP_P]], align 4

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to