Skip to content

Commit 454b98e

Browse files
authored
Merge pull request #67391 from eeckstein/fix-stack-promotion-5.9
[5.9] StackPromotion: fix a crash due to a problem in liferange evaluation
2 parents c56aa07 + 4708990 commit 454b98e

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/StackPromotion.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,13 @@ private extension BasicBlockRange {
268268
/// Returns true if there is a direct edge connecting this range with the `otherRange`.
269269
func hasControlFlowEdge(to otherRange: BasicBlockRange) -> Bool {
270270
func isOnlyInOtherRange(_ block: BasicBlock) -> Bool {
271-
return !inclusiveRangeContains(block) &&
272-
otherRange.inclusiveRangeContains(block) && block != otherRange.begin
271+
return !inclusiveRangeContains(block) && otherRange.inclusiveRangeContains(block)
273272
}
274273

275274
for lifeBlock in inclusiveRange {
276275
assert(otherRange.inclusiveRangeContains(lifeBlock), "range must be a subset of other range")
277276
for succ in lifeBlock.successors {
278-
if isOnlyInOtherRange(succ) {
277+
if isOnlyInOtherRange(succ) && succ != otherRange.begin {
279278
return true
280279
}
281280
// The entry of the begin-block is conceptually not part of the range. We can check if

test/SILOptimizer/stack_promotion.sil

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,3 +1156,28 @@ bb0(%0 : $UnownedLink):
11561156
%r = tuple ()
11571157
return %r : $()
11581158
}
1159+
1160+
// CHECK-LABEL: sil @inner_liferange_jumps_to_outer_in_header_block
1161+
// CHECK: alloc_ref $XX
1162+
// CHECK-LABEL: } // end sil function 'inner_liferange_jumps_to_outer_in_header_block'
1163+
sil @inner_liferange_jumps_to_outer_in_header_block : $@convention(thin) (@owned XX) -> () {
1164+
bb0(%0 : $XX):
1165+
%1 = alloc_stack $XX
1166+
br bb1(%0 : $XX)
1167+
1168+
bb1(%2 : $XX):
1169+
strong_release %2 : $XX
1170+
%4 = alloc_ref $XX
1171+
store %4 to %1 : $*XX
1172+
cond_br undef, bb2, bb3
1173+
1174+
bb2:
1175+
br bb1(%4 : $XX)
1176+
1177+
bb3:
1178+
strong_release %4 : $XX
1179+
dealloc_stack %1 : $*XX
1180+
%r = tuple ()
1181+
return %r : $()
1182+
}
1183+

0 commit comments

Comments
 (0)