-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IRGen] Don't call objc_retainAutoreleasedReturnValue() without interop.
When ObjC interop is not enabled, we shouldn't be emitting calls to `objc_retainAutoreleasedReturnValue()` as that function might not exist. Call `swift_retain()` instead, to balance the `swift_release()` of the returned value. Fixes #47846, #45359. rdar://23335318
- Loading branch information
Showing
5 changed files
with
41 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#define CF_BRIDGED_TYPE(T) __attribute__((objc_bridge(T))) | ||
|
||
typedef struct CF_BRIDGED_TYPE(id) __CFBridgedType *CFBridgedTypeRef; | ||
|
||
__attribute__((cf_audited_transfer)) | ||
CFBridgedTypeRef returnsACFBridgedType(void); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// RUN: %target-swift-frontend -module-name cf_objc_retainAutoreleasedReturnValue -I %S/Inputs %s -enable-objc-interop -emit-ir | %FileCheck %s | ||
// RUN: %target-swift-frontend -module-name cf_objc_retainAutoreleasedReturnValue -I %S/Inputs %s -emit-ir | %FileCheck %s --check-prefix=NO_INTEROP | ||
|
||
import CFBridgedType | ||
|
||
@inline(never) | ||
public func foo() { | ||
let _ = returnsACFBridgedType() | ||
} | ||
|
||
// With interop enabled, this should use objc_retainAutoreleasedReturnValue() | ||
|
||
// CHECK-LABEL: define protected swiftcc void @"$s37cf_objc_retainAutoreleasedReturnValue3fooyyF"() | ||
// CHECK: entry: | ||
// CHECK: %0 = call {{.*}}@returnsACFBridgedType() | ||
// CHECK: %1 = notail call ptr @llvm.objc.retainAutoreleasedReturnValue(ptr %0) | ||
|
||
// Without interop, it should call swift_retain() instead. | ||
|
||
// NO_INTEROP-LABEL: define protected swiftcc void @"$s37cf_objc_retainAutoreleasedReturnValue3fooyyF"() | ||
// NO_INTEROP: entry: | ||
// NO_INTEROP: %0 = call {{.*}}@returnsACFBridgedType() | ||
// NO_INTEROP: %1 = call ptr @swift_retain(ptr returned %0) | ||
|