@@ -103,7 +103,14 @@ impl<'tcx> MirPass<'tcx> for ConstProp {
103
103
// That would require a uniform one-def no-mutation analysis
104
104
// and RPO (or recursing when needing the value of a local).
105
105
let mut optimization_finder = ConstPropagator :: new ( body, dummy_body, tcx) ;
106
- optimization_finder. visit_body ( body) ;
106
+
107
+ // Traverse the body in reverse post-order, to ensure that `FullConstProp` locals are
108
+ // assigned before being read.
109
+ let postorder = body. basic_blocks . postorder ( ) . to_vec ( ) ;
110
+ for bb in postorder. into_iter ( ) . rev ( ) {
111
+ let data = & mut body. basic_blocks . as_mut_preserves_cfg ( ) [ bb] ;
112
+ optimization_finder. visit_basic_block_data ( bb, data) ;
113
+ }
107
114
108
115
trace ! ( "ConstProp done for {:?}" , def_id) ;
109
116
}
@@ -790,12 +797,6 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
790
797
self . tcx
791
798
}
792
799
793
- fn visit_body ( & mut self , body : & mut Body < ' tcx > ) {
794
- for ( bb, data) in body. basic_blocks . as_mut_preserves_cfg ( ) . iter_enumerated_mut ( ) {
795
- self . visit_basic_block_data ( bb, data) ;
796
- }
797
- }
798
-
799
800
fn visit_operand ( & mut self , operand : & mut Operand < ' tcx > , location : Location ) {
800
801
self . super_operand ( operand, location) ;
801
802
0 commit comments