ahatanak created this revision. ahatanak added a reviewer: rjmccall. ahatanak added a project: clang. Herald added a project: All. ahatanak requested review of this revision.
Make sure the destructor is called if needed. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D136639 Files: clang/lib/CodeGen/CGExprAgg.cpp clang/test/CodeGenObjC/nontrivial-c-struct-property.m Index: clang/test/CodeGenObjC/nontrivial-c-struct-property.m =================================================================== --- clang/test/CodeGenObjC/nontrivial-c-struct-property.m +++ clang/test/CodeGenObjC/nontrivial-c-struct-property.m @@ -68,3 +68,26 @@ // CHECK: call void @objc_copyCppObjectAtomic({{.*}}, {{.*}}, ptr noundef @__move_assignment_8_8_s0) // CHECK-NOT: call // CHECK: ret void + +// CHECK: define void @test0(ptr noundef %{{.*}}, ptr noundef %[[A:.*]]) +// CHECK: alloca ptr, align 8 +// CHECK: %[[A_ADDR:.*]] = alloca ptr, align 8 +// CHECK: %[[AGG_TMP_ENSURED:.*]] = alloca %[[STRUCT_S0]], align 8 +// CHECK: %[[AGG_TMP:.*]] = alloca %[[STRUCT_S0]], align 8 +// CHECK: store ptr %[[A]], ptr %[[A_ADDR]], align 8 +// CHECK: %[[V0:.*]] = load ptr, ptr %[[A_ADDR]], align 8 +// CHECK: call void @__copy_constructor_8_8_s0(ptr %[[AGG_TMP_ENSURED]], ptr %[[V0]]) +// CHECK: call void @__copy_constructor_8_8_s0(ptr %[[AGG_TMP]], ptr %[[AGG_TMP_ENSURED]]) + +// CHECK: %[[COERCE_DIVE]] = getelementptr inbounds %[[STRUCT_S0]], ptr %[[AGG_TMP]], i32 0, i32 0 +// CHECK: %[[V4:.*]] = load ptr, ptr %[[COERCE_DIVE]], align 8 +// CHECK: %[[COERCE_VAL_PI:.*]] = ptrtoint ptr %[[V4]] to i64 +// CHECK: call void @objc_msgSend(ptr noundef %{{.*}}, ptr noundef %{{.*}}, i64 %[[COERCE_VAL_PI]]) + +// CHECK: call void @__destructor_8_s0(ptr %[[AGG_TMP]]) + +// CHECK: call void @__destructor_8_s0(ptr %[[AGG_TMP_ENSURED]]) + +void test0(C *c, S0 *a) { + c.atomic0 = *a; +} Index: clang/lib/CodeGen/CGExprAgg.cpp =================================================================== --- clang/lib/CodeGen/CGExprAgg.cpp +++ clang/lib/CodeGen/CGExprAgg.cpp @@ -201,7 +201,16 @@ return EmitFinalDestCopy(E->getType(), LV); } - CGF.EmitPseudoObjectRValue(E, EnsureSlot(E->getType())); + AggValueSlot Slot = EnsureSlot(E->getType()); + bool NeedsDestruction = + !Slot.isExternallyDestructed() && + E->getType().isDestructedType() == QualType::DK_nontrivial_c_struct; + if (NeedsDestruction) + Slot.setExternallyDestructed(); + CGF.EmitPseudoObjectRValue(E, Slot); + if (NeedsDestruction) + CGF.pushDestroy(QualType::DK_nontrivial_c_struct, Slot.getAddress(), + E->getType()); } void VisitVAArgExpr(VAArgExpr *E);
Index: clang/test/CodeGenObjC/nontrivial-c-struct-property.m =================================================================== --- clang/test/CodeGenObjC/nontrivial-c-struct-property.m +++ clang/test/CodeGenObjC/nontrivial-c-struct-property.m @@ -68,3 +68,26 @@ // CHECK: call void @objc_copyCppObjectAtomic({{.*}}, {{.*}}, ptr noundef @__move_assignment_8_8_s0) // CHECK-NOT: call // CHECK: ret void + +// CHECK: define void @test0(ptr noundef %{{.*}}, ptr noundef %[[A:.*]]) +// CHECK: alloca ptr, align 8 +// CHECK: %[[A_ADDR:.*]] = alloca ptr, align 8 +// CHECK: %[[AGG_TMP_ENSURED:.*]] = alloca %[[STRUCT_S0]], align 8 +// CHECK: %[[AGG_TMP:.*]] = alloca %[[STRUCT_S0]], align 8 +// CHECK: store ptr %[[A]], ptr %[[A_ADDR]], align 8 +// CHECK: %[[V0:.*]] = load ptr, ptr %[[A_ADDR]], align 8 +// CHECK: call void @__copy_constructor_8_8_s0(ptr %[[AGG_TMP_ENSURED]], ptr %[[V0]]) +// CHECK: call void @__copy_constructor_8_8_s0(ptr %[[AGG_TMP]], ptr %[[AGG_TMP_ENSURED]]) + +// CHECK: %[[COERCE_DIVE]] = getelementptr inbounds %[[STRUCT_S0]], ptr %[[AGG_TMP]], i32 0, i32 0 +// CHECK: %[[V4:.*]] = load ptr, ptr %[[COERCE_DIVE]], align 8 +// CHECK: %[[COERCE_VAL_PI:.*]] = ptrtoint ptr %[[V4]] to i64 +// CHECK: call void @objc_msgSend(ptr noundef %{{.*}}, ptr noundef %{{.*}}, i64 %[[COERCE_VAL_PI]]) + +// CHECK: call void @__destructor_8_s0(ptr %[[AGG_TMP]]) + +// CHECK: call void @__destructor_8_s0(ptr %[[AGG_TMP_ENSURED]]) + +void test0(C *c, S0 *a) { + c.atomic0 = *a; +} Index: clang/lib/CodeGen/CGExprAgg.cpp =================================================================== --- clang/lib/CodeGen/CGExprAgg.cpp +++ clang/lib/CodeGen/CGExprAgg.cpp @@ -201,7 +201,16 @@ return EmitFinalDestCopy(E->getType(), LV); } - CGF.EmitPseudoObjectRValue(E, EnsureSlot(E->getType())); + AggValueSlot Slot = EnsureSlot(E->getType()); + bool NeedsDestruction = + !Slot.isExternallyDestructed() && + E->getType().isDestructedType() == QualType::DK_nontrivial_c_struct; + if (NeedsDestruction) + Slot.setExternallyDestructed(); + CGF.EmitPseudoObjectRValue(E, Slot); + if (NeedsDestruction) + CGF.pushDestroy(QualType::DK_nontrivial_c_struct, Slot.getAddress(), + E->getType()); } void VisitVAArgExpr(VAArgExpr *E);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits