Skip to content

Commit 0860953

Browse files
authored
Merge pull request #72011 from al45tair/eng/PR-23335318
[IRGen] Don't call objc_retainAutoreleasedReturnValue() without interop.
2 parents a68adb9 + 0d7c575 commit 0860953

6 files changed

+57
-4
lines changed

lib/IRGen/GenCall.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2605,7 +2605,10 @@ class SyncCallEmission final : public CallEmission {
26052605
if (fnConv.getNumDirectSILResults() == 1
26062606
&& (fnConv.getDirectSILResults().begin()->getConvention()
26072607
== ResultConvention::Autoreleased)) {
2608-
result = emitObjCRetainAutoreleasedReturnValue(IGF, result);
2608+
if (IGF.IGM.Context.LangOpts.EnableObjCInterop)
2609+
result = emitObjCRetainAutoreleasedReturnValue(IGF, result);
2610+
else
2611+
IGF.emitNativeStrongRetain(result, IGF.getDefaultAtomicity());
26092612
}
26102613

26112614
auto origFnType = getCallee().getOrigFunctionType();

test/IRGen/Inputs/CFBridgedType.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#define CF_BRIDGED_TYPE(T) __attribute__((objc_bridge(T)))
2+
3+
typedef struct CF_BRIDGED_TYPE(id) __CFBridgedType *CFBridgedTypeRef;
4+
5+
__attribute__((cf_audited_transfer))
6+
CFBridgedTypeRef returnsACFBridgedType(void);

test/IRGen/Inputs/module.modulemap

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,9 @@ module SynthesizedProtocol {
3333
}
3434

3535
module PointerAuth {
36-
header "ptrauth_field_fptr_import.h"
37-
}
36+
header "ptrauth_field_fptr_import.h"
37+
}
38+
39+
module CFBridgedType {
40+
header "CFBridgedType.h"
41+
}

test/IRGen/autorelease.sil

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) %s -emit-ir | %FileCheck -check-prefix CHECK -check-prefix CHECK-%target-ptrsize -check-prefix %target-cpu -DINT=i%target-ptrsize %s
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) %s -enable-objc-interop -emit-ir | %FileCheck -check-prefix CHECK -check-prefix CHECK-%target-ptrsize -check-prefix %target-cpu -DINT=i%target-ptrsize %s
2+
3+
// REQUIRES: objc_codegen
24

35
// rdar://16565958
46

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %target-swift-frontend -module-name cf_objc_retainAutoreleasedReturnValue -I %S/Inputs %s -enable-objc-interop -emit-ir | %FileCheck %s
2+
3+
// We need to require objc_codegen to avoid this test on WASM.
4+
// (That's why the other half of this test is in a separate file.)
5+
6+
// REQUIRES: objc_codegen
7+
8+
import CFBridgedType
9+
10+
@inline(never)
11+
public func foo() {
12+
let _ = returnsACFBridgedType()
13+
}
14+
15+
// With interop enabled, this should use objc_retainAutoreleasedReturnValue()
16+
17+
// CHECK-LABEL: define {{.*}}swiftcc void @"$s37cf_objc_retainAutoreleasedReturnValue3fooyyF"()
18+
// CHECK: entry:
19+
// CHECK: %0 = call {{.*}}@returnsACFBridgedType()
20+
// CHECK: %1 = notail call ptr @llvm.objc.retainAutoreleasedReturnValue(ptr %0)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %target-swift-frontend -module-name cf_objc_retainAutoreleasedReturnValue -I %S/Inputs %s -disable-objc-interop -emit-ir | %FileCheck %s
2+
3+
// This is in a separate file because *this* one works on WASM.
4+
// (cf_objc_retainAutoreleasedReturnValue.swift does not.)
5+
6+
import CFBridgedType
7+
8+
@inline(never)
9+
public func foo() {
10+
let _ = returnsACFBridgedType()
11+
}
12+
13+
// With interop disabled, this should use swift_retain().
14+
15+
// CHECK-LABEL: define {{.*}}swiftcc void @"$s37cf_objc_retainAutoreleasedReturnValue3fooyyF"()
16+
// CHECK: entry:
17+
// CHECK: %0 = call {{.*}}@returnsACFBridgedType()
18+
// CHECK: %1 = call ptr @swift_retain(ptr returned %0)

0 commit comments

Comments
 (0)