Skip to content

Commit 9d0cd15

Browse files
committed
SILGen: Fix assert when bridging no-payload enum case to Any
It's possible for a value of a non-trivial type to have no cleanup, if the value was constructed from a no-payload enum case. Tweak the assert to check the value's ownership instead of checking the type. Fixes <https://bugs.swift.org/browse/SR-12000>, <rdar://problem/58455443>.
1 parent 3cec742 commit 9d0cd15

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/SILGen/SILGenBridging.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ static ManagedValue emitNativeToCBridgedNonoptionalValue(SILGenFunction &SGF,
730730
nativeType);
731731

732732
// Put the value into memory if necessary.
733-
assert(v.getType().isTrivial(SGF.F) || v.hasCleanup());
733+
assert(v.getOwnershipKind() == ValueOwnershipKind::None || v.hasCleanup());
734734
SILModuleConventions silConv(SGF.SGM.M);
735735
// bridgeAnything always takes an indirect argument as @in.
736736
// Since we don't have the SIL type here, check the current SIL stage/mode

test/SILGen/objc_bridging_any.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,15 @@ class SwiftAnyEnjoyer: NSIdLover, NSIdLoving {
690690
func takesId(viaProtocol x: Any) { }
691691
}
692692

693+
enum SillyOptional {
694+
case nothing
695+
case something(NSObject)
696+
}
693697

698+
func bridgeNoPayloadEnumCase(_ receiver: NSIdLover) {
699+
let value = SillyOptional.nothing
700+
receiver.takesId(value)
701+
}
694702

695703
// CHECK-LABEL: sil_witness_table shared [serialized] GenericOption: Hashable module objc_generics {
696704
// CHECK-NEXT: base_protocol Equatable: GenericOption: Equatable module objc_generics

0 commit comments

Comments
 (0)