llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clangir

Author: Amr Hesham (AmrDeveloper)

<details>
<summary>Changes</summary>

Upstream the support of Agg init with lvalue ComplexType

Issue: https://github.com/llvm/llvm-project/issues/141365

---
Full diff: https://github.com/llvm/llvm-project/pull/159974.diff


2 Files Affected:

- (modified) clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp (+1-1) 
- (modified) clang/test/CIR/CodeGen/array.cpp (+22) 


``````````diff
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)

``````````

</details>


https://github.com/llvm/llvm-project/pull/159974
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to