Skip to content

Commit 44ac016

Browse files
committed
SimplifyCfg: don't incref target when collapsing a goto with 1 pred
1 parent ae51ccf commit 44ac016

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/librustc_mir/transform/simplify_cfg.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,16 @@ impl<'a, 'tcx: 'a> CfgSimplifier<'a, 'tcx> {
160160
debug!("collapsing goto chain from {:?} to {:?}", *start, target);
161161

162162
*changed |= *start != target;
163-
self.pred_count[target] += 1;
164-
self.pred_count[*start] -= 1;
163+
164+
if self.pred_count[*start] == 1 {
165+
// This is the last reference to *start, so the pred-count to
166+
// to target is moved into the current block.
167+
self.pred_count[*start] = 0;
168+
} else {
169+
self.pred_count[target] += 1;
170+
self.pred_count[*start] -= 1;
171+
}
172+
165173
*start = target;
166174
}
167175

0 commit comments

Comments
 (0)