Skip to content

Commit eb48925

Browse files
authored
Merge pull request #79130 from eeckstein/fix-destroy-hoisting
DestroyHoisting: visit begin_borrows which don't have an end_borrow in dead-end blocks.
2 parents 8d2d1fc + 9b2dfbb commit eb48925

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/DestroyHoisting.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,15 @@ private extension InstructionRange {
188188
}
189189
defer { visitor.deinitialize() }
190190

191+
// This is important to visit begin_borrows which don't have an end_borrow in dead-end blocks.
192+
// TODO: we can remove this once we have complete lifetimes.
193+
visitor.innerScopeHandler = {
194+
if let inst = $0.definingInstruction {
195+
liverange.insert(inst)
196+
}
197+
return .continueWalk
198+
}
199+
191200
_ = visitor.visitUses()
192201
self = liverange
193202
}

test/SILOptimizer/destroy-hoisting.sil

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,3 +370,28 @@ bb0(%0 : @owned $Klass):
370370
%r = tuple ()
371371
return %r
372372
}
373+
374+
// CHECK-LABEL: sil [ossa] @borrow_in_deadend_block :
375+
// CHECK: bb1:
376+
// CHECK-NEXT: destroy_value %1
377+
// CHECK-NEXT: destroy_value %2
378+
// CHECK: } // end sil function 'borrow_in_deadend_block'
379+
sil [ossa] @borrow_in_deadend_block : $@convention(thin) (@in Klass) -> () {
380+
bb0(%0 : $*Klass):
381+
%1 = load [take] %0
382+
%2 = copy_value %1
383+
%3 = begin_borrow %1
384+
end_borrow %3
385+
cond_br undef, bb1, bb2
386+
387+
bb1:
388+
destroy_value %1
389+
destroy_value %2
390+
%8 = tuple ()
391+
return %8
392+
393+
bb2:
394+
%10 = begin_borrow %1
395+
unreachable
396+
}
397+

0 commit comments

Comments
 (0)