r320721 - In an ARC lambda-to-block conversion thunk, reclaim the return value of
John McCall via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 14 10:21:14 PST 2017
Author: rjmccall
Date: Thu Dec 14 10:21:14 2017
New Revision: 320721
URL: http://llvm.org/viewvc/llvm-project?rev=320721&view=rev
Log:
In an ARC lambda-to-block conversion thunk, reclaim the return value of
the lambda so that we don't over-release it.
Patch by Dan Zimmerman!
Added:
cfe/trunk/test/CodeGenObjCXX/arc-forwarded-lambda-call.mm
Modified:
cfe/trunk/lib/CodeGen/CGClass.cpp
Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=320721&r1=320720&r2=320721&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Thu Dec 14 10:21:14 2017
@@ -2777,9 +2777,12 @@ void CodeGenFunction::EmitForwardingCall
RValue RV = EmitCall(calleeFnInfo, callee, returnSlot, callArgs);
// If necessary, copy the returned value into the slot.
- if (!resultType->isVoidType() && returnSlot.isNull())
+ if (!resultType->isVoidType() && returnSlot.isNull()) {
+ if (getLangOpts().ObjCAutoRefCount && resultType->isObjCRetainableType()) {
+ RV = RValue::get(EmitARCRetainAutoreleasedReturnValue(RV.getScalarVal()));
+ }
EmitReturnOfRValue(RV, resultType);
- else
+ } else
EmitBranchThroughCleanup(ReturnBlock);
}
Added: cfe/trunk/test/CodeGenObjCXX/arc-forwarded-lambda-call.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/arc-forwarded-lambda-call.mm?rev=320721&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjCXX/arc-forwarded-lambda-call.mm (added)
+++ cfe/trunk/test/CodeGenObjCXX/arc-forwarded-lambda-call.mm Thu Dec 14 10:21:14 2017
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.12.0 -emit-llvm -disable-llvm-passes -O3 -fblocks -fobjc-arc -fobjc-runtime-has-weak -std=c++11 -o - %s | FileCheck %s
+
+void test0(id x) {
+ extern void test0_helper(id (^)(void));
+ test0_helper([=]() { return x; });
+ // CHECK-LABEL: define internal i8* @___Z5test0P11objc_object_block_invoke
+ // CHECK: [[T0:%.*]] = call i8* @"_ZZ5test0P11objc_objectENK3$_0clEv"
+ // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]])
+ // CHECK-NEXT: [[T2:%.*]] = tail call i8* @objc_autoreleaseReturnValue(i8* [[T1]])
+ // CHECK-NEXT: ret i8* [[T2]]
+}
+
+id test1_rv;
+
+void test1() {
+ extern void test1_helper(id (*)(void));
+ test1_helper([](){ return test1_rv; });
+ // CHECK-LABEL: define internal i8* @"_ZZ5test1vEN3$_18__invokeEv"
+ // CHECK: [[T0:%.*]] = call i8* @"_ZZ5test1vENK3$_1clEv"
+ // CHECK-NEXT: [[T1:%.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* [[T0]])
+ // CHECK-NEXT: [[T2:%.*]] = tail call i8* @objc_autoreleaseReturnValue(i8* [[T1]])
+ // CHECK-NEXT: ret i8* [[T2]]
+}
More information about the cfe-commits
mailing list