Skip to content

Commit a9a997c

Browse files
authored
[CIR] Implement CXX new for ComplexType with init (#159973)
This change implements CXX new for ComplexType with init Issue: #141365
1 parent 0adfeb1 commit a9a997c

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

clang/lib/CIR/CodeGen/CIRGenExprCXX.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ static void storeAnyExprIntoOneUnit(CIRGenFunction &cgf, const Expr *init,
238238
cgf.makeAddrLValue(newPtr, allocType), false);
239239
return;
240240
case cir::TEK_Complex:
241-
cgf.cgm.errorNYI(init->getSourceRange(),
242-
"storeAnyExprIntoOneUnit: complex");
241+
cgf.emitComplexExprIntoLValue(init, cgf.makeAddrLValue(newPtr, allocType),
242+
/*isInit*/ true);
243243
return;
244244
case cir::TEK_Aggregate: {
245245
assert(!cir::MissingFeatures::aggValueSlotGC());

clang/test/CIR/CodeGen/new.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,31 @@ void test_new_with_ctor() {
152152
// OGCG: call{{.*}} void @_ZN2S2C1Eii(ptr {{.*}} %[[NEW_S2_2]], i32 noundef 1, i32 noundef 2)
153153
// OGCG: store ptr %[[NEW_S2_2]], ptr %[[PS2_2_ADDR]], align 8
154154
// OGCG: ret void
155+
156+
void test_new_with_complex_type() {
157+
_Complex float *a = new _Complex float{1.0f, 2.0f};
158+
}
159+
160+
// CHECK: cir.func{{.*}} @_Z26test_new_with_complex_typev
161+
// CHECK: %0 = cir.alloca !cir.ptr<!cir.complex<!cir.float>>, !cir.ptr<!cir.ptr<!cir.complex<!cir.float>>>, ["a", init]
162+
// CHECK: %1 = cir.const #cir.int<8> : !u64i
163+
// CHECK: %2 = cir.call @_Znwm(%1) : (!u64i) -> !cir.ptr<!void>
164+
// CHECK: %3 = cir.cast(bitcast, %2 : !cir.ptr<!void>), !cir.ptr<!cir.complex<!cir.float>>
165+
// CHECK: %4 = cir.const #cir.const_complex<#cir.fp<1.000000e+00> : !cir.float, #cir.fp<2.000000e+00> : !cir.float> : !cir.complex<!cir.float>
166+
// CHECK: cir.store align(8) %4, %3 : !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>
167+
// CHECK: cir.store align(8) %3, %0 : !cir.ptr<!cir.complex<!cir.float>>, !cir.ptr<!cir.ptr<!cir.complex<!cir.float>>>
168+
169+
// LLVM: define{{.*}} void @_Z26test_new_with_complex_typev
170+
// LLVM: %[[A_ADDR:.*]] = alloca ptr, i64 1, align 8
171+
// LLVM: %[[NEW_COMPLEX:.*]] = call ptr @_Znwm(i64 8)
172+
// LLVM: store { float, float } { float 1.000000e+00, float 2.000000e+00 }, ptr %[[NEW_COMPLEX]], align 8
173+
// LLVM: store ptr %[[NEW_COMPLEX]], ptr %[[A_ADDR]], align 8
174+
175+
// OGCG: define{{.*}} void @_Z26test_new_with_complex_typev
176+
// OGCG: %[[A_ADDR:.*]] = alloca ptr, align 8
177+
// OGCG: %[[NEW_COMPLEX:.*]] = call noalias noundef nonnull ptr @_Znwm(i64 noundef 8)
178+
// OGCG: %[[COMPLEX_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[NEW_COMPLEX]], i32 0, i32 0
179+
// OGCG: %[[COMPLEX_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[NEW_COMPLEX]], i32 0, i32 1
180+
// OGCG: store float 1.000000e+00, ptr %[[COMPLEX_REAL_PTR]], align 8
181+
// OGCG: store float 2.000000e+00, ptr %[[COMPLEX_IMAG_PTR]], align 4
182+
// OGCG: store ptr %[[NEW_COMPLEX]], ptr %[[A_ADDR]], align 8

0 commit comments

Comments
 (0)