[llvm-branch-commits] [clang] a9a997c - [CIR] Implement CXX new for ComplexType with init (#159973)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Sep 23 08:58:07 PDT 2025
Author: Amr Hesham
Date: 2025-09-23T17:11:37+02:00
New Revision: a9a997c729a7547daea06121fa3233a10e741099
URL: https://github.com/llvm/llvm-project/commit/a9a997c729a7547daea06121fa3233a10e741099
DIFF: https://github.com/llvm/llvm-project/commit/a9a997c729a7547daea06121fa3233a10e741099.diff
LOG: [CIR] Implement CXX new for ComplexType with init (#159973)
This change implements CXX new for ComplexType with init
Issue: https://github.com/llvm/llvm-project/issues/141365
Added:
Modified:
clang/lib/CIR/CodeGen/CIRGenExprCXX.cpp
clang/test/CIR/CodeGen/new.cpp
Removed:
################################################################################
diff --git a/clang/lib/CIR/CodeGen/CIRGenExprCXX.cpp b/clang/lib/CIR/CodeGen/CIRGenExprCXX.cpp
index 3db34ccb1748d..1f7e3dd1fa7d2 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprCXX.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprCXX.cpp
@@ -238,8 +238,8 @@ static void storeAnyExprIntoOneUnit(CIRGenFunction &cgf, const Expr *init,
cgf.makeAddrLValue(newPtr, allocType), false);
return;
case cir::TEK_Complex:
- cgf.cgm.errorNYI(init->getSourceRange(),
- "storeAnyExprIntoOneUnit: complex");
+ cgf.emitComplexExprIntoLValue(init, cgf.makeAddrLValue(newPtr, allocType),
+ /*isInit*/ true);
return;
case cir::TEK_Aggregate: {
assert(!cir::MissingFeatures::aggValueSlotGC());
diff --git a/clang/test/CIR/CodeGen/new.cpp b/clang/test/CIR/CodeGen/new.cpp
index 31adb9bf4859b..b14bf077cd154 100644
--- a/clang/test/CIR/CodeGen/new.cpp
+++ b/clang/test/CIR/CodeGen/new.cpp
@@ -152,3 +152,31 @@ void test_new_with_ctor() {
// OGCG: call{{.*}} void @_ZN2S2C1Eii(ptr {{.*}} %[[NEW_S2_2]], i32 noundef 1, i32 noundef 2)
// OGCG: store ptr %[[NEW_S2_2]], ptr %[[PS2_2_ADDR]], align 8
// OGCG: ret void
+
+void test_new_with_complex_type() {
+ _Complex float *a = new _Complex float{1.0f, 2.0f};
+}
+
+// CHECK: cir.func{{.*}} @_Z26test_new_with_complex_typev
+// CHECK: %0 = cir.alloca !cir.ptr<!cir.complex<!cir.float>>, !cir.ptr<!cir.ptr<!cir.complex<!cir.float>>>, ["a", init]
+// CHECK: %1 = cir.const #cir.int<8> : !u64i
+// CHECK: %2 = cir.call @_Znwm(%1) : (!u64i) -> !cir.ptr<!void>
+// CHECK: %3 = cir.cast(bitcast, %2 : !cir.ptr<!void>), !cir.ptr<!cir.complex<!cir.float>>
+// 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>
+// CHECK: cir.store align(8) %4, %3 : !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>
+// CHECK: cir.store align(8) %3, %0 : !cir.ptr<!cir.complex<!cir.float>>, !cir.ptr<!cir.ptr<!cir.complex<!cir.float>>>
+
+// LLVM: define{{.*}} void @_Z26test_new_with_complex_typev
+// LLVM: %[[A_ADDR:.*]] = alloca ptr, i64 1, align 8
+// LLVM: %[[NEW_COMPLEX:.*]] = call ptr @_Znwm(i64 8)
+// LLVM: store { float, float } { float 1.000000e+00, float 2.000000e+00 }, ptr %[[NEW_COMPLEX]], align 8
+// LLVM: store ptr %[[NEW_COMPLEX]], ptr %[[A_ADDR]], align 8
+
+// OGCG: define{{.*}} void @_Z26test_new_with_complex_typev
+// OGCG: %[[A_ADDR:.*]] = alloca ptr, align 8
+// OGCG: %[[NEW_COMPLEX:.*]] = call noalias noundef nonnull ptr @_Znwm(i64 noundef 8)
+// OGCG: %[[COMPLEX_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[NEW_COMPLEX]], i32 0, i32 0
+// OGCG: %[[COMPLEX_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[NEW_COMPLEX]], i32 0, i32 1
+// OGCG: store float 1.000000e+00, ptr %[[COMPLEX_REAL_PTR]], align 8
+// OGCG: store float 2.000000e+00, ptr %[[COMPLEX_IMAG_PTR]], align 4
+// OGCG: store ptr %[[NEW_COMPLEX]], ptr %[[A_ADDR]], align 8
More information about the llvm-branch-commits
mailing list