Skip to content

Commit c69d43e

Browse files
committed
SILGen: Fix crash when emitting foreign-to-native thunk for allocating init in -swift-version 5
This comes up when we import a static factory method as a convenience init. The thunk was using DynamicSelfType as the type of a basic block argument, because that was the type of the 'self' parameter in -swift-version 5. Fixes <rdar://problem/44242156>.
1 parent 2cfea1f commit c69d43e

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

lib/SILGen/SILGenBridging.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1613,7 +1613,8 @@ void SILGenFunction::emitForeignToNativeThunk(SILDeclRef thunk) {
16131613
Type allocatorSelfType;
16141614
if (thunk.kind == SILDeclRef::Kind::Allocator) {
16151615
auto *selfDecl = fd->getImplicitSelfDecl();
1616-
allocatorSelfType = F.mapTypeIntoContext(selfDecl->getInterfaceType());
1616+
allocatorSelfType = F.mapTypeIntoContext(
1617+
fd->getDeclContext()->getSelfInterfaceType());
16171618

16181619
auto selfMetatype =
16191620
CanMetatypeType::get(allocatorSelfType->getCanonicalType());

test/SILGen/Inputs/usr/include/Gizmo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ typedef long NSInteger;
3939
- (Gizmo*) init OBJC_DESIGNATED_INITIALIZER;
4040
- (Gizmo*) initWithBellsOn:(NSInteger)x OBJC_DESIGNATED_INITIALIZER;
4141
- (instancetype) initWithoutBells:(NSInteger)x;
42+
+ (instancetype) gizmoWithWhistles:(NSInteger)x;
4243
- (void) fork NS_CONSUMES_SELF;
4344
- (void) enumerateSubGizmos: (void (^ _Nullable)(Gizmo*))f;
4445
+ (void) consume: (NS_CONSUMED Gizmo*) gizmo;

test/SILGen/objc_thunks.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
// RUN: %target-swift-emit-silgen -module-name objc_thunks -Xllvm -sil-full-demangle -Xllvm -sil-print-debuginfo -sdk %S/Inputs -I %S/Inputs -enable-source-import %s -emit-verbose-sil -enable-sil-ownership | %FileCheck %s
3+
// RUN: %target-swift-emit-silgen -module-name objc_thunks -Xllvm -sil-full-demangle -Xllvm -sil-print-debuginfo -sdk %S/Inputs -I %S/Inputs -enable-source-import %s -emit-verbose-sil -enable-sil-ownership -swift-version 5 | %FileCheck %s
34

45
// REQUIRES: objc_interop
56

@@ -592,3 +593,12 @@ func testObjCNoescapeThunk() {
592593
// CHECK-NEXT: [[T4:%.*]] = tuple ()
593594
// CHECK-NEXT: end_borrow [[T2]]
594595
// CHECK-NEXT: return [[T4]]
596+
597+
// Call a convenience initializer
598+
func buildGizmo1() -> Gizmo {
599+
return Gizmo(outBells: 10)
600+
}
601+
602+
func buildGizmo2() -> Gizmo {
603+
return Gizmo(whistles: 10)
604+
}

0 commit comments

Comments
 (0)