@@ -55,33 +55,33 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
55
55
} ;
56
56
let basic_block = & self . body ( ) . basic_blocks ( ) [ loc. block ] ;
57
57
58
- let old_frames = self . frame_idx ( ) ;
59
58
60
59
if let Some ( stmt) = basic_block. statements . get ( loc. statement_index ) {
61
- assert_eq ! ( old_frames, self . frame_idx( ) ) ;
60
+ let old_frames = self . frame_idx ( ) ;
62
61
self . statement ( stmt) ?;
62
+ // Make sure we are not updating `statement_index` of the wrong frame.
63
+ assert_eq ! ( old_frames, self . frame_idx( ) ) ;
64
+ // Advance the program counter.
65
+ self . frame_mut ( ) . loc . as_mut ( ) . unwrap ( ) . statement_index += 1 ;
63
66
return Ok ( true ) ;
64
67
}
65
68
66
69
M :: before_terminator ( self ) ?;
67
70
68
71
let terminator = basic_block. terminator ( ) ;
69
- assert_eq ! ( old_frames, self . frame_idx( ) ) ;
70
72
self . terminator ( terminator) ?;
71
73
Ok ( true )
72
74
}
73
75
74
76
/// Runs the interpretation logic for the given `mir::Statement` at the current frame and
75
- /// statement counter. This also moves the statement counter forward.
77
+ /// statement counter.
78
+ ///
79
+ /// This does NOT move the statement counter forward, the caller has to do that!
76
80
pub fn statement ( & mut self , stmt : & mir:: Statement < ' tcx > ) -> InterpResult < ' tcx > {
77
81
info ! ( "{:?}" , stmt) ;
78
82
79
83
use rustc_middle:: mir:: StatementKind :: * ;
80
84
81
- // Some statements (e.g., box) push new stack frames.
82
- // We have to record the stack frame number *before* executing the statement.
83
- let frame_idx = self . frame_idx ( ) ;
84
-
85
85
match & stmt. kind {
86
86
Assign ( box ( place, rvalue) ) => self . eval_rvalue_into_place ( rvalue, * place) ?,
87
87
@@ -144,7 +144,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
144
144
Nop => { }
145
145
}
146
146
147
- self . stack_mut ( ) [ frame_idx] . loc . as_mut ( ) . unwrap ( ) . statement_index += 1 ;
148
147
Ok ( ( ) )
149
148
}
150
149
@@ -300,6 +299,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
300
299
Ok ( ( ) )
301
300
}
302
301
302
+ /// Evaluate the given terminator. Will also adjust the stack frame and statement position accordingly.
303
303
fn terminator ( & mut self , terminator : & mir:: Terminator < ' tcx > ) -> InterpResult < ' tcx > {
304
304
info ! ( "{:?}" , terminator. kind) ;
305
305
0 commit comments