[PATCH] D82513: [CodeGen] Store the return value of the target function call to the thunk's return value slot directly when the return type is an aggregate instead of doing so via a temporary
Akira Hatanaka via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 24 17:56:47 PDT 2020
ahatanak created this revision.
ahatanak added reviewers: rjmccall, hans.
ahatanak added a project: clang.
Herald added subscribers: ributzka, dexonsmith, jkorous.
This fixes PR45997 (https://bugs.llvm.org/show_bug.cgi?id=45997), which is caused by a bug that has existed since we started passing and returning C++ structs with ObjC strong pointer members directly in some cases (see https://reviews.llvm.org/D44908).
rdar://problem/63740936
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D82513
Files:
clang/lib/CodeGen/CGVTables.cpp
clang/test/CodeGenObjCXX/objc-struct-cxx-abi.mm
Index: clang/test/CodeGenObjCXX/objc-struct-cxx-abi.mm
===================================================================
--- clang/test/CodeGenObjCXX/objc-struct-cxx-abi.mm
+++ clang/test/CodeGenObjCXX/objc-struct-cxx-abi.mm
@@ -178,3 +178,32 @@
void testCallContainsNonTrivial(ContainsNonTrivial *a) {
testParamContainsNonTrivial(*a);
}
+
+namespace testThunk {
+
+// CHECK-LABEL: define i64 @_ZThn8_N9testThunk2D02m0Ev(
+// CHECK: %[[RETVAL:.*]] = alloca %[[STRUCT_STRONG]], align 8
+// CHECK: %[[CALL:.*]] = tail call i64 @_ZN9testThunk2D02m0Ev(
+// CHECK: %[[COERCE_DIVE:.*]] = getelementptr inbounds %[[STRUCT_STRONG]], %[[STRUCT_STRONG]]* %[[RETVAL]], i32 0, i32 0
+// CHECK: %[[COERCE_VAL_IP:.*]] = inttoptr i64 %[[CALL]] to i8*
+// CHECK: store i8* %[[COERCE_VAL_IP]], i8** %[[COERCE_DIVE]], align 8
+// CHECK: %[[COERCE_DIVE2:.*]] = getelementptr inbounds %[[STRUCT_STRONG]], %[[STRUCT_STRONG]]* %[[RETVAL]], i32 0, i32 0
+// CHECK: %[[V3:.*]] = load i8*, i8** %[[COERCE_DIVE2]], align 8
+// CHECK: %[[COERCE_VAL_PI:.*]] = ptrtoint i8* %[[V3]] to i64
+// CHECK: ret i64 %[[COERCE_VAL_PI]]
+
+struct B0 {
+ virtual Strong m0();
+};
+
+struct B1 {
+ virtual Strong m0();
+};
+
+struct D0 : B0, B1 {
+ Strong m0() override;
+};
+
+Strong D0::m0() { return {}; }
+
+}
Index: clang/lib/CodeGen/CGVTables.cpp
===================================================================
--- clang/lib/CodeGen/CGVTables.cpp
+++ clang/lib/CodeGen/CGVTables.cpp
@@ -363,7 +363,8 @@
: FPT->getReturnType();
ReturnValueSlot Slot;
if (!ResultType->isVoidType() &&
- CurFnInfo->getReturnInfo().getKind() == ABIArgInfo::Indirect)
+ (CurFnInfo->getReturnInfo().getKind() == ABIArgInfo::Indirect ||
+ hasAggregateEvaluationKind(ResultType)))
Slot = ReturnValueSlot(ReturnValue, ResultType.isVolatileQualified(),
/*IsUnused=*/false, /*IsExternallyDestructed=*/true);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82513.273196.patch
Type: text/x-patch
Size: 1951 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200625/4532d8b1/attachment.bin>
More information about the cfe-commits
mailing list