Skip to content

Commit ecd67a7

Browse files
authored
[CIR] Upstream CXXDefaultArgExpr for AggregateExpr (#165991)
Upstream the CXXDefaultArgExpr support for AggregateExpr
1 parent 6601c38 commit ecd67a7

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,8 @@ class AggExprEmitter : public StmtVisitor<AggExprEmitter> {
343343
cgf.cgm.errorNYI(e->getSourceRange(), "AggExprEmitter: VisitNoInitExpr");
344344
}
345345
void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *dae) {
346-
cgf.cgm.errorNYI(dae->getSourceRange(),
347-
"AggExprEmitter: VisitCXXDefaultArgExpr");
346+
CIRGenFunction::CXXDefaultArgExprScope scope(cgf, dae);
347+
Visit(dae->getExpr());
348348
}
349349
void VisitCXXInheritedCtorInitExpr(const CXXInheritedCtorInitExpr *e) {
350350
cgf.cgm.errorNYI(e->getSourceRange(),

clang/test/CIR/CodeGen/struct.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,3 +344,47 @@ void struct_with_const_member_expr() {
344344
// OGCG: %[[BF_SET:.*]] = or i8 %[[BF_CLEAR]], 0
345345
// OGCG: store i8 %[[BF_SET]], ptr %[[REF_ADDR]], align 4
346346
// OGCG: store i32 0, ptr %[[A_ADDR]], align 4
347+
348+
void function_arg_with_default_value(CompleteS a = {1, 2}) {}
349+
350+
// CIR: %[[ARG_ADDR:.*]] = cir.alloca !rec_CompleteS, !cir.ptr<!rec_CompleteS>, ["a", init]
351+
// CIR: cir.store %{{.*}}, %[[ARG_ADDR]] : !rec_CompleteS, !cir.ptr<!rec_CompleteS>
352+
353+
// LLVM: %[[ARG_ADDR:.*]] = alloca %struct.CompleteS, i64 1, align 4
354+
// LLVM: store %struct.CompleteS %{{.*}}, ptr %[[ARG_ADDR]], align 4
355+
356+
// OGCG: %[[ARG_ADDR:.*]] = alloca %struct.CompleteS, align 4
357+
// OGCG: store i64 %{{.*}}, ptr %[[ARG_ADDR]], align 4
358+
359+
void calling_function_with_default_values() {
360+
function_arg_with_default_value();
361+
}
362+
363+
// CIR: %[[AGG_ADDR:.*]] = cir.alloca !rec_CompleteS, !cir.ptr<!rec_CompleteS>, ["agg.tmp0"]
364+
// CIR: %[[ELEM_0_PTR:.*]] = cir.get_member %[[AGG_ADDR]][0] {name = "a"} : !cir.ptr<!rec_CompleteS> -> !cir.ptr<!s32i>
365+
// CIR: %[[CONST_1:.*]] = cir.const #cir.int<1> : !s32i
366+
// CIR: cir.store{{.*}} %[[CONST_1]], %[[ELEM_0_PTR]] : !s32i, !cir.ptr<!s32i>
367+
// CIR: %[[ELEM_1_PTR:.*]] = cir.get_member %[[AGG_ADDR]][1] {name = "b"} : !cir.ptr<!rec_CompleteS> -> !cir.ptr<!s8i>
368+
// CIR: %[[CONST_2:.*]] = cir.const #cir.int<2> : !s32i
369+
// CIR: %[[CONST_2_I8:.*]] = cir.cast integral %[[CONST_2]] : !s32i -> !s8i
370+
// CIR: cir.store{{.*}} %[[CONST_2_I8]], %[[ELEM_1_PTR]] : !s8i, !cir.ptr<!s8i>
371+
// CIR: %[[TMP_AGG:.*]] = cir.load{{.*}} %[[AGG_ADDR]] : !cir.ptr<!rec_CompleteS>, !rec_CompleteS
372+
// CIR: cir.call @_Z31function_arg_with_default_value9CompleteS(%[[TMP_AGG]]) : (!rec_CompleteS) -> ()
373+
374+
// TODO(CIR): the difference between the CIR LLVM and OGCG is because the lack of calling convention lowering,
375+
376+
// LLVM: %[[AGG_ADDR:.*]] = alloca %struct.CompleteS, i64 1, align 4
377+
// LLVM: %[[ELEM_0_PTR:.*]] = getelementptr %struct.CompleteS, ptr %[[AGG_ADDR]], i32 0, i32 0
378+
// LLVM: store i32 1, ptr %[[ELEM_0_PTR]], align 4
379+
// LLVM: %[[ELEM_1_PTR:.*]] = getelementptr %struct.CompleteS, ptr %[[AGG_ADDR]], i32 0, i32 1
380+
// LLVM: store i8 2, ptr %[[ELEM_1_PTR]], align 4
381+
// LLVM: %[[TMP_AGG:.*]] = load %struct.CompleteS, ptr %[[AGG_ADDR]], align 4
382+
// LLVM: call void @_Z31function_arg_with_default_value9CompleteS(%struct.CompleteS %[[TMP_AGG]])
383+
384+
// OGCG: %[[AGG_ADDR:.*]] = alloca %struct.CompleteS, align 4
385+
// OGCG: %[[ELEM_0_PTR:.*]] = getelementptr inbounds nuw %struct.CompleteS, ptr %[[AGG_ADDR]], i32 0, i32 0
386+
// OGCG: store i32 1, ptr %[[ELEM_0_PTR]], align 4
387+
// OGCG: %[[ELEM_1_PTR:.*]] = getelementptr inbounds nuw %struct.CompleteS, ptr %[[AGG_ADDR]], i32 0, i32 1
388+
// OGCG: store i8 2, ptr %[[ELEM_1_PTR]], align 4
389+
// OGCG: %[[TMP_AGG:.*]] = load i64, ptr %[[AGG_ADDR]], align 4
390+
// OGCG: call void @_Z31function_arg_with_default_value9CompleteS(i64 %[[TMP_AGG]])

0 commit comments

Comments
 (0)