File tree Expand file tree Collapse file tree 2 files changed +27
-10
lines changed
lib/SILOptimizer/Transforms Expand file tree Collapse file tree 2 files changed +27
-10
lines changed Original file line number Diff line number Diff line change @@ -419,10 +419,12 @@ void DCE::propagateLiveness(SILInstruction *I) {
419
419
SILBasicBlock *DCE::nearestUsefulPostDominator (SILBasicBlock *Block) {
420
420
// Find the nearest post-dominator that has useful instructions.
421
421
auto *PostDomNode = PDT->getNode (Block)->getIDom ();
422
- while (!LiveBlocks.count (PostDomNode->getBlock ()))
422
+ while (PostDomNode && !LiveBlocks.count (PostDomNode->getBlock ()))
423
423
PostDomNode = PostDomNode->getIDom ();
424
424
425
- return PostDomNode->getBlock ();
425
+ if (PostDomNode)
426
+ return PostDomNode->getBlock ();
427
+ return nullptr ;
426
428
}
427
429
428
430
// Replace the given conditional branching instruction with a plain
@@ -485,8 +487,11 @@ bool DCE::removeDead(SILFunction &F) {
485
487
// We want to replace dead terminators with unconditional branches to
486
488
// the nearest post-dominator that has useful instructions.
487
489
if (isa<TermInst>(Inst)) {
488
- replaceBranchWithJump (Inst,
489
- nearestUsefulPostDominator (Inst->getParent ()));
490
+ SILBasicBlock *postDom = nearestUsefulPostDominator (Inst->getParent ());
491
+ if (!postDom)
492
+ continue ;
493
+
494
+ replaceBranchWithJump (Inst, postDom);
490
495
Inst->eraseFromParent ();
491
496
BranchesChanged = true ;
492
497
Changed = true ;
Original file line number Diff line number Diff line change 1
1
// RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -enable-sil-verify-all -dce %s | %FileCheck %s
2
2
3
- // REQUIRES: rdar34013900
4
-
5
3
sil_stage canonical
6
4
7
5
import Builtin
59
57
return %18 : $()
60
58
}
61
59
62
- // We currently bail out on functions that have structurally infinite
63
- // loops.
64
60
// CHECK-LABEL: sil @dead3
65
61
sil @dead3 : $@convention(thin) () -> () {
66
62
bb0:
67
63
// CHECK: bb0
68
64
br bb1
69
65
// CHECK: bb1
70
66
bb1:
71
- // CHECK: integer_literal $Builtin.Int32, 0
72
- // CHECK: br bb1
67
+ // CHECK: bb1:
68
+ // CHECK-NEXT: br bb1
73
69
%0 = integer_literal $Builtin.Int32, 0
74
70
br bb1
75
71
}
@@ -247,3 +243,19 @@ bb0(%0 : $*Container):
247
243
return %90 : $()
248
244
}
249
245
246
+ // Check that DCE does not crash with an infinite loop through a cond_br.
247
+ // CHECK-LABEL: sil @deal_with_infinite_loop
248
+ // CHECK: cond_br
249
+ sil @deal_with_infinite_loop : $@convention(thin) () -> () {
250
+ bb0:
251
+ br bb1
252
+
253
+ bb1:
254
+ cond_br undef, bb2, bb3
255
+
256
+ bb2:
257
+ br bb1
258
+
259
+ bb3:
260
+ br bb1
261
+ }
You can’t perform that action at this time.
0 commit comments