Skip to content

SILGen: Fix crash when emitting foreign-to-native thunk for allocating init in -swift-version 5 #19255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/SILGen/SILGenBridging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1613,7 +1613,8 @@ void SILGenFunction::emitForeignToNativeThunk(SILDeclRef thunk) {
Type allocatorSelfType;
if (thunk.kind == SILDeclRef::Kind::Allocator) {
auto *selfDecl = fd->getImplicitSelfDecl();
allocatorSelfType = F.mapTypeIntoContext(selfDecl->getInterfaceType());
allocatorSelfType = F.mapTypeIntoContext(
fd->getDeclContext()->getSelfInterfaceType());

auto selfMetatype =
CanMetatypeType::get(allocatorSelfType->getCanonicalType());
Expand Down
1 change: 1 addition & 0 deletions test/SILGen/Inputs/usr/include/Gizmo.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ typedef long NSInteger;
- (Gizmo*) init OBJC_DESIGNATED_INITIALIZER;
- (Gizmo*) initWithBellsOn:(NSInteger)x OBJC_DESIGNATED_INITIALIZER;
- (instancetype) initWithoutBells:(NSInteger)x;
+ (instancetype) gizmoWithWhistles:(NSInteger)x;
- (void) fork NS_CONSUMES_SELF;
- (void) enumerateSubGizmos: (void (^ _Nullable)(Gizmo*))f;
+ (void) consume: (NS_CONSUMED Gizmo*) gizmo;
Expand Down
10 changes: 10 additions & 0 deletions test/SILGen/objc_thunks.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

// 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
// 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

// REQUIRES: objc_interop

Expand Down Expand Up @@ -592,3 +593,12 @@ func testObjCNoescapeThunk() {
// CHECK-NEXT: [[T4:%.*]] = tuple ()
// CHECK-NEXT: end_borrow [[T2]]
// CHECK-NEXT: return [[T4]]

// Call a convenience initializer
func buildGizmo1() -> Gizmo {
return Gizmo(outBells: 10)
}

func buildGizmo2() -> Gizmo {
return Gizmo(whistles: 10)
}