From 54896273106b810bffd3c1622b7cdac990f8fd05 Mon Sep 17 00:00:00 2001 From: Erik Eckstein Date: Wed, 11 Jun 2025 13:34:14 +0200 Subject: [PATCH] LowerHopToActor: insert a borrow scope for an `Optional.none` value An optional-none value has "none" ownership, but still a borrow scope is needed. Fixes a SIL verifier crash. rdar://153066034 --- lib/SILOptimizer/Mandatory/LowerHopToActor.cpp | 2 +- test/SILOptimizer/lower_hop_to_actor.sil | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/SILOptimizer/Mandatory/LowerHopToActor.cpp b/lib/SILOptimizer/Mandatory/LowerHopToActor.cpp index 90b2a78328d6f..0941e312795c7 100644 --- a/lib/SILOptimizer/Mandatory/LowerHopToActor.cpp +++ b/lib/SILOptimizer/Mandatory/LowerHopToActor.cpp @@ -273,7 +273,7 @@ SILValue LowerHopToActor::emitGetExecutor(SILBuilderWithScope &B, if (auto wrappedActor = actorType->getOptionalObjectType()) { assert(makeOptional); - if (B.hasOwnership() && actor->getOwnershipKind() == OwnershipKind::Owned) { + if (B.hasOwnership() && actor->getOwnershipKind() != OwnershipKind::Guaranteed) { actor = B.createBeginBorrow(loc, actor); needEndBorrow = true; } diff --git a/test/SILOptimizer/lower_hop_to_actor.sil b/test/SILOptimizer/lower_hop_to_actor.sil index c24e5888ee7f6..c594b5b142dc8 100644 --- a/test/SILOptimizer/lower_hop_to_actor.sil +++ b/test/SILOptimizer/lower_hop_to_actor.sil @@ -307,3 +307,17 @@ bb0(%0 : @guaranteed $Optional): return %r } +// CHECK-LABEL: sil [ossa] @optional_none : +// CHECK: %0 = enum +// CHECK-NEXT: %1 = begin_borrow %0 +// CHECK-NEXT: switch_enum %1 +// CHECK: mark_dependence +// CHECK-NEXT: end_borrow %1 +// CHECKL: } // end sil function '@optional_none' +sil [ossa] @optional_none : $@convention(thin) @async () -> () { +bb0: + %0 = enum $Optional, #Optional.none!enumelt + hop_to_executor %0 + %r = tuple () + return %r +}