Skip to content

Commit be7ffee

Browse files
authored
Merge pull request #67331 from eeckstein/fix-stack-promotion
StackPromotion: fix a crash due to a problem in liferange evaluation
2 parents 4961902 + 89b0de3 commit be7ffee

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/StackPromotion.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,14 +289,13 @@ private extension BasicBlockRange {
289289
/// Returns true if there is a direct edge connecting this range with the `otherRange`.
290290
func hasControlFlowEdge(to otherRange: BasicBlockRange) -> Bool {
291291
func isOnlyInOtherRange(_ block: BasicBlock) -> Bool {
292-
return !inclusiveRangeContains(block) &&
293-
otherRange.inclusiveRangeContains(block) && block != otherRange.begin
292+
return !inclusiveRangeContains(block) && otherRange.inclusiveRangeContains(block)
294293
}
295294

296295
for lifeBlock in inclusiveRange {
297296
assert(otherRange.inclusiveRangeContains(lifeBlock), "range must be a subset of other range")
298297
for succ in lifeBlock.successors {
299-
if isOnlyInOtherRange(succ) {
298+
if isOnlyInOtherRange(succ) && succ != otherRange.begin {
300299
return true
301300
}
302301
// The entry of the begin-block is conceptually not part of the range. We can check if

test/SILOptimizer/stack_promotion.sil

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,3 +1209,27 @@ bb3:
12091209
br bb3
12101210
}
12111211

1212+
// CHECK-LABEL: sil @inner_liferange_jumps_to_outer_in_header_block
1213+
// CHECK: alloc_ref $XX
1214+
// CHECK-LABEL: } // end sil function 'inner_liferange_jumps_to_outer_in_header_block'
1215+
sil @inner_liferange_jumps_to_outer_in_header_block : $@convention(thin) (@owned XX) -> () {
1216+
bb0(%0 : $XX):
1217+
%1 = alloc_stack $XX
1218+
br bb1(%0 : $XX)
1219+
1220+
bb1(%2 : $XX):
1221+
strong_release %2 : $XX
1222+
%4 = alloc_ref $XX
1223+
store %4 to %1 : $*XX
1224+
cond_br undef, bb2, bb3
1225+
1226+
bb2:
1227+
br bb1(%4 : $XX)
1228+
1229+
bb3:
1230+
strong_release %4 : $XX
1231+
dealloc_stack %1 : $*XX
1232+
%r = tuple ()
1233+
return %r : $()
1234+
}
1235+

0 commit comments

Comments
 (0)