Author: Amr Hesham Date: 2025-10-05T11:38:27Z New Revision: 3149a7720f714c14f7e6320745d9e35f49dba62b
URL: https://github.com/llvm/llvm-project/commit/3149a7720f714c14f7e6320745d9e35f49dba62b DIFF: https://github.com/llvm/llvm-project/commit/3149a7720f714c14f7e6320745d9e35f49dba62b.diff LOG: [CIR] Implement DesignatedInitUpdateExpr for AggregateExpr (#161897) Implement the DesignatedInitUpdateExpr support for AggregateExpr Added: Modified: clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp clang/test/CIR/CodeGen/struct.cpp Removed: ################################################################################ diff --git a/clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp b/clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp index e51c3fcdef962..60ccf18b743df 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprAggregate.cpp @@ -201,8 +201,10 @@ class AggExprEmitter : public StmtVisitor<AggExprEmitter> { } void VisitDesignatedInitUpdateExpr(DesignatedInitUpdateExpr *e) { - cgf.cgm.errorNYI(e->getSourceRange(), - "AggExprEmitter: VisitDesignatedInitUpdateExpr"); + AggValueSlot dest = ensureSlot(cgf.getLoc(e->getExprLoc()), e->getType()); + LValue destLV = cgf.makeAddrLValue(dest.getAddress(), e->getType()); + emitInitializationToLValue(e->getBase(), destLV); + VisitInitListExpr(e->getUpdater()); } void VisitAbstractConditionalOperator(const AbstractConditionalOperator *e) { cgf.cgm.errorNYI(e->getSourceRange(), diff --git a/clang/test/CIR/CodeGen/struct.cpp b/clang/test/CIR/CodeGen/struct.cpp index c68f7426661b5..263799f8a5deb 100644 --- a/clang/test/CIR/CodeGen/struct.cpp +++ b/clang/test/CIR/CodeGen/struct.cpp @@ -184,6 +184,39 @@ void generic_selection() { // OGCG: %[[D_ADDR:.*]] = alloca %struct.CompleteS, align 4 // OGCG: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %[[D_ADDR]], ptr align 4 %[[A_ADDR]], i64 8, i1 false) +void designated_init_update_expr() { + CompleteS a; + + struct Container { + CompleteS c; + } b = {a, .c.a = 1}; +} + +// CIR: %[[A_ADDR:.*]] = cir.alloca !rec_CompleteS, !cir.ptr<!rec_CompleteS>, ["a"] +// CIR: %[[B_ADDR:.*]] = cir.alloca !rec_Container, !cir.ptr<!rec_Container>, ["b", init] +// CIR: %[[C_ADDR:.*]] = cir.get_member %[[B_ADDR]][0] {name = "c"} : !cir.ptr<!rec_Container> -> !cir.ptr<!rec_CompleteS> +// CIR: cir.call @_ZN9CompleteSC1ERKS_(%2, %[[A_ADDR]]) nothrow : (!cir.ptr<!rec_CompleteS>, !cir.ptr<!rec_CompleteS>) -> () +// CIR: %[[ELEM_0_PTR:.*]] = cir.get_member %[[C_ADDR]][0] {name = "a"} : !cir.ptr<!rec_CompleteS> -> !cir.ptr<!s32i> +// CIR: %[[CONST_1:.*]] = cir.const #cir.int<1> : !s32i +// CIR: cir.store{{.*}} %[[CONST_1]], %[[ELEM_0_PTR]] : !s32i, !cir.ptr<!s32i> +// CIR: %[[ELEM_1_PTR:.*]] = cir.get_member %[[C_ADDR]][1] {name = "b"} : !cir.ptr<!rec_CompleteS> -> !cir.ptr<!s8i> + +// LLVM: %[[A_ADDR:.*]] = alloca %struct.CompleteS, i64 1, align 4 +// LLVM: %[[B_ADDR:.*]] = alloca %struct.Container, i64 1, align 4 +// LLVM: %[[C_ADDR:.*]] = getelementptr %struct.Container, ptr %[[B_ADDR]], i32 0, i32 0 +// LLVM: call void @_ZN9CompleteSC1ERKS_(ptr %[[C_ADDR]], ptr %[[A_ADDR]]) +// LLVM: %[[ELEM_0_PTR:.*]] = getelementptr %struct.CompleteS, ptr %[[C_ADDR]], i32 0, i32 0 +// LLVM: store i32 1, ptr %[[ELEM_0_PTR]], align 4 +// LLVM: %[[ELEM_1_PTR:.*]] = getelementptr %struct.CompleteS, ptr %[[C_ADDR]], i32 0, i32 1 + +// OGCG: %[[A_ADDR:.*]] = alloca %struct.CompleteS, align 4 +// OGCG: %[[B_ADDR:.*]] = alloca %struct.Container, align 4 +// OGCG: %[[C_ADDR:.*]] = getelementptr inbounds nuw %struct.Container, ptr %[[B_ADDR]], i32 0, i32 0 +// OGCG: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %[[C_ADDR]], ptr align 4 %[[A_ADDR]], i64 8, i1 false) +// OGCG: %[[ELEM_0_PTR:.*]] = getelementptr inbounds nuw %struct.CompleteS, ptr %[[C_ADDR]], i32 0, i32 0 +// OGCG: store i32 1, ptr %[[ELEM_0_PTR]], align 4 +// OGCG: %[[ELEM_1_PTR:.*]] = getelementptr inbounds nuw %struct.CompleteS, ptr %[[C_ADDR]], i32 0, i32 1 + void atomic_init() { _Atomic CompleteS a; __c11_atomic_init(&a, {}); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
