File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -912,7 +912,13 @@ SILValue swift::findOwnershipReferenceAggregate(SILValue ref) {
912912 || isa<OwnershipForwardingConversionInst>(root)
913913 || isa<OwnershipForwardingSelectEnumInstBase>(root)
914914 || isa<OwnershipForwardingMultipleValueInstruction>(root)) {
915- root = root->getDefiningInstruction ()->getOperand (0 );
915+ SILInstruction *inst = root->getDefiningInstruction ();
916+
917+ // The `enum` instruction can have no operand.
918+ if (inst->getNumOperands () == 0 )
919+ return root;
920+
921+ root = inst->getOperand (0 );
916922 continue ;
917923 }
918924 if (auto *arg = dyn_cast<SILArgument>(root)) {
Original file line number Diff line number Diff line change @@ -699,6 +699,28 @@ bb4:
699699 return %5 : $Int32
700700}
701701
702+ // CHECK-LABEL: @dontCrashWithOptionalNone
703+ // CHECK: PAIR #0.
704+ // CHECK-NEXT: %6 = apply %5() : $@convention(thin) () -> ()
705+ // CHECK-NEXT: %4 = ref_element_addr [immutable] %3 : $X, #X.a
706+ // CHECK-NEXT: r=1,w=1
707+ sil @dontCrashWithOptionalNone : $@convention(thin) () -> () {
708+ bb0:
709+ %26 = enum $Optional<X>, #Optional.none!enumelt
710+ switch_enum %26 : $Optional<X>, case #Optional.none!enumelt: bb1, case #Optional.some!enumelt: bb2
711+ bb1:
712+ br bb3
713+ bb2:
714+ %68 = unchecked_enum_data %26 : $Optional<X>, #Optional.some!enumelt
715+ %1 = ref_element_addr [immutable] %68 : $X, #X.a
716+ %5 = function_ref @nouser_func : $@convention(thin) () -> ()
717+ %6 = apply %5() : $@convention(thin) () -> ()
718+ br bb3
719+ bb3:
720+ %r = tuple ()
721+ return %r : $()
722+ }
723+
702724// CHECK-LABEL: @testLoadTake
703725// CHECK: PAIR #0.
704726// CHECK-NEXT: %2 = load [take] %0 : $*C
You can’t perform that action at this time.
0 commit comments