[clang] [CIR] Upstream support Agg init with lvalue ComplexType (PR #159974)
Amr Hesham via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 23 11:20:34 PDT 2025
https://github.com/AmrDeveloper updated https://github.com/llvm/llvm-project/pull/159974
>From 8cab15bd7c28444de8197834bc0e012c0984474e Mon Sep 17 00:00:00 2001
From: AmrDeveloper <amr96 at programmer.net>
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 5615960ea5247..4a8aac900ee07 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 47d4083e9ed68d57ca6cefe9f9c8cd890fb9f0d6 Mon Sep 17 00:00:00 2001
From: AmrDeveloper <amr96 at programmer.net>
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 | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/clang/test/CIR/CodeGen/array.cpp b/clang/test/CIR/CodeGen/array.cpp
index 5c6f049e45dff..5dac10491d036 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}};
}
@@ -596,4 +596,4 @@ void foo13() {
// 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)
+// OGCG: call void @llvm.memcpy.p0.p0.i64(ptr align 16 %[[ARR_ADDR]], ptr align 16 @__const._Z27array_with_complex_elementsv.arr, i64 16, i1 false)
More information about the cfe-commits
mailing list