Skip to content

Commit 3149a77

Browse files
authored
[CIR] Implement DesignatedInitUpdateExpr for AggregateExpr (#161897)
Implement the DesignatedInitUpdateExpr support for AggregateExpr
1 parent 1af06cb commit 3149a77

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,10 @@ class AggExprEmitter : public StmtVisitor<AggExprEmitter> {
201201
}
202202

203203
void VisitDesignatedInitUpdateExpr(DesignatedInitUpdateExpr *e) {
204-
cgf.cgm.errorNYI(e->getSourceRange(),
205-
"AggExprEmitter: VisitDesignatedInitUpdateExpr");
204+
AggValueSlot dest = ensureSlot(cgf.getLoc(e->getExprLoc()), e->getType());
205+
LValue destLV = cgf.makeAddrLValue(dest.getAddress(), e->getType());
206+
emitInitializationToLValue(e->getBase(), destLV);
207+
VisitInitListExpr(e->getUpdater());
206208
}
207209
void VisitAbstractConditionalOperator(const AbstractConditionalOperator *e) {
208210
cgf.cgm.errorNYI(e->getSourceRange(),

clang/test/CIR/CodeGen/struct.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,39 @@ void generic_selection() {
184184
// OGCG: %[[D_ADDR:.*]] = alloca %struct.CompleteS, align 4
185185
// OGCG: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %[[D_ADDR]], ptr align 4 %[[A_ADDR]], i64 8, i1 false)
186186

187+
void designated_init_update_expr() {
188+
CompleteS a;
189+
190+
struct Container {
191+
CompleteS c;
192+
} b = {a, .c.a = 1};
193+
}
194+
195+
// CIR: %[[A_ADDR:.*]] = cir.alloca !rec_CompleteS, !cir.ptr<!rec_CompleteS>, ["a"]
196+
// CIR: %[[B_ADDR:.*]] = cir.alloca !rec_Container, !cir.ptr<!rec_Container>, ["b", init]
197+
// CIR: %[[C_ADDR:.*]] = cir.get_member %[[B_ADDR]][0] {name = "c"} : !cir.ptr<!rec_Container> -> !cir.ptr<!rec_CompleteS>
198+
// CIR: cir.call @_ZN9CompleteSC1ERKS_(%2, %[[A_ADDR]]) nothrow : (!cir.ptr<!rec_CompleteS>, !cir.ptr<!rec_CompleteS>) -> ()
199+
// CIR: %[[ELEM_0_PTR:.*]] = cir.get_member %[[C_ADDR]][0] {name = "a"} : !cir.ptr<!rec_CompleteS> -> !cir.ptr<!s32i>
200+
// CIR: %[[CONST_1:.*]] = cir.const #cir.int<1> : !s32i
201+
// CIR: cir.store{{.*}} %[[CONST_1]], %[[ELEM_0_PTR]] : !s32i, !cir.ptr<!s32i>
202+
// CIR: %[[ELEM_1_PTR:.*]] = cir.get_member %[[C_ADDR]][1] {name = "b"} : !cir.ptr<!rec_CompleteS> -> !cir.ptr<!s8i>
203+
204+
// LLVM: %[[A_ADDR:.*]] = alloca %struct.CompleteS, i64 1, align 4
205+
// LLVM: %[[B_ADDR:.*]] = alloca %struct.Container, i64 1, align 4
206+
// LLVM: %[[C_ADDR:.*]] = getelementptr %struct.Container, ptr %[[B_ADDR]], i32 0, i32 0
207+
// LLVM: call void @_ZN9CompleteSC1ERKS_(ptr %[[C_ADDR]], ptr %[[A_ADDR]])
208+
// LLVM: %[[ELEM_0_PTR:.*]] = getelementptr %struct.CompleteS, ptr %[[C_ADDR]], i32 0, i32 0
209+
// LLVM: store i32 1, ptr %[[ELEM_0_PTR]], align 4
210+
// LLVM: %[[ELEM_1_PTR:.*]] = getelementptr %struct.CompleteS, ptr %[[C_ADDR]], i32 0, i32 1
211+
212+
// OGCG: %[[A_ADDR:.*]] = alloca %struct.CompleteS, align 4
213+
// OGCG: %[[B_ADDR:.*]] = alloca %struct.Container, align 4
214+
// OGCG: %[[C_ADDR:.*]] = getelementptr inbounds nuw %struct.Container, ptr %[[B_ADDR]], i32 0, i32 0
215+
// OGCG: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %[[C_ADDR]], ptr align 4 %[[A_ADDR]], i64 8, i1 false)
216+
// OGCG: %[[ELEM_0_PTR:.*]] = getelementptr inbounds nuw %struct.CompleteS, ptr %[[C_ADDR]], i32 0, i32 0
217+
// OGCG: store i32 1, ptr %[[ELEM_0_PTR]], align 4
218+
// OGCG: %[[ELEM_1_PTR:.*]] = getelementptr inbounds nuw %struct.CompleteS, ptr %[[C_ADDR]], i32 0, i32 1
219+
187220
void atomic_init() {
188221
_Atomic CompleteS a;
189222
__c11_atomic_init(&a, {});

0 commit comments

Comments
 (0)