]> git.lizzy.rs Git - rust.git/commitdiff
Fix change detection in CfgSimplifier::collapse_goto_chain
authorTomasz Miąsko <tomasz.miasko@gmail.com>
Mon, 3 Aug 2020 00:00:00 +0000 (00:00 +0000)
committerTomasz Miąsko <tomasz.miasko@gmail.com>
Sun, 2 Aug 2020 22:39:53 +0000 (00:39 +0200)
Check that the old target is different from the new collapsed one,
before concluding that anything changed.

src/librustc_mir/transform/simplify.rs
src/test/ui/issues/issue-75704.rs [new file with mode: 0644]

index 9288d6e16f5e079e8937a78c521102d1944bb91e..acf8c0181ce7b5e8709285ab5cb21763e8673d13 100644 (file)
@@ -212,6 +212,7 @@ fn collapse_goto_chain(&mut self, start: &mut BasicBlock, changed: &mut bool) {
                 Terminator { kind: TerminatorKind::Goto { ref mut target }, .. } => target,
                 _ => unreachable!(),
             };
+            *changed |= *target != last;
             *target = last;
             debug!("collapsing goto chain from {:?} to {:?}", current, target);
 
@@ -223,7 +224,6 @@ fn collapse_goto_chain(&mut self, start: &mut BasicBlock, changed: &mut bool) {
                 self.pred_count[*target] += 1;
                 self.pred_count[current] -= 1;
             }
-            *changed = true;
             self.basic_blocks[current].terminator = Some(terminator);
         }
     }
diff --git a/src/test/ui/issues/issue-75704.rs b/src/test/ui/issues/issue-75704.rs
new file mode 100644 (file)
index 0000000..aed7ddb
--- /dev/null
@@ -0,0 +1,7 @@
+// Caused an infinite loop during SimlifyCfg MIR transform previously.
+//
+// build-pass
+
+fn main() {
+    loop { continue; }
+}