Skip to content

Commit 6e05e3c

Browse files
committed
Handle startAsyncLetWithLocalBuffer in exclusivity diagnostics.
Fixes rdar://128981120 (Crash when inout arg captured through some closures? (llvm::all_of(apply->getUses(), hasExpectedUsesOfNoEscapePartialApply) && "noescape partial_apply has unexpected use!")) (cherry picked from commit 1be703c)
1 parent 613b321 commit 6e05e3c

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

lib/SILOptimizer/Analysis/AccessSummaryAnalysis.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,15 @@ static bool hasExpectedUsesOfNoEscapePartialApply(Operand *partialApplyUse) {
242242
// destroy_value %storage : $@callee_owned () -> ()
243243
return true;
244244
default:
245-
return false;
245+
break;
246246
}
247+
if (auto *startAsyncLet = dyn_cast<BuiltinInst>(user)) {
248+
if (startAsyncLet->getBuiltinKind() ==
249+
BuiltinValueKind::StartAsyncLetWithLocalBuffer) {
250+
return true;
251+
}
252+
}
253+
return false;
247254
}
248255
#endif
249256

test/SILOptimizer/access_summary_analysis.sil

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,3 +521,38 @@ entry:
521521
%t = tuple ()
522522
return %t : $()
523523
}
524+
525+
sil [ossa] @asyncIntClosure : $@convention(thin) @async (@inout_aliasable Builtin.Int64) -> (@out Builtin.Int64, @error any Error) {
526+
bb0(%0 : $*Builtin.Int64, %1: $*Builtin.Int64):
527+
%2 = begin_access [modify] [unknown] %0 : $*Builtin.Int64
528+
%3 = load [trivial] %1 : $*Builtin.Int64
529+
assign %3 to %2 : $*Builtin.Int64
530+
end_access %2 : $*Builtin.Int64
531+
%4 = tuple ()
532+
return %4 : $()
533+
}
534+
535+
sil @swift_asyncLet_finish : $@convention(thin) @async (Builtin.RawPointer, Builtin.RawPointer) -> ()
536+
537+
// CHECK-LABEL: @partial_apply_asynclet
538+
sil [ossa] @partial_apply_asynclet : $@convention(thin) @async (@inout_aliasable Builtin.Int64) -> () {
539+
bb0(%0 : $*Builtin.Int64):
540+
%i = alloc_stack $Builtin.Int64
541+
%p = address_to_pointer %i : $*Builtin.Int64 to $Builtin.RawPointer
542+
%o = enum $Optional<Builtin.RawPointer>, #Optional.none!enumelt
543+
%x = enum $Optional<Builtin.Executor>, #Optional.none!enumelt
544+
%f = function_ref @asyncIntClosure : $@convention(thin) @async (@inout_aliasable Builtin.Int64) -> (@out Builtin.Int64, @error any Error)
545+
%e = partial_apply [callee_guaranteed] %f(%0) : $@convention(thin) @async (@inout_aliasable Builtin.Int64) -> (@out Builtin.Int64, @error any Error)
546+
%a = convert_function %e : $@async @callee_guaranteed () -> (@out Builtin.Int64, @error any Error) to $@async @callee_guaranteed @substituted <τ_0_0> () -> (@sil_sending @out τ_0_0, @error any Error) for <Builtin.Int64>
547+
%n = convert_escape_to_noescape [not_guaranteed] %a : $@async @callee_guaranteed @substituted <τ_0_0> () -> (@sil_sending @out τ_0_0, @error any Error) for <Builtin.Int64> to $@noescape @async @callee_guaranteed @substituted <τ_0_0> () -> (@sil_sending @out τ_0_0, @error any Error) for <Builtin.Int64>
548+
%sl = builtin "startAsyncLetWithLocalBuffer"<Builtin.Int64>(%o : $Optional<Builtin.RawPointer>, %n : $@noescape @async @callee_guaranteed @substituted <τ_0_0> () -> (@sil_sending @out τ_0_0, @error any Error) for <Builtin.Int64>, %p : $Builtin.RawPointer) : $Builtin.RawPointer
549+
%fn = function_ref @swift_asyncLet_finish : $@convention(thin) @async (Builtin.RawPointer, Builtin.RawPointer) -> ()
550+
%ap = apply %fn(%sl, %p) : $@convention(thin) @async (Builtin.RawPointer, Builtin.RawPointer) -> ()
551+
hop_to_executor %x : $Optional<Builtin.Executor>
552+
%el = builtin "endAsyncLetLifetime"(%sl : $Builtin.RawPointer) : $()
553+
destroy_value %n : $@noescape @async @callee_guaranteed @substituted <τ_0_0> () -> (@sil_sending @out τ_0_0, @error any Error) for <Builtin.Int64>
554+
destroy_value %a : $@async @callee_guaranteed @substituted <τ_0_0> () -> (@sil_sending @out τ_0_0, @error any Error) for <Builtin.Int64>
555+
dealloc_stack %i : $*Builtin.Int64
556+
%t = tuple ()
557+
return %t : $()
558+
}

0 commit comments

Comments
 (0)