Skip to content

Commit 3fdf0b2

Browse files
committed
SILGen: The foreign-to-native thunk for an @objc protocol member should use a native convention.
Fixes rdar://problem/31922123.
1 parent ee556cf commit 3fdf0b2

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/SIL/SILFunctionType.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1685,8 +1685,13 @@ TypeConverter::getDeclRefRepresentation(SILDeclRef c) {
16851685
// available. There's no great way to do this.
16861686

16871687
// Protocol witnesses are called using the witness calling convention.
1688-
if (auto proto = dyn_cast<ProtocolDecl>(c.getDecl()->getDeclContext()))
1688+
if (auto proto = dyn_cast<ProtocolDecl>(c.getDecl()->getDeclContext())) {
1689+
// Use the regular method convention for foreign-to-native thunks.
1690+
if (c.isForeignToNativeThunk())
1691+
return SILFunctionTypeRepresentation::Method;
1692+
assert(!c.isNativeToForeignThunk() && "shouldn't be possible");
16891693
return getProtocolWitnessRepresentation(proto);
1694+
}
16901695

16911696
switch (c.kind) {
16921697
case SILDeclRef::Kind::GlobalAccessor:
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-silgen %s | %FileCheck %s
2+
// REQUIRES: objc_interop
3+
4+
import Foundation
5+
6+
@objc protocol P {
7+
func p(_: String)
8+
}
9+
@objc class C: NSObject {
10+
func c(_: String) {}
11+
}
12+
13+
// CHECK-LABEL: sil shared [serializable] [thunk] @_T0{{.*}}1P{{.*}}1p{{.*}} : $@convention(method) <Self where Self : P> (@owned String, @guaranteed Self) -> ()
14+
func foo(x: Bool, y: C & P) -> (String) -> () {
15+
return x ? y.c : y.p
16+
}

0 commit comments

Comments
 (0)