Skip to content

Commit da99ef3

Browse files
committed
---
yaml --- r: 271485 b: refs/heads/auto c: f976e22 h: refs/heads/master i: 271483: a59a62a
1 parent 5eb5d56 commit da99ef3

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
@@ -8,7 +8,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
88
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
99
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1010
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
11-
refs/heads/auto: a61c1759c7297f09955409fffaa162c7a21f89a7
11+
refs/heads/auto: f976e222e97fdcb8ab66634c8910ce524f6804c9
1212
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1313
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336
1414
refs/tags/0.2: 1754d02027f2924bed83b0160ee340c7f41d5ea1

branches/auto/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)