Skip to content

Commit 0c3e6e2

Browse files
committed
FunctionSignatureOpts: fix a crash due to a missing argument declaration
The existential -> generic transformation in FSO didn't preserve the argument declaration. This caused an assert to hit in a later FSO transformation. rdar://problem/61206439 https://bugs.swift.org/browse/SR-12487
1 parent 3d93968 commit 0c3e6e2

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

lib/SILOptimizer/FunctionSignatureTransforms/ExistentialTransform.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ void ExistentialSpecializerCloner::cloneArguments(
179179
NewF.getLoweredType(NewF.mapTypeIntoContext(GenericParam));
180180
GenericSILType = GenericSILType.getCategoryType(
181181
ArgDesc.Arg->getType().getCategory());
182-
auto *NewArg = ClonedEntryBB->createFunctionArgument(GenericSILType);
182+
auto *NewArg =
183+
ClonedEntryBB->createFunctionArgument(GenericSILType, ArgDesc.Decl);
183184
NewArg->setOwnershipKind(ValueOwnershipKind(
184185
NewF, GenericSILType, ArgDesc.Arg->getArgumentConvention()));
185186
// Determine the Conformances.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// RUN: %target-swift-frontend -module-name main -O -emit-sil -primary-file %s | %FileCheck %s
2+
3+
protocol P {
4+
func foo()
5+
}
6+
7+
public struct Inner {
8+
var x: Int
9+
var y: Int
10+
}
11+
12+
public struct S : P {
13+
var i: Inner
14+
15+
func foo() {
16+
print(i.x)
17+
}
18+
}
19+
20+
// Check that FSO does not crash due to a missing decl on the function argument.
21+
22+
// Following specializations should be done:
23+
// * FSO: existential to protocol constrained generic
24+
// * generic specialization <S>
25+
// * FSO: argument explosion
26+
27+
// CHECK-LABEL: sil shared [noinline] @$s4main6testityyAA1P_pFTf4e_nAA1SV_Tg5Tf4x_n : $@convention(thin) (Int) -> () {
28+
// CHECK-NEXT: // %0 "p"
29+
@inline(never)
30+
func testit(_ p: P) {
31+
p.foo()
32+
}
33+
34+
public func callit(s: S) {
35+
testit(s)
36+
}

0 commit comments

Comments
 (0)