Skip to content

Commit 7ad1a18

Browse files
committed
Fix store_borrow's end_borrows in GenericCloner when lifetime boundary cannot be found
Make sure end_borrows are inserted before dealloc_stack. Instead of inserting them at function exits. Insert before dealloc_stack of destination.
1 parent 81351da commit 7ad1a18

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

lib/SILOptimizer/Utils/GenericCloner.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,9 @@ void GenericCloner::postFixUp(SILFunction *f) {
260260
scopedAddress.endScopeAtLivenessBoundary(&storeBorrowLiveness);
261261
continue;
262262
}
263-
for (auto *exit : FunctionExits) {
264-
scopedAddress.createScopeEnd(exit->getIterator(),
263+
auto *alloc = cast<AllocStackInst>(sbi->getDest());
264+
for (auto *dealloc : alloc->getUsersOfType<DeallocStackInst>()) {
265+
scopedAddress.createScopeEnd(dealloc->getIterator(),
265266
RegularLocation::getAutoGeneratedLocation());
266267
}
267268
}

test/SIL/store_borrow_verify_errors.sil

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// RUN: %target-sil-opt -verify-continue-on-failure -enable-sil-verify-all=0 %s -o /dev/null 2>&1 | %FileCheck %s
1+
// RUN: %target-sil-opt -dont-abort-on-memory-lifetime-errors -verify-continue-on-failure -enable-sil-verify-all=0 %s -o /dev/null 2>&1 | %FileCheck %s
2+
3+
// Memory lifetime verifier also raises errors in some of these cases, add dont-abort-on-memory-lifetime-errors so that we don't check it's output.
4+
// Memory lifetime verifier cannot subsume this because the verification is disabled on unreachable paths.
25

36
import Builtin
47

test/SILOptimizer/specialize_ossa.sil

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ bb0(%0 : $Builtin.NativeObject):
3232
return %9999 : $()
3333
}
3434

35+
// CHECK-LABEL: sil shared [noinline] [ossa] @$s33XXX_foo_guaranteed_generic_returnBo_Tg5 :
36+
// CHECK: [[S1:%.*]] = alloc_stack $Builtin.NativeObject
37+
// CHECK: [[S2:%.*]] = alloc_stack $Builtin.NativeObject
38+
// CHECK: [[SBI:%.*]] = store_borrow %0 to [[S2]] : $*Builtin.NativeObject
39+
// CHECK: end_borrow [[SBI]] : $*Builtin.NativeObject
40+
// CHECK: dealloc_stack [[S2]] : $*Builtin.NativeObject
41+
// CHECK-LABEL: } // end sil function '$s33XXX_foo_guaranteed_generic_returnBo_Tg5'
42+
3543
// CHECK-LABEL: sil [ossa] @exp1 : $@convention(thin) () -> () {
3644
// CHECK-NOT: apply
3745
// Call of specialized initializer: <Int32>
@@ -115,7 +123,6 @@ bb0(%0 : $*T, %1 : $*XXX<T>):
115123
return %9 : $Int32 // id: %11
116124
}
117125

118-
119126
sil [ossa] [noinline] @XXX_foo_guaranteed_generic_return : $@convention(method) <T> (@in_guaranteed T, @in XXX<T>) -> @out T {
120127
bb0(%0 : $*T, %1 : $*T, %2 : $*XXX<T>):
121128
%3 = address_to_pointer %1 : $*T to $Builtin.RawPointer

0 commit comments

Comments
 (0)