Skip to content

Commit 5413488

Browse files
committed
SILGen: Fix crash in emitEnumConstructor() if type lowering depends on resilience
It's possible that the result value here is passed indirectly, but the enum value is loadable inside the constructor's body. Let's make sure we handle this correctly. Fixes https://bugs.swift.org/browse/SR-12966 / rdar://problem/70395861.
1 parent 527fb5d commit 5413488

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/SILGen/SILGenConstructor.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,11 @@ void SILGenFunction::emitEnumConstructor(EnumElementDecl *element) {
544544
// Return the enum.
545545
auto ReturnLoc = ImplicitReturnLocation::getImplicitReturnLoc(Loc);
546546

547-
if (mv.isInContext()) {
548-
assert(enumTI.isAddressOnly());
547+
if (dest) {
548+
if (!mv.isInContext()) {
549+
dest->copyOrInitValueInto(*this, Loc, mv, /*isInit*/ true);
550+
dest->finishInitialization(*this);
551+
}
549552
scope.pop();
550553
B.createReturn(ReturnLoc, emitEmptyTuple(Loc));
551554
} else {

test/SILGen/protocol_enum_witness.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ public enum AnotherBar: AnotherFoo {
1717
case bar(arg: Int)
1818
}
1919

20+
public struct PublicStruct {}
21+
22+
enum InternalEnumWithPublicStruct : Foo {
23+
case button
24+
case other(PublicStruct)
25+
}
26+
2027
// CHECK-LABEL: sil shared [transparent] [serialized] [thunk] [ossa] @$s21protocol_enum_witness3BarOAA3FooA2aDP6buttonxvgZTW : $@convention(witness_method: Foo) (@thick Bar.Type) -> @out Bar {
2128
// CHECK: bb0([[BAR:%.*]] : $*Bar, [[BAR_TYPE:%.*]] : $@thick Bar.Type):
2229
// CHECK-NEXT: [[META_TYPE:%.*]] = metatype $@thin Bar.Type

0 commit comments

Comments
 (0)