Skip to content

Commit d0a5dd1

Browse files
AmrDeveloperaokblast
authored andcommitted
[CIR] Implement VisitCXXDefaultArgExpr for ComplexType (llvm#164079)
Implement CXXDefaultArgExpr support for ComplexType Issue llvm#141365
1 parent c9dc0bd commit d0a5dd1

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,8 @@ class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> {
196196
return Visit(e->getSubExpr());
197197
}
198198
mlir::Value VisitCXXDefaultArgExpr(CXXDefaultArgExpr *dae) {
199-
cgf.cgm.errorNYI(dae->getExprLoc(),
200-
"ComplexExprEmitter VisitCXXDefaultArgExpr");
201-
return {};
199+
CIRGenFunction::CXXDefaultArgExprScope scope(cgf, dae);
200+
return Visit(dae->getExpr());
202201
}
203202
mlir::Value VisitCXXDefaultInitExpr(CXXDefaultInitExpr *die) {
204203
CIRGenFunction::CXXDefaultInitExprScope scope(cgf, die);

clang/lib/CIR/CodeGen/CIRGenFunction.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,11 @@ class CIRGenFunction : public CIRGenTypeCache {
733733
SourceLocExprScopeGuard sourceLocScope;
734734
};
735735

736+
struct CXXDefaultArgExprScope : SourceLocExprScopeGuard {
737+
CXXDefaultArgExprScope(CIRGenFunction &cfg, const CXXDefaultArgExpr *e)
738+
: SourceLocExprScopeGuard(e, cfg.curSourceLocExprScope) {}
739+
};
740+
736741
LValue makeNaturalAlignPointeeAddrLValue(mlir::Value v, clang::QualType t);
737742
LValue makeNaturalAlignAddrLValue(mlir::Value val, QualType ty);
738743

clang/test/CIR/CodeGen/complex.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,3 +1429,42 @@ void imag_on_scalar_bool() {
14291429
// OGCG: %[[A_ADDR:.*]] = alloca i8, align 1
14301430
// OGCG: %[[B_ADDR:.*]] = alloca i8, align 1
14311431
// OGCG: store i8 0, ptr %[[B_ADDR]], align 1
1432+
1433+
void function_with_complex_default_arg(
1434+
float _Complex a = __builtin_complex(1.0f, 2.2f)) {}
1435+
1436+
// CIR: %[[ARG_0_ADDR:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["a", init]
1437+
// CIR: cir.store %{{.*}}, %[[ARG_0_ADDR]] : !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>
1438+
1439+
// TODO(CIR): the difference between the CIR LLVM and OGCG is because the lack of calling convention lowering,
1440+
1441+
// LLVM: %[[ARG_0_ADDR:.*]] = alloca { float, float }, i64 1, align 4
1442+
// LLVM: store { float, float } %{{.*}}, ptr %[[ARG_0_ADDR]], align 4
1443+
1444+
// OGCG: %[[ARG_0_ADDR:.*]] = alloca { float, float }, align 4
1445+
// OGCG: store <2 x float> %{{.*}}, ptr %[[ARG_0_ADDR]], align 4
1446+
1447+
void calling_function_with_default_arg() {
1448+
function_with_complex_default_arg();
1449+
}
1450+
1451+
// CIR: %[[DEFAULT_ARG_ADDR:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["coerce"]
1452+
// CIR: %[[DEFAULT_ARG_VAL:.*]] = cir.const #cir.const_complex<#cir.fp<1.000000e+00> : !cir.float, #cir.fp<2.200000e+00> : !cir.float> : !cir.complex<!cir.float>
1453+
// CIR: cir.store{{.*}} %[[DEFAULT_ARG_VAL]], %[[DEFAULT_ARG_ADDR]] : !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>
1454+
// CIR: %[[TMP_DEFAULT_ARG:.*]] = cir.load{{.*}} %[[DEFAULT_ARG_ADDR]] : !cir.ptr<!cir.complex<!cir.float>>, !cir.complex<!cir.float>
1455+
// CIR: cir.call @_Z33function_with_complex_default_argCf(%[[TMP_DEFAULT_ARG]]) : (!cir.complex<!cir.float>) -> ()
1456+
1457+
// TODO(CIR): the difference between the CIR LLVM and OGCG is because the lack of calling convention lowering,
1458+
1459+
// LLVM: %[[DEFAULT_ARG_ADDR:.*]] = alloca { float, float }, i64 1, align 4
1460+
// LLVM: store { float, float } { float 1.000000e+00, float 0x40019999A0000000 }, ptr %[[DEFAULT_ARG_ADDR]], align 4
1461+
// LLVM: %[[TMP_DEFAULT_ARG:.*]] = load { float, float }, ptr %[[DEFAULT_ARG_ADDR]], align 4
1462+
// LLVM: call void @_Z33function_with_complex_default_argCf({ float, float } %[[TMP_DEFAULT_ARG]])
1463+
1464+
// OGCG: %[[DEFAULT_ARG_ADDR:.*]] = alloca { float, float }, align 4
1465+
// OGCG: %[[DEFAULT_ARG_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[DEFAULT_ARG_ADDR]], i32 0, i32 0
1466+
// OGCG: %[[DEFAULT_ARG_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[DEFAULT_ARG_ADDR]], i32 0, i32 1
1467+
// OGCG: store float 1.000000e+00, ptr %[[DEFAULT_ARG_REAL_PTR]], align 4
1468+
// OGCG: store float 0x40019999A0000000, ptr %[[DEFAULT_ARG_IMAG_PTR]], align 4
1469+
// OGCG: %[[TMP_DEFAULT_ARG:.*]] = load <2 x float>, ptr %[[DEFAULT_ARG_ADDR]], align 4
1470+
// OGCG: call void @_Z33function_with_complex_default_argCf(<2 x float> {{.*}} %[[TMP_DEFAULT_ARG]])

0 commit comments

Comments
 (0)