Skip to content

Commit 4f25c91

Browse files
committed
Fix unwinding logic
1 parent 8df4248 commit 4f25c91

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

src/librustc_mir/interpret/eval_context.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
584584
let frame = self.stack.pop().expect(
585585
"tried to pop a stack frame, but there were none",
586586
);
587-
let stack_pop_info = M::stack_pop(self, frame.extra)?;
587+
let stack_pop_info = M::stack_pop(self, frame.extra, unwinding)?;
588588
match (unwinding, stack_pop_info) {
589589
(true, StackPopInfo::StartUnwinding) =>
590590
bug!("Attempted to start unwinding while already unwinding!"),
@@ -616,7 +616,12 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
616616
// Now where do we jump next?
617617

618618
// Determine if we leave this function normally or via unwinding.
619-
let cur_unwinding = unwinding && stack_pop_info != StackPopInfo::StopUnwinding;
619+
let cur_unwinding = match stack_pop_info {
620+
StackPopInfo::StartUnwinding => true,
621+
StackPopInfo::StopUnwinding => false,
622+
_ => unwinding
623+
};
624+
620625
trace!("StackPopCleanup: {:?} StackPopInfo: {:?} cur_unwinding = {:?}",
621626
frame.return_to_block, stack_pop_info, cur_unwinding);
622627
if cur_unwinding {

src/librustc_mir/interpret/machine.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
270270
fn stack_pop(
271271
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
272272
_extra: Self::FrameExtra,
273+
_unwinding: bool
273274
) -> InterpResult<'tcx, StackPopInfo> {
274275
// By default, we do not support unwinding from panics
275276
Ok(StackPopInfo::Normal)

src/librustc_mir/transform/const_prop.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use crate::interpret::{
3030
self, InterpCx, ScalarMaybeUndef, Immediate, OpTy,
3131
StackPopCleanup, LocalValue, LocalState, AllocId, Frame,
3232
Allocation, MemoryKind, ImmTy, Pointer, Memory, PlaceTy,
33-
StackPopInfo, Operand as InterpOperand,
33+
Operand as InterpOperand,
3434
};
3535
use crate::const_eval::error_to_const_error;
3636
use crate::transform::{MirPass, MirSource};
@@ -252,15 +252,6 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine {
252252
fn stack_push(_ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx> {
253253
Ok(())
254254
}
255-
256-
/// Called immediately before a stack frame gets popped.
257-
#[inline(always)]
258-
fn stack_pop(
259-
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
260-
_extra: ()
261-
) -> InterpResult<'tcx, StackPopInfo> {
262-
Ok(StackPopInfo::Normal)
263-
}
264255
}
265256

266257
type Const<'tcx> = OpTy<'tcx>;

0 commit comments

Comments
 (0)