Skip to content

Commit 6a0ba8b

Browse files
authored
[CIR] Prepare a 'this' for CXXDefaultInitExprs (#165994)
Prepare a 'this' for CXXDefaultInitExprs
1 parent e1324a9 commit 6a0ba8b

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,9 @@ void AggExprEmitter::visitCXXParenListOrInitListExpr(
839839
}
840840
}
841841

842+
// Prepare a 'this' for CXXDefaultInitExprs.
843+
CIRGenFunction::FieldConstructionScope fcScope(cgf, dest.getAddress());
844+
842845
LValue destLV = cgf.makeAddrLValue(dest.getAddress(), e->getType());
843846

844847
if (record->isUnion()) {

clang/test/CIR/CodeGen/struct-init.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,26 @@ void init_expr(int a, int b, int c) {
205205
// OGCG: %[[C_PLUS_THREE:.*]] = add nsw i32 %[[C]], 3
206206
// OGCG: store i32 %[[C_PLUS_THREE]], ptr %[[S_C]]
207207
// OGCG: ret void
208+
209+
void cxx_default_init_with_struct_field() {
210+
struct Parent {
211+
int getA();
212+
int a = getA();
213+
};
214+
Parent p = Parent{};
215+
}
216+
217+
// CIR: %[[P_ADDR:.*]] = cir.alloca !rec_Parent, !cir.ptr<!rec_Parent>, ["p", init]
218+
// CIR: %[[P_ELEM_0_PTR:.*]] = cir.get_member %[[P_ADDR]][0] {name = "a"} : !cir.ptr<!rec_Parent> -> !cir.ptr<!s32i>
219+
// CIR: %[[METHOD_CALL:.*]] = cir.call @_ZZ34cxx_default_init_with_struct_fieldvEN6Parent4getAEv(%[[P_ADDR]]) : (!cir.ptr<!rec_Parent>) -> !s32i
220+
// CIR: cir.store{{.*}} %[[METHOD_CALL]], %[[P_ELEM_0_PTR]] : !s32i, !cir.ptr<!s32i>
221+
222+
// LLVM: %[[P_ADDR:.*]] = alloca %struct.Parent, i64 1, align 4
223+
// LLVM: %[[P_ELEM_0_PTR:.*]] = getelementptr %struct.Parent, ptr %[[P_ADDR]], i32 0, i32 0
224+
// LLVM: %[[METHOD_CALL:.*]] = call i32 @_ZZ34cxx_default_init_with_struct_fieldvEN6Parent4getAEv(ptr %[[P_ADDR]])
225+
// LLVM: store i32 %[[METHOD_CALL]], ptr %[[P_ELEM_0_PTR]], align 4
226+
227+
// OGCG: %[[P_ADDR:.*]] = alloca %struct.Parent, align 4
228+
// OGCG: %[[P_ELEM_0_PTR:.*]] = getelementptr inbounds nuw %struct.Parent, ptr %[[P_ADDR]], i32 0, i32 0
229+
// OGCG: %[[METHOD_CALL:.*]] = call noundef i32 @_ZZ34cxx_default_init_with_struct_fieldvEN6Parent4getAEv(ptr {{.*}} %[[P_ADDR]])
230+
// OGCG: store i32 %[[METHOD_CALL]], ptr %[[P_ELEM_0_PTR]], align 4

0 commit comments

Comments
 (0)