From 9b2d42587f1b12188c1430bd79c058f4590f0ded Mon Sep 17 00:00:00 2001 From: hyd-dev Date: Sat, 22 May 2021 22:45:00 +0800 Subject: [PATCH] `unwind` is no longer `Option` --- rust-version | 2 +- src/machine.rs | 6 ++-- src/shims/foreign_items.rs | 2 +- src/shims/intrinsics.rs | 2 +- src/shims/mod.rs | 4 +-- src/shims/panic.rs | 30 ++++++++++++------- .../compile-fail/panic/unwind_panic_abort.rs | 2 +- 7 files changed, 28 insertions(+), 20 deletions(-) diff --git a/rust-version b/rust-version index 31d26ea43e..7fc12e477e 100644 --- a/rust-version +++ b/rust-version @@ -1 +1 @@ -0f8cd43ee8c3614e04b5c624dd8a45758d7023da +ce0d64e03ef9875e0935bb60e989542b7ec29579 diff --git a/src/machine.rs b/src/machine.rs index fb2d877c38..467696e839 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -356,7 +356,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> { abi: Abi, args: &[OpTy<'tcx, Tag>], ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>, - unwind: Option, + unwind: StackPopUnwind, ) -> InterpResult<'tcx, Option<&'mir mir::Body<'tcx>>> { ecx.find_mir_or_eval_fn(instance, abi, args, ret, unwind) } @@ -368,7 +368,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> { abi: Abi, args: &[OpTy<'tcx, Tag>], ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>, - _unwind: Option, + _unwind: StackPopUnwind, ) -> InterpResult<'tcx> { ecx.call_dlsym(fn_val, abi, args, ret) } @@ -379,7 +379,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> { instance: ty::Instance<'tcx>, args: &[OpTy<'tcx, Tag>], ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>, - unwind: Option, + unwind: StackPopUnwind, ) -> InterpResult<'tcx> { ecx.call_intrinsic(instance, args, ret, unwind) } diff --git a/src/shims/foreign_items.rs b/src/shims/foreign_items.rs index 47d939e697..4c96c99eee 100644 --- a/src/shims/foreign_items.rs +++ b/src/shims/foreign_items.rs @@ -120,7 +120,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx abi: Abi, args: &[OpTy<'tcx, Tag>], ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>, - unwind: Option, + unwind: StackPopUnwind, ) -> InterpResult<'tcx, Option<&'mir mir::Body<'tcx>>> { let this = self.eval_context_mut(); let attrs = this.tcx.get_attrs(def_id); diff --git a/src/shims/intrinsics.rs b/src/shims/intrinsics.rs index f2979a3c69..c018dd8738 100644 --- a/src/shims/intrinsics.rs +++ b/src/shims/intrinsics.rs @@ -23,7 +23,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx instance: ty::Instance<'tcx>, args: &[OpTy<'tcx, Tag>], ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>, - _unwind: Option, + _unwind: StackPopUnwind, ) -> InterpResult<'tcx> { let this = self.eval_context_mut(); diff --git a/src/shims/mod.rs b/src/shims/mod.rs index 13ea14b4b9..bb8d0bb8db 100644 --- a/src/shims/mod.rs +++ b/src/shims/mod.rs @@ -29,7 +29,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx abi: Abi, args: &[OpTy<'tcx, Tag>], ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>, - unwind: Option, + unwind: StackPopUnwind, ) -> InterpResult<'tcx, Option<&'mir mir::Body<'tcx>>> { let this = self.eval_context_mut(); trace!("eval_fn_call: {:#?}, {:?}", instance, ret.map(|p| p.0)); @@ -64,7 +64,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx ptr_op: &OpTy<'tcx, Tag>, align_op: &OpTy<'tcx, Tag>, ret: Option<(&PlaceTy<'tcx, Tag>, mir::BasicBlock)>, - unwind: Option, + unwind: StackPopUnwind, ) -> InterpResult<'tcx, bool> { let this = self.eval_context_mut(); let (dest, ret) = ret.unwrap(); diff --git a/src/shims/panic.rs b/src/shims/panic.rs index 06a434727b..b1da7f340f 100644 --- a/src/shims/panic.rs +++ b/src/shims/panic.rs @@ -41,15 +41,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx fn handle_miri_start_panic( &mut self, args: &[OpTy<'tcx, Tag>], - unwind: Option, + unwind: StackPopUnwind, ) -> InterpResult<'tcx> { let this = self.eval_context_mut(); trace!("miri_start_panic: {:?}", this.frame().instance); - // Make sure we only start unwinding when this matches our panic strategy. - if this.tcx.sess.panic_strategy() != PanicStrategy::Unwind { - throw_ub_format!("unwinding despite panic=abort"); - } // Get the raw pointer stored in arg[0] (the panic payload). let &[ref payload] = check_arg_count(args)?; @@ -59,7 +55,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx thread.panic_payload = Some(payload); // Jump to the unwind block to begin unwinding. - this.unwind_to_block(unwind); + this.unwind_to_block(unwind)?; return Ok(()); } @@ -99,7 +95,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx &[data.into()], Some(&ret_place), // Directly return to caller. - StackPopCleanup::Goto { ret: Some(ret), unwind: None }, + StackPopCleanup::Goto { ret: Some(ret), unwind: StackPopUnwind::Skip }, )?; // We ourselves will return `0`, eventually (will be overwritten if we catch a panic). @@ -155,7 +151,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx &[catch_unwind.data.into(), payload.into()], Some(&ret_place), // Directly return to caller of `try`. - StackPopCleanup::Goto { ret: Some(catch_unwind.ret), unwind: None }, + StackPopCleanup::Goto { ret: Some(catch_unwind.ret), unwind: StackPopUnwind::Skip }, )?; // We pushed a new stack frame, the engine should not do any jumping now! @@ -166,7 +162,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx } /// Starta a panic in the interpreter with the given message as payload. - fn start_panic(&mut self, msg: &str, unwind: Option) -> InterpResult<'tcx> { + fn start_panic(&mut self, msg: &str, unwind: StackPopUnwind) -> InterpResult<'tcx> { let this = self.eval_context_mut(); // First arg: message. @@ -209,12 +205,24 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx Abi::Rust, &[index.into(), len.into()], None, - StackPopCleanup::Goto { ret: None, unwind }, + StackPopCleanup::Goto { + ret: None, + unwind: match unwind { + Some(cleanup) => StackPopUnwind::Cleanup(cleanup), + None => StackPopUnwind::Skip, + }, + }, )?; } _ => { // Forward everything else to `panic` lang item. - this.start_panic(msg.description(), unwind)?; + this.start_panic( + msg.description(), + match unwind { + Some(cleanup) => StackPopUnwind::Cleanup(cleanup), + None => StackPopUnwind::Skip, + }, + )?; } } Ok(()) diff --git a/tests/compile-fail/panic/unwind_panic_abort.rs b/tests/compile-fail/panic/unwind_panic_abort.rs index 05284eb770..a333a4b0de 100644 --- a/tests/compile-fail/panic/unwind_panic_abort.rs +++ b/tests/compile-fail/panic/unwind_panic_abort.rs @@ -7,5 +7,5 @@ extern "Rust" { } fn main() { - unsafe { miri_start_panic(&mut 0); } //~ ERROR unwinding despite panic=abort + unsafe { miri_start_panic(&mut 0); } //~ ERROR unwinding past a stack frame that does not allow unwinding }