Skip to content

Commit 5562bb6

Browse files
committed
Auto merge of #76748 - tmiasko:no-op-jumps, r=matthewjasper
Fix underflow when calculating the number of no-op jumps folded When removing unwinds to no-op blocks and folding jumps to no-op blocks, remove the unwind target first. Otherwise we cannot determine if target has been already folded or not. Previous implementation incorrectly assumed that all resume targets had been folded already, occasionally resulting in an underflow: ``` remove_noop_landing_pads: removed 18446744073709551613 jumps and 3 landing pads ```
2 parents 78a0894 + ff1a9e4 commit 5562bb6

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

compiler/rustc_mir/src/transform/remove_noop_landing_pads.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,16 @@ impl RemoveNoopLandingPads {
102102
let postorder: Vec<_> = traversal::postorder(body).map(|(bb, _)| bb).collect();
103103
for bb in postorder {
104104
debug!(" processing {:?}", bb);
105+
if let Some(unwind) = body[bb].terminator_mut().unwind_mut() {
106+
if let Some(unwind_bb) = *unwind {
107+
if nop_landing_pads.contains(unwind_bb) {
108+
debug!(" removing noop landing pad");
109+
landing_pads_removed += 1;
110+
*unwind = None;
111+
}
112+
}
113+
}
114+
105115
for target in body[bb].terminator_mut().successors_mut() {
106116
if *target != resume_block && nop_landing_pads.contains(*target) {
107117
debug!(" folding noop jump to {:?} to resume block", target);
@@ -110,15 +120,6 @@ impl RemoveNoopLandingPads {
110120
}
111121
}
112122

113-
if let Some(unwind) = body[bb].terminator_mut().unwind_mut() {
114-
if *unwind == Some(resume_block) {
115-
debug!(" removing noop landing pad");
116-
jumps_folded -= 1;
117-
landing_pads_removed += 1;
118-
*unwind = None;
119-
}
120-
}
121-
122123
let is_nop_landing_pad = self.is_nop_landing_pad(bb, body, &nop_landing_pads);
123124
if is_nop_landing_pad {
124125
nop_landing_pads.insert(bb);

0 commit comments

Comments
 (0)