Skip to content

Commit 375bfbf

Browse files
authored
[CIR] Backport VisitCXXDefaultArgExpr for ComplexType (#1961)
Backport the VisitCXXDefaultArgExpr support for ComplexType from the upstream
1 parent 0a77e15 commit 375bfbf

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> {
174174
return Visit(E->getSubExpr());
175175
}
176176
mlir::Value VisitCXXDefaultArgExpr(CXXDefaultArgExpr *DAE) {
177-
llvm_unreachable("NYI");
177+
CIRGenFunction::CXXDefaultArgExprScope scope(CGF, DAE);
178+
return Visit(DAE->getExpr());
178179
}
179180

180181
mlir::Value VisitCXXDefaultInitExpr(CXXDefaultInitExpr *DIE) {

clang/test/CIR/CodeGen/complex.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,3 +331,42 @@ void complex_type_argument() {
331331
// OGCG: %[[TMP_ARG:.*]] = load <2 x float>, ptr %[[ARG_ADDR]], align 4
332332
// OGCG: call void @_Z22complex_type_parameterCf(<2 x float> noundef %[[TMP_ARG]])
333333

334+
void function_with_complex_default_arg(
335+
float _Complex a = __builtin_complex(1.0f, 2.2f)) {}
336+
337+
// CIR: %[[ARG_0_ADDR:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["a", init]
338+
// CIR: cir.store %{{.*}}, %[[ARG_0_ADDR]] : !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>
339+
340+
// TODO(CIR): the difference between the CIR LLVM and OGCG is because the lack of calling convention lowering,
341+
342+
// LLVM: %[[ARG_0_ADDR:.*]] = alloca { float, float }, i64 1, align 4
343+
// LLVM: store { float, float } %{{.*}}, ptr %[[ARG_0_ADDR]], align 4
344+
345+
// OGCG: %[[ARG_0_ADDR:.*]] = alloca { float, float }, align 4
346+
// OGCG: store <2 x float> %{{.*}}, ptr %[[ARG_0_ADDR]], align 4
347+
348+
void calling_function_with_default_arg() {
349+
function_with_complex_default_arg();
350+
}
351+
352+
// CIR: %[[DEFAULT_ARG_ADDR:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["coerce"]
353+
// CIR: %[[DEFAULT_ARG_VAL:.*]] = cir.const #cir.complex<#cir.fp<1.000000e+00> : !cir.float, #cir.fp<2.200000e+00> : !cir.float> : !cir.complex<!cir.float>
354+
// CIR: cir.store{{.*}} %[[DEFAULT_ARG_VAL]], %[[DEFAULT_ARG_ADDR]] : !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>
355+
// CIR: %[[TMP_DEFAULT_ARG:.*]] = cir.load{{.*}} %[[DEFAULT_ARG_ADDR]] : !cir.ptr<!cir.complex<!cir.float>>, !cir.complex<!cir.float>
356+
// CIR: cir.call @_Z33function_with_complex_default_argCf(%[[TMP_DEFAULT_ARG]]) : (!cir.complex<!cir.float>) -> ()
357+
358+
// TODO(CIR): the difference between the CIR LLVM and OGCG is because the lack of calling convention lowering,
359+
360+
// LLVM: %[[DEFAULT_ARG_ADDR:.*]] = alloca { float, float }, i64 1, align 4
361+
// LLVM: store { float, float } { float 1.000000e+00, float 0x40019999A0000000 }, ptr %[[DEFAULT_ARG_ADDR]], align 4
362+
// LLVM: %[[TMP_DEFAULT_ARG:.*]] = load { float, float }, ptr %[[DEFAULT_ARG_ADDR]], align 4
363+
// LLVM: call void @_Z33function_with_complex_default_argCf({ float, float } %[[TMP_DEFAULT_ARG]])
364+
365+
// OGCG: %[[DEFAULT_ARG_ADDR:.*]] = alloca { float, float }, align 4
366+
// OGCG: %[[DEFAULT_ARG_REAL_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[DEFAULT_ARG_ADDR]], i32 0, i32 0
367+
// OGCG: %[[DEFAULT_ARG_IMAG_PTR:.*]] = getelementptr inbounds nuw { float, float }, ptr %[[DEFAULT_ARG_ADDR]], i32 0, i32 1
368+
// OGCG: store float 1.000000e+00, ptr %[[DEFAULT_ARG_REAL_PTR]], align 4
369+
// OGCG: store float 0x40019999A0000000, ptr %[[DEFAULT_ARG_IMAG_PTR]], align 4
370+
// OGCG: %[[TMP_DEFAULT_ARG:.*]] = load <2 x float>, ptr %[[DEFAULT_ARG_ADDR]], align 4
371+
// OGCG: call void @_Z33function_with_complex_default_argCf(<2 x float> {{.*}} %[[TMP_DEFAULT_ARG]])
372+

0 commit comments

Comments
 (0)