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

>From 62c9484e43b14314c4bd3ceae5b41ca30c4cf5c6 Mon Sep 17 00:00:00 2001
From: AmrDeveloper <[email protected]>
Date: Sun, 21 Sep 2025 08:51:14 +0200
Subject: [PATCH 1/2] [CIR] Upstream support Agg init with lvalue ComplexType

---
 clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp |  2 +-
 clang/test/CIR/CodeGen/array.cpp              | 22 +++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp
index dc34d2b3baa8d..f46a607830b82 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp
@@ -500,7 +500,7 @@ void AggExprEmitter::emitInitializationToLValue(Expr *e, 
LValue lv) {
 
   switch (cgf.getEvaluationKind(type)) {
   case cir::TEK_Complex:
-    cgf.cgm.errorNYI("emitInitializationToLValue TEK_Complex");
+    cgf.emitComplexExprIntoLValue(e, lv, /*isInit*/ true);
     break;
   case cir::TEK_Aggregate:
     cgf.emitAggExpr(e, AggValueSlot::forLValue(lv, AggValueSlot::IsDestructed,
diff --git a/clang/test/CIR/CodeGen/array.cpp b/clang/test/CIR/CodeGen/array.cpp
index a643de2d26189..5c6f049e45dff 100644
--- a/clang/test/CIR/CodeGen/array.cpp
+++ b/clang/test/CIR/CodeGen/array.cpp
@@ -575,3 +575,25 @@ void func12() {
 // LLVM: %[[ARR:.*]] = alloca [4 x %struct.Point], i64 1, align 16
 
 // OGCG: %[[ARR:.*]] = alloca [4 x %struct.Point], align 16
+
+void foo13() {
+  _Complex float arr[2] = {{1.1f, 2.2f}, {3.3f, 4.4f}};
+}
+
+// CIR: %[[ARR_ADDR:.*]] = cir.alloca !cir.array<!cir.complex<!cir.float> x 
2>, !cir.ptr<!cir.array<!cir.complex<!cir.float> x 2>>, ["arr", init]
+// CIR: %[[ARR_0:.*]] = cir.cast(array_to_ptrdecay, %[[ARR_ADDR]] : 
!cir.ptr<!cir.array<!cir.complex<!cir.float> x 2>>), 
!cir.ptr<!cir.complex<!cir.float>>
+// CIR: %[[CONST_COMPLEX_0:.*]] = cir.const 
#cir.const_complex<#cir.fp<1.100000e+00> : !cir.float, #cir.fp<2.200000e+00> : 
!cir.float> : !cir.complex<!cir.float>
+// CIR: cir.store{{.*}} %[[CONST_COMPLEX_0]], %[[ARR_0]] : 
!cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>
+// CIR: %[[IDX_1:.*]] = cir.const #cir.int<1> : !s64i
+// CIR: %[[ARR_1:.*]] = cir.ptr_stride(%1 : 
!cir.ptr<!cir.complex<!cir.float>>, %[[IDX_1]] : !s64i), 
!cir.ptr<!cir.complex<!cir.float>>
+// CIR: %[[CONST_COMPLEX_1:.*]] = cir.const 
#cir.const_complex<#cir.fp<3.300000e+00> : !cir.float, #cir.fp<4.400000e+00> : 
!cir.float> : !cir.complex<!cir.float>
+// CIR: cir.store{{.*}} %[[CONST_COMPLEX_1]], %[[ARR_1]] : 
!cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>
+
+// LLVM: %[[ARR_ADDR:.*]] = alloca [2 x { float, float }], i64 1, align 16
+// LLVM: %[[ARR_0:.*]] = getelementptr { float, float }, ptr %[[ARR_ADDR]], 
i32 0
+// LLVM: store { float, float } { float 0x3FF19999A0000000, float 
0x40019999A0000000 }, ptr %[[ARR_0]], align 8
+// LLVM: %[[ARR_1:.*]] = getelementptr { float, float }, ptr %[[ARR_0]], i64 1
+// LLVM: store { float, float } { float 0x400A666660000000, float 
0x40119999A0000000 }, ptr %[[ARR_1]], align 8
+
+// OGCG: %[[ARR_ADDR:.*]] = alloca [2 x { float, float }], align 16
+// OGCG: call void @llvm.memcpy.p0.p0.i64(ptr align 16 %[[ARR_ADDR]], ptr 
align 16 @__const._Z5foo13v.arr, i64 16, i1 false)

>From ed03994abc6ea4abf741ae2a545d0706ac4609e1 Mon Sep 17 00:00:00 2001
From: AmrDeveloper <[email protected]>
Date: Tue, 23 Sep 2025 17:20:24 +0200
Subject: [PATCH 2/2] Update the name of test function

---
 clang/test/CIR/CodeGen/array.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/CIR/CodeGen/array.cpp b/clang/test/CIR/CodeGen/array.cpp
index 5c6f049e45dff..88913a52af58b 100644
--- a/clang/test/CIR/CodeGen/array.cpp
+++ b/clang/test/CIR/CodeGen/array.cpp
@@ -576,7 +576,7 @@ void func12() {
 
 // OGCG: %[[ARR:.*]] = alloca [4 x %struct.Point], align 16
 
-void foo13() {
+void array_with_complex_elements() {
   _Complex float arr[2] = {{1.1f, 2.2f}, {3.3f, 4.4f}};
 }
 

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

Reply via email to