Skip to content

Commit 0db10e9

Browse files
author
Joe Shajrawi
authored
Merge pull request #9290 from shajrawi/firefox_crash
Fixes a bug in large loadable types wherein only the callee type of Apply is changed
2 parents cb7ad7d + 746fd28 commit 0db10e9

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

lib/IRGen/LoadableByAddress.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,19 @@ void LargeValueVisitor::visitApply(ApplySite applySite) {
472472
if (!isLargeLoadableType(genEnv, currType, pass.Mod) &&
473473
(currType != newType)) {
474474
pass.applies.push_back(applySite.getInstruction());
475+
return;
476+
}
477+
// Check callee - need new generic env:
478+
SILFunctionType *origSILFunctionType = applySite.getSubstCalleeType();
479+
GenericEnvironment *genEnvCallee = nullptr;
480+
if (origSILFunctionType->isPolymorphic()) {
481+
genEnvCallee = getGenericEnvironment(
482+
applySite.getModule(), CanSILFunctionType(origSILFunctionType));
483+
}
484+
SILFunctionType *newSILFunctionType =
485+
getNewSILFunctionTypePtr(genEnvCallee, origSILFunctionType, pass.Mod);
486+
if (origSILFunctionType != newSILFunctionType) {
487+
pass.applies.push_back(applySite.getInstruction());
475488
}
476489
}
477490

test/IRGen/big_types_corner_cases.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,25 @@ public func f3_uses_f2() {
3131
// CHECK: call swiftcc { i8*, %swift.refcounted* } @_T022big_types_corner_cases13f2_returns_f1AA9BigStructVADcyF()
3232
// CHECK: call swiftcc void %16(%T22big_types_corner_cases9BigStructV* noalias nocapture sret %call.aggresult1, %T22big_types_corner_cases9BigStructV* noalias nocapture dereferenceable
3333
// CHECK: ret void
34+
35+
public struct MyStruct {
36+
public let a: Int
37+
public let b: String?
38+
}
39+
40+
typealias UploadFunction = ((MyStruct, Int?) -> Void) -> Void
41+
func takesUploader(_ u: UploadFunction) { }
42+
43+
class Foo {
44+
func blam() {
45+
takesUploader(self.myMethod) // crash compiling this
46+
}
47+
48+
func myMethod(_ callback: (MyStruct, Int) -> Void) -> Void { }
49+
}
50+
51+
// CHECK-LABEL: define{{( protected)?}} linkonce_odr hidden swiftcc { i8*, %swift.refcounted* } @_T022big_types_corner_cases3FooC8myMethodyyAA8MyStructV_SitcFTc(%T22big_types_corner_cases3FooC*)
52+
// CHECK: getelementptr inbounds %T22big_types_corner_cases3FooC, %T22big_types_corner_cases3FooC*
53+
// CHECK: getelementptr inbounds void (i8*, %swift.refcounted*, %T22big_types_corner_cases3FooC*)*, void (i8*, %swift.refcounted*, %T22big_types_corner_cases3FooC*)**
54+
// CHECK: call noalias %swift.refcounted* @swift_rt_swift_allocObject(%swift.type* getelementptr inbounds (%swift.full_boxmetadata, %swift.full_boxmetadata*
55+
// CHECK: ret { i8*, %swift.refcounted* }

0 commit comments

Comments
 (0)