Skip to content

Commit c07ba10

Browse files
committed
Auto merge of #142546 - cjgillot:reachable-jump, r=<try>
Only traverse reachable blocks in JumpThreading. Fixes #131451 We only compute loop headers for reachable blocks. We shouldn't try to perform an opt on unreachable blocks anyway.
2 parents 586ad39 + 89b079d commit c07ba10

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

compiler/rustc_mir_transform/src/jump_threading.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl<'tcx> crate::MirPass<'tcx> for JumpThreading {
8989
opportunities: Vec::new(),
9090
};
9191

92-
for bb in body.basic_blocks.indices() {
92+
for (bb, _) in traversal::preorder(body) {
9393
finder.start_from_switch(bb);
9494
}
9595

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
//@ known-bug: #131451
1+
//@ build-pass
22
//@ needs-rustc-debug-assertions
33
//@ compile-flags: -Zmir-enable-passes=+GVN -Zmir-enable-passes=+JumpThreading --crate-type=lib
44

55
pub fn fun(terminate: bool) {
66
while true {}
7+
//~^ WARN denote infinite loops with `loop { ... }`
78

89
while !terminate {}
910
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
warning: denote infinite loops with `loop { ... }`
2+
--> $DIR/unreachable-loop-jump-threading.rs:6:5
3+
|
4+
LL | while true {}
5+
| ^^^^^^^^^^ help: use `loop`
6+
|
7+
= note: `#[warn(while_true)]` on by default
8+
9+
warning: 1 warning emitted
10+

0 commit comments

Comments
 (0)