@@ -12,6 +12,7 @@ use rustc::middle::const_eval::ConstVal;
12
12
use rustc:: middle:: ty:: TyCtxt ;
13
13
use rustc:: mir:: repr:: * ;
14
14
use rustc:: mir:: transform:: { MirPass , Pass } ;
15
+ use pretty;
15
16
use syntax:: ast:: NodeId ;
16
17
17
18
use super :: remove_dead_blocks:: RemoveDeadBlocks ;
@@ -30,16 +31,22 @@ impl SimplifyCfg {
30
31
let mut seen: Vec < BasicBlock > = Vec :: with_capacity ( 8 ) ;
31
32
32
33
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;
38
45
}
39
- seen. push ( next) ;
40
- target = next;
46
+ _ => break
41
47
}
42
- _ => break
48
+ } else {
49
+ break
43
50
}
44
51
}
45
52
@@ -106,8 +113,11 @@ impl SimplifyCfg {
106
113
107
114
impl < ' tcx > MirPass < ' tcx > for SimplifyCfg {
108
115
fn run_pass ( & mut self , tcx : & TyCtxt < ' tcx > , id : NodeId , mir : & mut Mir < ' tcx > ) {
116
+ let mut counter = 0 ;
109
117
let mut changed = true ;
110
118
while changed {
119
+ pretty:: dump_mir ( tcx, "simplify_cfg" , & counter, id, mir, None ) ;
120
+ counter += 1 ;
111
121
changed = self . simplify_branches ( mir) ;
112
122
changed |= self . remove_goto_chains ( mir) ;
113
123
RemoveDeadBlocks . run_pass ( tcx, id, mir) ;
0 commit comments