Skip to content

Commit 7d65012

Browse files
committed
SILGen: use the correct forwarding substitutions for the setter of an assign_by_wrapper.
Fixes a crash when a function, which assigns to a wrapped property has additional generic parameters. https://bugs.swift.org/browse/SR-11484 rdar://problem/55442328
1 parent 3e48f71 commit 7d65012

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

lib/SILGen/SILGenLValue.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,8 +1427,6 @@ namespace {
14271427
// Create the allocating setter function. It captures the base address.
14281428
auto setterInfo = SGF.getConstantInfo(setter);
14291429
SILValue setterFRef = SGF.emitGlobalFunctionRef(loc, setter, setterInfo);
1430-
auto setterSubs = SGF.getFunction().getForwardingSubstitutionMap();
1431-
14321430
CanSILFunctionType setterTy = setterFRef->getType().castTo<SILFunctionType>();
14331431
SILFunctionConventions setterConv(setterTy, SGF.SGM.M);
14341432

@@ -1442,7 +1440,7 @@ namespace {
14421440

14431441
PartialApplyInst *setterPAI =
14441442
SGF.B.createPartialApply(loc, setterFRef,
1445-
setterSubs, { capturedBase },
1443+
Substitutions, { capturedBase },
14461444
ParameterConvention::Direct_Guaranteed);
14471445
ManagedValue setterFn = SGF.emitManagedRValueWithCleanup(setterPAI);
14481446

test/SILOptimizer/di_property_wrappers.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ struct IntStruct {
6161
}
6262
wrapped = 27
6363
}
64+
65+
// Check that we don't crash if the function has unrelated generic parameters.
66+
// SR-11484
67+
mutating func setit<V>(_ v: V) {
68+
wrapped = 5
69+
}
6470
}
6571

6672
final class IntClass {
@@ -142,10 +148,15 @@ func testIntStruct() {
142148

143149
// CHECK-NEXT: .. init 42
144150
// CHECK-NEXT: .. set 27
145-
let t1 = IntStruct()
151+
var t1 = IntStruct()
146152
// CHECK-NEXT: 27
147153
print(t1.wrapped)
148154

155+
// CHECK-NEXT: .. set 5
156+
t1.setit(false)
157+
// CHECK-NEXT: 5
158+
print(t1.wrapped)
159+
149160
// CHECK-NEXT: .. init 42
150161
let t2 = IntStruct(conditional: false)
151162
// CHECK-NEXT: 42

0 commit comments

Comments
 (0)