Skip to content

Commit 7729dac

Browse files
committed
SILGen: Stub unavailable @objc interop functions and thunks.
Part of rdar://107388493
1 parent bed616c commit 7729dac

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

lib/SILGen/SILGenBridging.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,6 +1556,11 @@ void SILGenFunction::emitNativeToForeignThunk(SILDeclRef thunk) {
15561556
assert(thunk.isForeign);
15571557
SILDeclRef native = thunk.asForeign(false);
15581558

1559+
if (thunk.hasDecl()) {
1560+
if (shouldLowerToUnavailableCodeStub(thunk.getDecl()))
1561+
emitApplyOfUnavailableCodeReached();
1562+
}
1563+
15591564
// If we're calling a native non-designated class initializer, we have to
15601565
// discard the `self` object we were given, since
15611566
// Swift convenience initializers only have allocating entry points that
@@ -2067,6 +2072,9 @@ void SILGenFunction::emitForeignToNativeThunk(SILDeclRef thunk) {
20672072
auto nativeFnTy = F.getLoweredFunctionType();
20682073
assert(nativeFnTy == nativeCI.SILFnType);
20692074

2075+
if (shouldLowerToUnavailableCodeStub(fd))
2076+
emitApplyOfUnavailableCodeReached();
2077+
20702078
// Use the same generic environment as the native entry point.
20712079
F.setGenericEnvironment(SGM.Types.getConstantGenericEnvironment(thunk));
20722080

lib/SILGen/SILGenDestructor.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,9 @@ void SILGenFunction::emitObjCDestructor(SILDeclRef dtor) {
612612
if (dd->isImplicit())
613613
loc.markAutoGenerated();
614614

615+
if (shouldLowerToUnavailableCodeStub(dd))
616+
emitApplyOfUnavailableCodeReached();
617+
615618
SILValue selfValue = emitSelfDeclForDestructor(dd->getImplicitSelfDecl());
616619

617620
// Create a basic block to jump to for the implicit destruction behavior
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-silgen -module-name Test -parse-as-library %s -verify -unavailable-decl-optimization=stub | %FileCheck %s --check-prefixes=CHECK
2+
3+
// REQUIRES: objc_interop
4+
5+
import Foundation
6+
7+
func foo() {}
8+
9+
@available(*, unavailable)
10+
@objc public class C: NSObject {
11+
// C.__allocating_init()
12+
// CHECK-LABEL: sil {{.*}} @$s4Test1CCACycfC
13+
// CHECK: [[FNREF:%.*]] = function_ref @$ss31_diagnoseUnavailableCodeReacheds5NeverOyF
14+
// CHECK-NEXT: [[APPLY:%.*]] = apply [[FNREF]]()
15+
// CHECK: {{%.*}} = function_ref @$s4Test1CCACycfcTD
16+
// CHECK: } // end sil function '$s4Test1CCACycfC'
17+
//
18+
// dynamic C.init()
19+
// CHECK-LABEL: sil {{.*}} @$s4Test1CCACycfcTD
20+
// CHECK: [[FNREF:%.*]] = function_ref @$ss31_diagnoseUnavailableCodeReacheds5NeverOyF
21+
// CHECK-NEXT: [[APPLY:%.*]] = apply [[FNREF]]()
22+
// CHECK: objc_method %0 : $C, #C.init!initializer.foreign
23+
// CHECK: } // end sil function '$s4Test1CCACycfcTD'
24+
//
25+
// C.init()
26+
// CHECK-LABEL: sil {{.*}} @$s4Test1CCACycfc
27+
// CHECK: [[FNREF:%.*]] = function_ref @$ss31_diagnoseUnavailableCodeReacheds5NeverOyF
28+
// CHECK-NEXT: [[APPLY:%.*]] = apply [[FNREF]]()
29+
// CHECK: {{%.*}} = function_ref @$s4Test3fooyyF
30+
// CHECK: } // end sil function '$s4Test1CCACycfc'
31+
//
32+
// @objc C.init()
33+
// CHECK-LABEL: sil {{.*}} @$s4Test1CCACycfcTo
34+
// CHECK: [[FNREF:%.*]] = function_ref @$ss31_diagnoseUnavailableCodeReacheds5NeverOyF
35+
// CHECK-NEXT: [[APPLY:%.*]] = apply [[FNREF]]()
36+
// CHECK: {{%.*}} = function_ref @$s4Test1CCACycfc
37+
// CHECK: } // end sil function '$s4Test1CCACycfcTo'
38+
public override init() {
39+
foo()
40+
}
41+
42+
// C.__deallocating_deinit
43+
// CHECK-LABEL: sil {{.*}} @$s4Test1CCfD
44+
// CHECK: [[FNREF:%.*]] = function_ref @$ss31_diagnoseUnavailableCodeReacheds5NeverOyF
45+
// CHECK-NEXT: [[APPLY:%.*]] = apply [[FNREF]]()
46+
// CHECK: {{%.*}} = function_ref @$s4Test3fooyyF
47+
// CHECK: } // end sil function '$s4Test1CCfD'
48+
//
49+
// @objc C.__deallocating_deinit
50+
// CHECK-LABEL: sil {{.*}} @$s4Test1CCfDTo
51+
// CHECK: [[FNREF:%.*]] = function_ref @$ss31_diagnoseUnavailableCodeReacheds5NeverOyF
52+
// CHECK-NEXT: [[APPLY:%.*]] = apply [[FNREF]]()
53+
// CHECK: {{%.*}} = function_ref @$s4Test1CCfD
54+
// CHECK: } // end sil function '$s4Test1CCfDTo'
55+
deinit {
56+
foo()
57+
}
58+
}

0 commit comments

Comments
 (0)