Skip to content

Commit 9e1dcc2

Browse files
authored
[CIR] Implement CXXDefaultInitExpr support for ComplexType (#1869)
This change adds support for CXXDefaultInitExpr for ComplexType
1 parent ef64f86 commit 9e1dcc2

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

clang/lib/CIR/CodeGen/CIRGenExprAgg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ void AggExprEmitter::emitInitializationToLValue(Expr *E, LValue LV) {
790790

791791
switch (CGF.getEvaluationKind(type)) {
792792
case cir::TEK_Complex:
793-
llvm_unreachable("NYI");
793+
CGF.emitComplexExprIntoLValue(E, LV, /*isInit*/ true);
794794
return;
795795
case cir::TEK_Aggregate:
796796
CGF.emitAggExpr(

clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,12 @@ class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> {
171171
mlir::Value VisitCXXDefaultArgExpr(CXXDefaultArgExpr *DAE) {
172172
llvm_unreachable("NYI");
173173
}
174+
174175
mlir::Value VisitCXXDefaultInitExpr(CXXDefaultInitExpr *DIE) {
175-
llvm_unreachable("NYI");
176+
CIRGenFunction::CXXDefaultInitExprScope Scope(CGF, DIE);
177+
return Visit(DIE->getExpr());
176178
}
179+
177180
mlir::Value VisitExprWithCleanups(ExprWithCleanups *E) {
178181
CIRGenFunction::RunCleanupsScope Scope(CGF);
179182
mlir::Value V = Visit(E->getSubExpr());

clang/test/CIR/CodeGen/complex.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR
33
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-llvm %s -o %t-cir.ll
44
// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM
5+
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -Wno-unused-value -emit-llvm %s -o %t.ll
6+
// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG
57

68
void complex_functional_cast() {
79
using IntComplex = int _Complex;
@@ -184,3 +186,27 @@ void complex_comma_operator(int _Complex a, int _Complex b) {
184186
// LLVM: %[[RESULT:.*]] = alloca { i32, i32 }, i64 1, align 4
185187
// LLVM: %[[TMP_B:.*]] = load { i32, i32 }, ptr %[[COMPLEX_B]], align 4
186188
// LLVM: store { i32, i32 } %[[TMP_B]], ptr %[[RESULT]], align 4
189+
190+
void complex_cxx_default_init_expr() {
191+
struct FPComplexWrapper {
192+
float _Complex c{};
193+
};
194+
195+
FPComplexWrapper w{};
196+
}
197+
198+
// CIR: %[[W_ADDR:.*]] = cir.alloca !rec_FPComplexWrapper, !cir.ptr<!rec_FPComplexWrapper>, ["w", init]
199+
// CIR: %[[C_ADDR:.*]] = cir.get_member %[[W_ADDR]][0] {name = "c"} : !cir.ptr<!rec_FPComplexWrapper> -> !cir.ptr<!cir.complex<!cir.float>>
200+
// CIR: %[[CONST_COMPLEX:.*]] = cir.const #cir.complex<#cir.fp<0.000000e+00> : !cir.float, #cir.fp<0.000000e+00> : !cir.float> : !cir.complex<!cir.float>
201+
// CIR: cir.store{{.*}} %[[CONST_COMPLEX]], %[[C_ADDR]] : !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>
202+
203+
// LLVM: %[[W_ADDR:.*]] = alloca %struct.FPComplexWrapper, i64 1, align 4
204+
// LLVM: %[[C_ADDR:.*]] = getelementptr %struct.FPComplexWrapper, ptr %[[W_ADDR]], i32 0, i32 0
205+
// LLVM: store { float, float } zeroinitializer, ptr %[[C_ADDR]], align 4
206+
207+
// OGCG: %[[W_ADDR:.*]] = alloca %struct.Wrapper, align 4
208+
// OGCG: %[[C_ADDR:.*]] = getelementptr inbounds nuw %struct.FPComplexWrapper, ptr %[[W_ADDR]], i32 0, i32 0
209+
// OGCG: %[[C_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[C_ADDR]], i32 0, i32 0
210+
// OGCG: %[[C_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[C_ADDR]], i32 0, i32 1
211+
// OGCG: store float 0.000000e+00, ptr %[[C_REAL_PTR]], align 4
212+
// OGCG: store float 0.000000e+00, ptr %[[C_IMAG_PTR]], align 4

0 commit comments

Comments
 (0)