Skip to content

Commit 2d6a671

Browse files
authored
[CIR] Upstream support Agg init with lvalue ComplexType (#159974)
Upstream the support of Agg init with lvalue ComplexType Issue: #141365
1 parent 6d0f1e0 commit 2d6a671

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ void AggExprEmitter::emitInitializationToLValue(Expr *e, LValue lv) {
500500

501501
switch (cgf.getEvaluationKind(type)) {
502502
case cir::TEK_Complex:
503-
cgf.cgm.errorNYI("emitInitializationToLValue TEK_Complex");
503+
cgf.emitComplexExprIntoLValue(e, lv, /*isInit*/ true);
504504
break;
505505
case cir::TEK_Aggregate:
506506
cgf.emitAggExpr(e, AggValueSlot::forLValue(lv, AggValueSlot::IsDestructed,

clang/test/CIR/CodeGen/array.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,3 +575,25 @@ void func12() {
575575
// LLVM: %[[ARR:.*]] = alloca [4 x %struct.Point], i64 1, align 16
576576

577577
// OGCG: %[[ARR:.*]] = alloca [4 x %struct.Point], align 16
578+
579+
void array_with_complex_elements() {
580+
_Complex float arr[2] = {{1.1f, 2.2f}, {3.3f, 4.4f}};
581+
}
582+
583+
// 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]
584+
// 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>>
585+
// 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>
586+
// CIR: cir.store{{.*}} %[[CONST_COMPLEX_0]], %[[ARR_0]] : !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>
587+
// CIR: %[[IDX_1:.*]] = cir.const #cir.int<1> : !s64i
588+
// CIR: %[[ARR_1:.*]] = cir.ptr_stride(%1 : !cir.ptr<!cir.complex<!cir.float>>, %[[IDX_1]] : !s64i), !cir.ptr<!cir.complex<!cir.float>>
589+
// 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>
590+
// CIR: cir.store{{.*}} %[[CONST_COMPLEX_1]], %[[ARR_1]] : !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>
591+
592+
// LLVM: %[[ARR_ADDR:.*]] = alloca [2 x { float, float }], i64 1, align 16
593+
// LLVM: %[[ARR_0:.*]] = getelementptr { float, float }, ptr %[[ARR_ADDR]], i32 0
594+
// LLVM: store { float, float } { float 0x3FF19999A0000000, float 0x40019999A0000000 }, ptr %[[ARR_0]], align 8
595+
// LLVM: %[[ARR_1:.*]] = getelementptr { float, float }, ptr %[[ARR_0]], i64 1
596+
// LLVM: store { float, float } { float 0x400A666660000000, float 0x40119999A0000000 }, ptr %[[ARR_1]], align 8
597+
598+
// OGCG: %[[ARR_ADDR:.*]] = alloca [2 x { float, float }], align 16
599+
// 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)

0 commit comments

Comments
 (0)