From 4f25c91a0530d2337bff2b27c938e458a95e943b Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Mon, 28 Oct 2019 21:37:58 -0400 Subject: [PATCH] Fix unwinding logic --- src/librustc_mir/interpret/eval_context.rs | 9 +++++++-- src/librustc_mir/interpret/machine.rs | 1 + src/librustc_mir/transform/const_prop.rs | 11 +---------- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index 6598b0f99f2..fb3f4f21a97 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -584,7 +584,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let frame = self.stack.pop().expect( "tried to pop a stack frame, but there were none", ); - let stack_pop_info = M::stack_pop(self, frame.extra)?; + let stack_pop_info = M::stack_pop(self, frame.extra, unwinding)?; match (unwinding, stack_pop_info) { (true, StackPopInfo::StartUnwinding) => bug!("Attempted to start unwinding while already unwinding!"), @@ -616,7 +616,12 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { // Now where do we jump next? // Determine if we leave this function normally or via unwinding. - let cur_unwinding = unwinding && stack_pop_info != StackPopInfo::StopUnwinding; + let cur_unwinding = match stack_pop_info { + StackPopInfo::StartUnwinding => true, + StackPopInfo::StopUnwinding => false, + _ => unwinding + }; + trace!("StackPopCleanup: {:?} StackPopInfo: {:?} cur_unwinding = {:?}", frame.return_to_block, stack_pop_info, cur_unwinding); if cur_unwinding { diff --git a/src/librustc_mir/interpret/machine.rs b/src/librustc_mir/interpret/machine.rs index 18f831f8257..bed6c0b67eb 100644 --- a/src/librustc_mir/interpret/machine.rs +++ b/src/librustc_mir/interpret/machine.rs @@ -270,6 +270,7 @@ pub trait Machine<'mir, 'tcx>: Sized { fn stack_pop( _ecx: &mut InterpCx<'mir, 'tcx, Self>, _extra: Self::FrameExtra, + _unwinding: bool ) -> InterpResult<'tcx, StackPopInfo> { // By default, we do not support unwinding from panics Ok(StackPopInfo::Normal) diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 5c83fb8c821..3ee9445f9c0 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -30,7 +30,7 @@ use crate::interpret::{ self, InterpCx, ScalarMaybeUndef, Immediate, OpTy, StackPopCleanup, LocalValue, LocalState, AllocId, Frame, Allocation, MemoryKind, ImmTy, Pointer, Memory, PlaceTy, - StackPopInfo, Operand as InterpOperand, + Operand as InterpOperand, }; use crate::const_eval::error_to_const_error; use crate::transform::{MirPass, MirSource}; @@ -252,15 +252,6 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine { fn stack_push(_ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx> { Ok(()) } - - /// Called immediately before a stack frame gets popped. - #[inline(always)] - fn stack_pop( - _ecx: &mut InterpCx<'mir, 'tcx, Self>, - _extra: () - ) -> InterpResult<'tcx, StackPopInfo> { - Ok(StackPopInfo::Normal) - } } type Const<'tcx> = OpTy<'tcx>;