Skip to content

Commit bba2480

Browse files
committed
---
yaml --- r: 273523 b: refs/heads/beta c: f976e22 h: refs/heads/master i: 273521: eeed65b 273519: a55c327
1 parent ba25742 commit bba2480

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2323
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
2424
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26-
refs/heads/beta: a61c1759c7297f09955409fffaa162c7a21f89a7
26+
refs/heads/beta: f976e222e97fdcb8ab66634c8910ce524f6804c9
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
2828
refs/heads/tmp: e06d2ad9fcd5027bcaac5b08fc9aa39a49d0ecd3
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/beta/src/librustc_mir/transform/simplify_cfg.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use rustc::middle::const_eval::ConstVal;
1212
use rustc::middle::ty::TyCtxt;
1313
use rustc::mir::repr::*;
1414
use rustc::mir::transform::{MirPass, Pass};
15+
use pretty;
1516
use syntax::ast::NodeId;
1617

1718
use super::remove_dead_blocks::RemoveDeadBlocks;
@@ -30,16 +31,22 @@ impl SimplifyCfg {
3031
let mut seen: Vec<BasicBlock> = Vec::with_capacity(8);
3132

3233
while mir.basic_block_data(target).statements.is_empty() {
33-
debug!("final_target: target={:?}", target);
34-
match mir.basic_block_data(target).terminator().kind {
35-
TerminatorKind::Goto { target: next } => {
36-
if seen.contains(&next) {
37-
return None;
34+
// NB -- terminator may have been swapped with `None`
35+
// below, in which case we have a cycle and just want
36+
// to stop
37+
if let Some(ref terminator) = mir.basic_block_data(target).terminator {
38+
match terminator.kind {
39+
TerminatorKind::Goto { target: next } => {
40+
if seen.contains(&next) {
41+
return None;
42+
}
43+
seen.push(next);
44+
target = next;
3845
}
39-
seen.push(next);
40-
target = next;
46+
_ => break
4147
}
42-
_ => break
48+
} else {
49+
break
4350
}
4451
}
4552

@@ -106,8 +113,11 @@ impl SimplifyCfg {
106113

107114
impl<'tcx> MirPass<'tcx> for SimplifyCfg {
108115
fn run_pass(&mut self, tcx: &TyCtxt<'tcx>, id: NodeId, mir: &mut Mir<'tcx>) {
116+
let mut counter = 0;
109117
let mut changed = true;
110118
while changed {
119+
pretty::dump_mir(tcx, "simplify_cfg", &counter, id, mir, None);
120+
counter += 1;
111121
changed = self.simplify_branches(mir);
112122
changed |= self.remove_goto_chains(mir);
113123
RemoveDeadBlocks.run_pass(tcx, id, mir);

0 commit comments

Comments
 (0)