diff options
| author | Ralf Jung <post@ralfj.de> | 2023-08-19 13:21:41 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2023-08-20 15:52:40 +0200 |
| commit | 788fd44a3be128243ac48539d23235a3d91d9a85 (patch) | |
| tree | 62327d0ad2c60240842b13f0ce1b8c0130deaf9d /compiler/rustc_const_eval/src | |
| parent | 818ec8e23adcc4c6b684fc070b8c7e89c941171e (diff) | |
| download | rust-788fd44a3be128243ac48539d23235a3d91d9a85.tar.gz rust-788fd44a3be128243ac48539d23235a3d91d9a85.zip | |
interpret/miri: call panic_cannot_unwind lang item instead of hard-coding the same message
Diffstat (limited to 'compiler/rustc_const_eval/src')
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/eval_context.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/machine.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/terminator.rs | 3 |
3 files changed, 14 insertions, 3 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/eval_context.rs b/compiler/rustc_const_eval/src/interpret/eval_context.rs index 3ac6f07e8b7..61d3de5c405 100644 --- a/compiler/rustc_const_eval/src/interpret/eval_context.rs +++ b/compiler/rustc_const_eval/src/interpret/eval_context.rs @@ -765,7 +765,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { } mir::UnwindAction::Terminate => { self.frame_mut().loc = Right(self.frame_mut().body.span); - M::abort(self, "panic in a function that cannot unwind".to_owned())?; + M::unwind_terminate(self)?; + // This might have pushed a new stack frame, or it terminated execution. + // Either way, `loc` will not be updated. + return Ok(()); } }; Ok(()) @@ -865,6 +868,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { panic!("encountered StackPopCleanup::Root when unwinding!") } }; + // This must be the very last thing that happens, since it can in fact push a new stack frame. self.unwind_to_block(unwind) } else { // Follow the normal return edge. diff --git a/compiler/rustc_const_eval/src/interpret/machine.rs b/compiler/rustc_const_eval/src/interpret/machine.rs index e101785b6e2..15f2dd17bf5 100644 --- a/compiler/rustc_const_eval/src/interpret/machine.rs +++ b/compiler/rustc_const_eval/src/interpret/machine.rs @@ -223,6 +223,9 @@ pub trait Machine<'mir, 'tcx: 'mir>: Sized { throw_unsup_format!("aborting execution is not supported") } + /// Called when unwinding reached a state where execution should be terminated. + fn unwind_terminate(_ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx>; + /// Called for all binary operations where the LHS has pointer type. /// /// Returns a (value, overflowed) pair if the operation succeeded @@ -500,6 +503,11 @@ pub macro compile_time_machine(<$mir: lifetime, $tcx: lifetime>) { } #[inline(always)] + fn unwind_terminate(_ecx: &mut InterpCx<$mir, $tcx, Self>) -> InterpResult<$tcx> { + unreachable!("unwinding cannot happen during compile-time evaluation") + } + + #[inline(always)] fn call_extra_fn( _ecx: &mut InterpCx<$mir, $tcx, Self>, fn_val: !, diff --git a/compiler/rustc_const_eval/src/interpret/terminator.rs b/compiler/rustc_const_eval/src/interpret/terminator.rs index afca6a80319..b2ebcceceb3 100644 --- a/compiler/rustc_const_eval/src/interpret/terminator.rs +++ b/compiler/rustc_const_eval/src/interpret/terminator.rs @@ -197,8 +197,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { } UnwindTerminate => { - // FIXME: maybe should call `panic_no_unwind` lang item instead. - M::abort(self, "panic in a function that cannot unwind".to_owned())?; + M::unwind_terminate(self)?; } // When we encounter Resume, we've finished unwinding |
