Skip to content

Commit 407e214

Browse files
authored
[CIR] Backport CXX new for ComplexType with init (#1937)
Backport CXX new for ComplexType with init from the upstream
1 parent 9997e41 commit 407e214

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

clang/lib/CIR/CodeGen/CIRGenExprCXX.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ RValue CIRGenFunction::emitCXXMemberOrOperatorMemberCallExpr(
302302
"Destructor shouldn't have explicit parameters");
303303
assert(ReturnValue.isNull() && "Destructor shouldn't have return value");
304304
if (useVirtualCall) {
305-
CIRGenFunction* CGF = CGM.getCurrCIRGenFun();
305+
CIRGenFunction *CGF = CGM.getCurrCIRGenFun();
306306
CGM.getCXXABI().emitVirtualDestructorCall(
307307
*CGF, dtor, Dtor_Complete, This.getAddress(),
308308
dyn_cast<CXXMemberCallExpr>(CE));
@@ -961,7 +961,8 @@ static void StoreAnyExprIntoOneUnit(CIRGenFunction &CGF, const Expr *Init,
961961
CGF.makeAddrLValue(NewPtr, AllocType), false);
962962
return;
963963
case cir::TEK_Complex:
964-
llvm_unreachable("NYI");
964+
CGF.emitComplexExprIntoLValue(Init, CGF.makeAddrLValue(NewPtr, AllocType),
965+
/*isInit*/ true);
965966
return;
966967
case cir::TEK_Aggregate: {
967968
AggValueSlot Slot = AggValueSlot::forAddr(

clang/test/CIR/CodeGen/new.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,3 +329,31 @@ void t_multidim_init() {
329329
// CHECK: %[[ELEM_12_PTR:.*]] = cir.get_element %[[ARRAY_ELEM1_PTR]][%[[OFFSET6]]] : (!cir.ptr<!cir.array<!s32i x 3>>, !s64i) -> !cir.ptr<!s32i>
330330
// CHECK: %[[ELEM_12_VAL:.*]] = cir.const #cir.int<6> : !s32i
331331
// CHECK: cir.store{{.*}} %[[ELEM_12_VAL]], %[[ELEM_12_PTR]] : !s32i, !cir.ptr<!s32i>
332+
333+
void test_new_with_complex_type() {
334+
_Complex float *a = new _Complex float{1.0f, 2.0f};
335+
}
336+
337+
// CHECK: cir.func{{.*}} @_Z26test_new_with_complex_typev
338+
// CHECK: %[[A_ADDR:.*]] = cir.alloca !cir.ptr<!cir.complex<!cir.float>>, !cir.ptr<!cir.ptr<!cir.complex<!cir.float>>>, ["a", init]
339+
// CHECK: %[[COMPLEX_SIZE:.*]] = cir.const #cir.int<8> : !u64i
340+
// CHECK: %[[NEW_COMPLEX:.*]] = cir.call @_Znwm(%[[COMPLEX_SIZE]]) : (!u64i) -> !cir.ptr<!void>
341+
// CHECK: %[[COMPLEX_PTR:.*]] = cir.cast bitcast %[[NEW_COMPLEX]] : !cir.ptr<!void> -> !cir.ptr<!cir.complex<!cir.float>>
342+
// CHECK: %[[COMPLEX_VAL:.*]] = cir.const #cir.complex<#cir.fp<1.000000e+00> : !cir.float, #cir.fp<2.000000e+00> : !cir.float> : !cir.complex<!cir.float>
343+
// CHECK: cir.store{{.*}} %[[COMPLEX_VAL]], %[[COMPLEX_PTR]] : !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>
344+
// CHECK: cir.store{{.*}} %[[COMPLEX_PTR]], %[[A_ADDR]] : !cir.ptr<!cir.complex<!cir.float>>, !cir.ptr<!cir.ptr<!cir.complex<!cir.float>>>
345+
346+
// LLVM: define{{.*}} void @_Z26test_new_with_complex_typev
347+
// LLVM: %[[A_ADDR:.*]] = alloca ptr, i64 1, align 8
348+
// LLVM: %[[NEW_COMPLEX:.*]] = call ptr @_Znwm(i64 8)
349+
// LLVM: store { float, float } { float 1.000000e+00, float 2.000000e+00 }, ptr %[[NEW_COMPLEX]], align 8
350+
// LLVM: store ptr %[[NEW_COMPLEX]], ptr %[[A_ADDR]], align 8
351+
352+
// OGCG: define{{.*}} void @_Z26test_new_with_complex_typev
353+
// OGCG: %[[A_ADDR:.*]] = alloca ptr, align 8
354+
// OGCG: %[[NEW_COMPLEX:.*]] = call noalias noundef nonnull ptr @_Znwm(i64 noundef 8)
355+
// OGCG: %[[COMPLEX_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[NEW_COMPLEX]], i32 0, i32 0
356+
// OGCG: %[[COMPLEX_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[NEW_COMPLEX]], i32 0, i32 1
357+
// OGCG: store float 1.000000e+00, ptr %[[COMPLEX_REAL_PTR]], align 8
358+
// OGCG: store float 2.000000e+00, ptr %[[COMPLEX_IMAG_PTR]], align 4
359+
// OGCG: store ptr %[[NEW_COMPLEX]], ptr %[[A_ADDR]], align 8

0 commit comments

Comments
 (0)