Skip to content

Commit 0073512

Browse files
committed
MemBehavior: handle begin_access when checking for apply side-effects.
1 parent b3e9a7f commit 0073512

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/SILOptimizer/Analysis/MemoryBehavior.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ static bool hasEscapingUses(SILValue address, int &numChecks) {
364364
case SILInstructionKind::CopyAddrInst:
365365
case SILInstructionKind::DestroyAddrInst:
366366
case SILInstructionKind::DeallocStackInst:
367+
case SILInstructionKind::EndAccessInst:
367368
// Those instructions have no result and cannot escape the address.
368369
break;
369370
case SILInstructionKind::ApplyInst:
@@ -373,6 +374,7 @@ static bool hasEscapingUses(SILValue address, int &numChecks) {
373374
// possible that an address, passed as an indirect parameter, escapes
374375
// the function in any way (which is not unsafe and undefined behavior).
375376
break;
377+
case SILInstructionKind::BeginAccessInst:
376378
case SILInstructionKind::OpenExistentialAddrInst:
377379
case SILInstructionKind::UncheckedTakeEnumDataAddrInst:
378380
case SILInstructionKind::StructElementAddrInst:

test/SILOptimizer/mem-behavior.sil

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ bb2(%8 : $Error):
269269
unreachable
270270
}
271271

272-
273272
// CHECK-LABEL: @beginapply_allocstack_and_copyaddr
274273
// CHECK: PAIR #0.
275274
// CHECK-NEXT: (%4, %5) = begin_apply %3(%0) : $@yield_once @convention(thin) (@in Int32) -> @yields Int32
@@ -324,6 +323,23 @@ bb0(%0 : $X):
324323
return %3 : $Int32
325324
}
326325

326+
// CHECK-LABEL: @apply_and_begin_access
327+
// CHECK: PAIR #0.
328+
// CHECK-NEXT: %6 = apply %5(%1) : $@convention(thin) (@in Int32) -> Int32
329+
// CHECK-NEXT: %0 = argument of bb0 : $*Int32
330+
// CHECK-NEXT: r=0,w=0
331+
sil @apply_and_begin_access : $@convention(thin) (@in Int32) -> Int32 {
332+
bb0(%0 : $*Int32):
333+
%1 = alloc_stack $Int32
334+
%2 = begin_access [read] [static] %0 : $*Int32
335+
copy_addr %2 to %1 : $*Int32
336+
end_access %2 : $*Int32
337+
%5 = function_ref @single_indirect_arg : $@convention(thin) (@in Int32) -> Int32
338+
%6 = apply %5(%1) : $@convention(thin) (@in Int32) -> Int32
339+
dealloc_stack %1 : $*Int32
340+
return %6 : $Int32
341+
}
342+
327343
sil @load_from_in : $@convention(thin) (@in X) -> () {
328344
bb0(%0 : $*X):
329345
%1 = load %0 : $*X

0 commit comments

Comments
 (0)