From 4c53783f3c27ce30119018c752bdc805222409da Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 21 Aug 2023 09:57:10 +0200 Subject: [PATCH 1/8] when terminating during unwinding, show the reason why --- compiler/rustc_borrowck/src/invalidation.rs | 2 +- compiler/rustc_borrowck/src/lib.rs | 4 +- compiler/rustc_borrowck/src/type_check/mod.rs | 6 +- compiler/rustc_codegen_cranelift/src/base.rs | 9 +- .../rustc_codegen_cranelift/src/constant.rs | 2 +- compiler/rustc_codegen_ssa/src/mir/analyze.rs | 2 +- compiler/rustc_codegen_ssa/src/mir/block.rs | 151 +++++++++--------- compiler/rustc_codegen_ssa/src/mir/mod.rs | 8 +- .../src/interpret/eval_context.rs | 5 +- .../rustc_const_eval/src/interpret/machine.rs | 11 +- .../src/interpret/terminator.rs | 4 +- .../src/transform/check_consts/check.rs | 2 +- .../check_consts/post_drop_elaboration.rs | 2 +- .../src/transform/validate.rs | 19 ++- compiler/rustc_hir/src/lang_items.rs | 1 + compiler/rustc_middle/src/mir/patch.rs | 29 ++-- compiler/rustc_middle/src/mir/syntax.rs | 17 +- compiler/rustc_middle/src/mir/terminator.rs | 88 +++++++--- compiler/rustc_middle/src/mir/visit.rs | 2 +- compiler/rustc_mir_build/src/build/scope.rs | 4 +- compiler/rustc_mir_build/src/lints.rs | 2 +- .../rustc_mir_dataflow/src/elaborate_drops.rs | 2 +- .../src/framework/direction.rs | 8 +- .../src/impls/borrowed_locals.rs | 2 +- .../src/impls/storage_liveness.rs | 4 +- .../src/move_paths/builder.rs | 2 +- .../rustc_mir_dataflow/src/value_analysis.rs | 2 +- .../src/abort_unwinding_calls.rs | 2 +- .../src/add_call_guards.rs | 6 +- .../rustc_mir_transform/src/check_unsafety.rs | 2 +- .../src/const_prop_lint.rs | 2 +- .../rustc_mir_transform/src/coverage/graph.rs | 2 +- .../rustc_mir_transform/src/coverage/spans.rs | 2 +- compiler/rustc_mir_transform/src/dest_prop.rs | 2 +- .../src/elaborate_drops.rs | 12 +- compiler/rustc_mir_transform/src/generator.rs | 6 +- compiler/rustc_mir_transform/src/inline.rs | 8 +- .../src/remove_noop_landing_pads.rs | 2 +- .../src/separate_const_switch.rs | 4 +- compiler/rustc_mir_transform/src/shim.rs | 8 +- compiler/rustc_monomorphize/src/collector.rs | 32 ++-- compiler/rustc_smir/src/rustc_smir/mod.rs | 4 +- compiler/rustc_span/src/symbol.rs | 1 + library/core/src/panicking.rs | 17 ++ .../clippy_utils/src/qualify_min_const_fn.rs | 2 +- src/tools/miri/src/machine.rs | 4 +- .../miri/tests/fail/panic/double_panic.stderr | 4 +- ...c_abort.main.AbortUnwindingCalls.after.mir | 2 +- .../basic_assignment.main.ElaborateDrops.diff | 6 +- ...ignment.main.SimplifyCfg-initial.after.mir | 6 +- ...main.ElaborateDrops.before.panic-abort.mir | 6 +- ...ain.ElaborateDrops.before.panic-unwind.mir | 6 +- .../building/enum_cast.droppy.built.after.mir | 2 +- ...e_out.move_out_by_subslice.built.after.mir | 6 +- ...move_out.move_out_from_end.built.after.mir | 6 +- ...pl#0}-clone.InstSimplify.panic-unwind.diff | 2 +- ..._inline_test.main.Derefer.panic-abort.diff | 2 +- ...inline_test.main.Derefer.panic-unwind.diff | 2 +- ...#0}.StateTransform.before.panic-unwind.mir | 4 +- .../asm_unwind.main.Inline.panic-abort.diff | 2 +- .../asm_unwind.main.Inline.panic-unwind.diff | 2 +- .../inline/cycle.f.Inline.panic-unwind.diff | 2 +- .../inline/cycle.g.Inline.panic-unwind.diff | 2 +- .../cycle.main.Inline.panic-unwind.diff | 2 +- ...ic_rust_call.call.Inline.panic-unwind.diff | 2 +- ...nline_box_fn.call.Inline.panic-unwind.diff | 2 +- ...nline_diverging.h.Inline.panic-unwind.diff | 4 +- .../issue_78442.bar.Inline.panic-unwind.diff | 2 +- ...ssue_78442.bar.RevealAll.panic-unwind.diff | 2 +- .../unsized_argument.caller.Inline.diff | 2 +- ...41110.main.ElaborateDrops.panic-abort.diff | 8 +- ...1110.main.ElaborateDrops.panic-unwind.diff | 8 +- ...41110.test.ElaborateDrops.panic-abort.diff | 10 +- ...1110.test.ElaborateDrops.panic-unwind.diff | 10 +- ...41888.main.ElaborateDrops.panic-abort.diff | 6 +- ...1888.main.ElaborateDrops.panic-unwind.diff | 6 +- ...test.ElaborateDrops.before.panic-abort.mir | 4 +- ...est.ElaborateDrops.before.panic-unwind.mir | 4 +- tests/mir-opt/issue_91633.bar.built.after.mir | 2 +- tests/mir-opt/issue_91633.foo.built.after.mir | 2 +- ...fg-initial.after-ElaborateDrops.after.diff | 2 +- ...fg-initial.after-ElaborateDrops.after.diff | 2 +- ...main.ElaborateDrops.before.panic-abort.mir | 2 +- ...ain.ElaborateDrops.before.panic-unwind.mir | 2 +- ...Cfg-elaborate-drops.after.panic-unwind.mir | 2 +- ...Cfg-elaborate-drops.after.panic-unwind.mir | 4 +- ...[String].AddMovesForPackedDrops.before.mir | 2 +- ...Vec_i32_.AddMovesForPackedDrops.before.mir | 2 +- 88 files changed, 383 insertions(+), 281 deletions(-) diff --git a/compiler/rustc_borrowck/src/invalidation.rs b/compiler/rustc_borrowck/src/invalidation.rs index d4c42a7587481..84be50a641694 100644 --- a/compiler/rustc_borrowck/src/invalidation.rs +++ b/compiler/rustc_borrowck/src/invalidation.rs @@ -202,7 +202,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> { } } TerminatorKind::Goto { target: _ } - | TerminatorKind::UnwindTerminate + | TerminatorKind::UnwindTerminate(_) | TerminatorKind::Unreachable | TerminatorKind::FalseEdge { real_target: _, imaginary_target: _ } | TerminatorKind::FalseUnwind { real_target: _, unwind: _ } => { diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index ef2788efbcfc5..ca96d14b89c12 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -770,7 +770,7 @@ impl<'cx, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx, R> for MirBorro } TerminatorKind::Goto { target: _ } - | TerminatorKind::UnwindTerminate + | TerminatorKind::UnwindTerminate(_) | TerminatorKind::Unreachable | TerminatorKind::UnwindResume | TerminatorKind::Return @@ -817,7 +817,7 @@ impl<'cx, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx, R> for MirBorro } } - TerminatorKind::UnwindTerminate + TerminatorKind::UnwindTerminate(_) | TerminatorKind::Assert { .. } | TerminatorKind::Call { .. } | TerminatorKind::Drop { .. } diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index d91a3d94045ed..3004291c3e75e 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -1334,7 +1334,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { match &term.kind { TerminatorKind::Goto { .. } | TerminatorKind::UnwindResume - | TerminatorKind::UnwindTerminate + | TerminatorKind::UnwindTerminate(_) | TerminatorKind::Return | TerminatorKind::GeneratorDrop | TerminatorKind::Unreachable @@ -1613,7 +1613,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { span_mirbug!(self, block_data, "resume on non-cleanup block!") } } - TerminatorKind::UnwindTerminate => { + TerminatorKind::UnwindTerminate(_) => { if !is_cleanup { span_mirbug!(self, block_data, "abort on non-cleanup block!") } @@ -1697,7 +1697,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { span_mirbug!(self, ctxt, "unwind on cleanup block") } } - UnwindAction::Unreachable | UnwindAction::Terminate => (), + UnwindAction::Unreachable | UnwindAction::Terminate(_) => (), } } diff --git a/compiler/rustc_codegen_cranelift/src/base.rs b/compiler/rustc_codegen_cranelift/src/base.rs index ed371a04c5370..9159bc3698755 100644 --- a/compiler/rustc_codegen_cranelift/src/base.rs +++ b/compiler/rustc_codegen_cranelift/src/base.rs @@ -474,8 +474,8 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) { *destination, ); } - TerminatorKind::UnwindTerminate => { - codegen_panic_cannot_unwind(fx, source_info); + TerminatorKind::UnwindTerminate(reason) => { + codegen_unwind_terminate(fx, source_info, *reason); } TerminatorKind::UnwindResume => { // FIXME implement unwinding @@ -971,13 +971,14 @@ pub(crate) fn codegen_panic_nounwind<'tcx>( codegen_panic_inner(fx, rustc_hir::LangItem::PanicNounwind, &args, source_info.span); } -pub(crate) fn codegen_panic_cannot_unwind<'tcx>( +pub(crate) fn codegen_unwind_terminate<'tcx>( fx: &mut FunctionCx<'_, '_, 'tcx>, source_info: mir::SourceInfo, + reason: UnwindTerminateReason, ) { let args = []; - codegen_panic_inner(fx, rustc_hir::LangItem::PanicCannotUnwind, &args, source_info.span); + codegen_panic_inner(fx, reason.lang_item(), &args, source_info.span); } fn codegen_panic_inner<'tcx>( diff --git a/compiler/rustc_codegen_cranelift/src/constant.rs b/compiler/rustc_codegen_cranelift/src/constant.rs index 7db5f79eead9e..a934b0767f174 100644 --- a/compiler/rustc_codegen_cranelift/src/constant.rs +++ b/compiler/rustc_codegen_cranelift/src/constant.rs @@ -551,7 +551,7 @@ pub(crate) fn mir_operand_get_const_val<'tcx>( TerminatorKind::Goto { .. } | TerminatorKind::SwitchInt { .. } | TerminatorKind::UnwindResume - | TerminatorKind::UnwindTerminate + | TerminatorKind::UnwindTerminate(_) | TerminatorKind::Return | TerminatorKind::Unreachable | TerminatorKind::Drop { .. } diff --git a/compiler/rustc_codegen_ssa/src/mir/analyze.rs b/compiler/rustc_codegen_ssa/src/mir/analyze.rs index 3f5b46333d9b1..7fda2d5fadf7b 100644 --- a/compiler/rustc_codegen_ssa/src/mir/analyze.rs +++ b/compiler/rustc_codegen_ssa/src/mir/analyze.rs @@ -285,7 +285,7 @@ pub fn cleanup_kinds(mir: &mir::Body<'_>) -> IndexVec TerminatorCodegenHelper<'tcx> { mir::UnwindAction::Cleanup(cleanup) => Some(self.llbb_with_cleanup(fx, cleanup)), mir::UnwindAction::Continue => None, mir::UnwindAction::Unreachable => None, - mir::UnwindAction::Terminate => { + mir::UnwindAction::Terminate(reason) => { if fx.mir[self.bb].is_cleanup && base::wants_new_eh_instructions(fx.cx.tcx().sess) { // MSVC SEH will abort automatically if an exception tries to // propagate out from cleanup. @@ -191,7 +191,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> { None } else { - Some(fx.terminate_block()) + Some(fx.terminate_block(reason)) } } }; @@ -264,7 +264,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> { ) -> MergingSucc { let unwind_target = match unwind { mir::UnwindAction::Cleanup(cleanup) => Some(self.llbb_with_cleanup(fx, cleanup)), - mir::UnwindAction::Terminate => Some(fx.terminate_block()), + mir::UnwindAction::Terminate(reason) => Some(fx.terminate_block(reason)), mir::UnwindAction::Continue => None, mir::UnwindAction::Unreachable => None, }; @@ -649,12 +649,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { helper: TerminatorCodegenHelper<'tcx>, bx: &mut Bx, terminator: &mir::Terminator<'tcx>, + reason: UnwindTerminateReason, ) { let span = terminator.source_info.span; self.set_debug_loc(bx, terminator.source_info); // Obtain the panic entry point. - let (fn_abi, llfn) = common::build_langcall(bx, Some(span), LangItem::PanicCannotUnwind); + let (fn_abi, llfn) = common::build_langcall(bx, Some(span), reason.lang_item()); // Codegen the actual panic invoke/call. let merging_succ = helper.do_call( @@ -1229,8 +1230,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { MergingSucc::False } - mir::TerminatorKind::UnwindTerminate => { - self.codegen_terminate_terminator(helper, bx, terminator); + mir::TerminatorKind::UnwindTerminate(reason) => { + self.codegen_terminate_terminator(helper, bx, terminator, reason); MergingSucc::False } @@ -1579,79 +1580,83 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { }) } - fn terminate_block(&mut self) -> Bx::BasicBlock { - self.terminate_block.unwrap_or_else(|| { - let funclet; - let llbb; - let mut bx; - if base::wants_msvc_seh(self.cx.sess()) { - // This is a basic block that we're aborting the program for, - // notably in an `extern` function. These basic blocks are inserted - // so that we assert that `extern` functions do indeed not panic, - // and if they do we abort the process. - // - // On MSVC these are tricky though (where we're doing funclets). If - // we were to do a cleanuppad (like below) the normal functions like - // `longjmp` would trigger the abort logic, terminating the - // program. Instead we insert the equivalent of `catch(...)` for C++ - // which magically doesn't trigger when `longjmp` files over this - // frame. - // - // Lots more discussion can be found on #48251 but this codegen is - // modeled after clang's for: - // - // try { - // foo(); - // } catch (...) { - // bar(); - // } - // - // which creates an IR snippet like - // - // cs_terminate: - // %cs = catchswitch within none [%cp_terminate] unwind to caller - // cp_terminate: - // %cp = catchpad within %cs [null, i32 64, null] - // ... - - llbb = Bx::append_block(self.cx, self.llfn, "cs_terminate"); - let cp_llbb = Bx::append_block(self.cx, self.llfn, "cp_terminate"); - - let mut cs_bx = Bx::build(self.cx, llbb); - let cs = cs_bx.catch_switch(None, None, &[cp_llbb]); - - // The "null" here is actually a RTTI type descriptor for the - // C++ personality function, but `catch (...)` has no type so - // it's null. The 64 here is actually a bitfield which - // represents that this is a catch-all block. - bx = Bx::build(self.cx, cp_llbb); - let null = - bx.const_null(bx.type_ptr_ext(bx.cx().data_layout().instruction_address_space)); - let sixty_four = bx.const_i32(64); - funclet = Some(bx.catch_pad(cs, &[null, sixty_four, null])); - } else { - llbb = Bx::append_block(self.cx, self.llfn, "terminate"); - bx = Bx::build(self.cx, llbb); + fn terminate_block(&mut self, reason: UnwindTerminateReason) -> Bx::BasicBlock { + if let Some(bb) = self.terminate_in_cleanup_block && reason == UnwindTerminateReason::InCleanup { + return bb; + } + + let funclet; + let llbb; + let mut bx; + if base::wants_msvc_seh(self.cx.sess()) { + // This is a basic block that we're aborting the program for, + // notably in an `extern` function. These basic blocks are inserted + // so that we assert that `extern` functions do indeed not panic, + // and if they do we abort the process. + // + // On MSVC these are tricky though (where we're doing funclets). If + // we were to do a cleanuppad (like below) the normal functions like + // `longjmp` would trigger the abort logic, terminating the + // program. Instead we insert the equivalent of `catch(...)` for C++ + // which magically doesn't trigger when `longjmp` files over this + // frame. + // + // Lots more discussion can be found on #48251 but this codegen is + // modeled after clang's for: + // + // try { + // foo(); + // } catch (...) { + // bar(); + // } + // + // which creates an IR snippet like + // + // cs_terminate: + // %cs = catchswitch within none [%cp_terminate] unwind to caller + // cp_terminate: + // %cp = catchpad within %cs [null, i32 64, null] + // ... + + llbb = Bx::append_block(self.cx, self.llfn, "cs_terminate"); + let cp_llbb = Bx::append_block(self.cx, self.llfn, "cp_terminate"); + + let mut cs_bx = Bx::build(self.cx, llbb); + let cs = cs_bx.catch_switch(None, None, &[cp_llbb]); + + // The "null" here is actually a RTTI type descriptor for the + // C++ personality function, but `catch (...)` has no type so + // it's null. The 64 here is actually a bitfield which + // represents that this is a catch-all block. + bx = Bx::build(self.cx, cp_llbb); + let null = + bx.const_null(bx.type_ptr_ext(bx.cx().data_layout().instruction_address_space)); + let sixty_four = bx.const_i32(64); + funclet = Some(bx.catch_pad(cs, &[null, sixty_four, null])); + } else { + llbb = Bx::append_block(self.cx, self.llfn, "terminate"); + bx = Bx::build(self.cx, llbb); - let llpersonality = self.cx.eh_personality(); - bx.filter_landing_pad(llpersonality); + let llpersonality = self.cx.eh_personality(); + bx.filter_landing_pad(llpersonality); - funclet = None; - } + funclet = None; + } - self.set_debug_loc(&mut bx, mir::SourceInfo::outermost(self.mir.span)); + self.set_debug_loc(&mut bx, mir::SourceInfo::outermost(self.mir.span)); - let (fn_abi, fn_ptr) = common::build_langcall(&bx, None, LangItem::PanicCannotUnwind); - let fn_ty = bx.fn_decl_backend_type(&fn_abi); + let (fn_abi, fn_ptr) = common::build_langcall(&bx, None, reason.lang_item()); + let fn_ty = bx.fn_decl_backend_type(&fn_abi); - let llret = bx.call(fn_ty, None, Some(&fn_abi), fn_ptr, &[], funclet.as_ref()); - bx.do_not_inline(llret); + let llret = bx.call(fn_ty, None, Some(&fn_abi), fn_ptr, &[], funclet.as_ref()); + bx.do_not_inline(llret); - bx.unreachable(); + bx.unreachable(); - self.terminate_block = Some(llbb); - llbb - }) + if reason == UnwindTerminateReason::InCleanup { + self.terminate_in_cleanup_block = Some(llbb); + } + llbb } /// Get the backend `BasicBlock` for a MIR `BasicBlock`, either already diff --git a/compiler/rustc_codegen_ssa/src/mir/mod.rs b/compiler/rustc_codegen_ssa/src/mir/mod.rs index ccf93f208d50d..7f38c54c36f0a 100644 --- a/compiler/rustc_codegen_ssa/src/mir/mod.rs +++ b/compiler/rustc_codegen_ssa/src/mir/mod.rs @@ -83,8 +83,8 @@ pub struct FunctionCx<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> { /// Cached unreachable block unreachable_block: Option, - /// Cached terminate upon unwinding block - terminate_block: Option, + /// Cached terminate upon unwinding (reason: InCleanup) block + terminate_in_cleanup_block: Option, /// The location where each MIR arg/var/tmp/ret is stored. This is /// usually an `PlaceRef` representing an alloca, but not always: @@ -174,7 +174,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( let mut start_bx = Bx::build(cx, start_llbb); if mir.basic_blocks.iter().any(|bb| { - bb.is_cleanup || matches!(bb.terminator().unwind(), Some(mir::UnwindAction::Terminate)) + bb.is_cleanup || matches!(bb.terminator().unwind(), Some(mir::UnwindAction::Terminate(_))) }) { start_bx.set_personality_fn(cx.eh_personality()); } @@ -199,7 +199,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( personality_slot: None, cached_llbbs, unreachable_block: None, - terminate_block: None, + terminate_in_cleanup_block: None, cleanup_kinds, landing_pads: IndexVec::from_elem(None, &mir.basic_blocks), funclets: IndexVec::from_fn_n(|_| None, mir.basic_blocks.len()), diff --git a/compiler/rustc_const_eval/src/interpret/eval_context.rs b/compiler/rustc_const_eval/src/interpret/eval_context.rs index 61d3de5c40504..90848dbfbc738 100644 --- a/compiler/rustc_const_eval/src/interpret/eval_context.rs +++ b/compiler/rustc_const_eval/src/interpret/eval_context.rs @@ -756,6 +756,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { /// /// If `target` is `UnwindAction::Unreachable`, that indicates the function does not allow /// unwinding, and doing so is UB. + #[cold] // usually we have normal returns, not unwinding pub fn unwind_to_block(&mut self, target: mir::UnwindAction) -> InterpResult<'tcx> { self.frame_mut().loc = match target { mir::UnwindAction::Cleanup(block) => Left(mir::Location { block, statement_index: 0 }), @@ -763,9 +764,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { mir::UnwindAction::Unreachable => { throw_ub_custom!(fluent::const_eval_unreachable_unwind); } - mir::UnwindAction::Terminate => { + mir::UnwindAction::Terminate(reason) => { self.frame_mut().loc = Right(self.frame_mut().body.span); - M::unwind_terminate(self)?; + M::unwind_terminate(self, reason)?; // This might have pushed a new stack frame, or it terminated execution. // Either way, `loc` will not be updated. return Ok(()); diff --git a/compiler/rustc_const_eval/src/interpret/machine.rs b/compiler/rustc_const_eval/src/interpret/machine.rs index d3c73b896c089..6be2e4069170f 100644 --- a/compiler/rustc_const_eval/src/interpret/machine.rs +++ b/compiler/rustc_const_eval/src/interpret/machine.rs @@ -222,7 +222,10 @@ pub trait Machine<'mir, 'tcx: 'mir>: Sized { fn panic_nounwind(_ecx: &mut InterpCx<'mir, 'tcx, Self>, msg: &str) -> InterpResult<'tcx>; /// Called when unwinding reached a state where execution should be terminated. - fn unwind_terminate(_ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx>; + fn unwind_terminate( + ecx: &mut InterpCx<'mir, 'tcx, Self>, + reason: mir::UnwindTerminateReason, + ) -> InterpResult<'tcx>; /// Called for all binary operations where the LHS has pointer type. /// @@ -462,6 +465,7 @@ pub trait Machine<'mir, 'tcx: 'mir>: Sized { /// Called immediately after a stack frame got popped, but before jumping back to the caller. /// The `locals` have already been destroyed! + #[inline(always)] fn after_stack_pop( _ecx: &mut InterpCx<'mir, 'tcx, Self>, _frame: Frame<'mir, 'tcx, Self::Provenance, Self::FrameExtra>, @@ -501,7 +505,10 @@ pub macro compile_time_machine(<$mir: lifetime, $tcx: lifetime>) { } #[inline(always)] - fn unwind_terminate(_ecx: &mut InterpCx<$mir, $tcx, Self>) -> InterpResult<$tcx> { + fn unwind_terminate( + _ecx: &mut InterpCx<$mir, $tcx, Self>, + _reason: mir::UnwindTerminateReason, + ) -> InterpResult<$tcx> { unreachable!("unwinding cannot happen during compile-time evaluation") } diff --git a/compiler/rustc_const_eval/src/interpret/terminator.rs b/compiler/rustc_const_eval/src/interpret/terminator.rs index b2ebcceceb328..ca7c484ea3141 100644 --- a/compiler/rustc_const_eval/src/interpret/terminator.rs +++ b/compiler/rustc_const_eval/src/interpret/terminator.rs @@ -196,8 +196,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { } } - UnwindTerminate => { - M::unwind_terminate(self)?; + UnwindTerminate(reason) => { + M::unwind_terminate(self, reason)?; } // When we encounter Resume, we've finished unwinding diff --git a/compiler/rustc_const_eval/src/transform/check_consts/check.rs b/compiler/rustc_const_eval/src/transform/check_consts/check.rs index e67098a3ac38a..f288ddc25d3a4 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/check.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/check.rs @@ -1037,7 +1037,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> { self.check_op(ops::Generator(hir::GeneratorKind::Gen)) } - TerminatorKind::UnwindTerminate => { + TerminatorKind::UnwindTerminate(_) => { // Cleanup blocks are skipped for const checking (see `visit_basic_block_data`). span_bug!(self.span, "`Terminate` terminator outside of cleanup block") } diff --git a/compiler/rustc_const_eval/src/transform/check_consts/post_drop_elaboration.rs b/compiler/rustc_const_eval/src/transform/check_consts/post_drop_elaboration.rs index a8c61d2c8fd89..fd6bc2ee9af59 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/post_drop_elaboration.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/post_drop_elaboration.rs @@ -106,7 +106,7 @@ impl<'tcx> Visitor<'tcx> for CheckLiveDrops<'_, 'tcx> { } } - mir::TerminatorKind::UnwindTerminate + mir::TerminatorKind::UnwindTerminate(_) | mir::TerminatorKind::Call { .. } | mir::TerminatorKind::Assert { .. } | mir::TerminatorKind::FalseEdge { .. } diff --git a/compiler/rustc_const_eval/src/transform/validate.rs b/compiler/rustc_const_eval/src/transform/validate.rs index 0dfbbf73dce47..b829f24ab7a3d 100644 --- a/compiler/rustc_const_eval/src/transform/validate.rs +++ b/compiler/rustc_const_eval/src/transform/validate.rs @@ -10,8 +10,8 @@ use rustc_middle::mir::{ traversal, BasicBlock, BinOp, Body, BorrowKind, CastKind, CopyNonOverlapping, Local, Location, MirPass, MirPhase, NonDivergingIntrinsic, NullOp, Operand, Place, PlaceElem, PlaceRef, ProjectionElem, RetagKind, RuntimePhase, Rvalue, SourceScope, Statement, StatementKind, - Terminator, TerminatorKind, UnOp, UnwindAction, VarDebugInfo, VarDebugInfoContents, - START_BLOCK, + Terminator, TerminatorKind, UnOp, UnwindAction, UnwindTerminateReason, VarDebugInfo, + VarDebugInfoContents, START_BLOCK, }; use rustc_middle::ty::{self, InstanceDef, ParamEnv, Ty, TyCtxt, TypeVisitableExt}; use rustc_mir_dataflow::impls::MaybeStorageLive; @@ -274,7 +274,16 @@ impl<'a, 'tcx> CfgChecker<'a, 'tcx> { self.fail(location, "`UnwindAction::Continue` in no-unwind function"); } } - UnwindAction::Unreachable | UnwindAction::Terminate => (), + UnwindAction::Terminate(UnwindTerminateReason::InCleanup) => { + if !is_cleanup { + self.fail( + location, + "`UnwindAction::Terminate(InCleanup)` in a non-cleanup block", + ); + } + } + // These are allowed everywhere. + UnwindAction::Unreachable | UnwindAction::Terminate(UnwindTerminateReason::Abi) => (), } } } @@ -501,7 +510,7 @@ impl<'a, 'tcx> Visitor<'tcx> for CfgChecker<'a, 'tcx> { self.fail(location, "Cannot `UnwindResume` in a function that cannot unwind") } } - TerminatorKind::UnwindTerminate => { + TerminatorKind::UnwindTerminate(_) => { let bb = location.block; if !self.body.basic_blocks[bb].is_cleanup { self.fail(location, "Cannot `UnwindTerminate` from non-cleanup basic block") @@ -1233,7 +1242,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { | TerminatorKind::InlineAsm { .. } | TerminatorKind::GeneratorDrop | TerminatorKind::UnwindResume - | TerminatorKind::UnwindTerminate + | TerminatorKind::UnwindTerminate(_) | TerminatorKind::Return | TerminatorKind::Unreachable => {} } diff --git a/compiler/rustc_hir/src/lang_items.rs b/compiler/rustc_hir/src/lang_items.rs index 302a949841316..23b20543d5355 100644 --- a/compiler/rustc_hir/src/lang_items.rs +++ b/compiler/rustc_hir/src/lang_items.rs @@ -238,6 +238,7 @@ language_item_table! { PanicLocation, sym::panic_location, panic_location, Target::Struct, GenericRequirement::None; PanicImpl, sym::panic_impl, panic_impl, Target::Fn, GenericRequirement::None; PanicCannotUnwind, sym::panic_cannot_unwind, panic_cannot_unwind, Target::Fn, GenericRequirement::Exact(0); + PanicInCleanup, sym::panic_in_cleanup, panic_in_cleanup, Target::Fn, GenericRequirement::Exact(0); /// libstd panic entry point. Necessary for const eval to be able to catch it BeginPanic, sym::begin_panic, begin_panic_fn, Target::Fn, GenericRequirement::None; diff --git a/compiler/rustc_middle/src/mir/patch.rs b/compiler/rustc_middle/src/mir/patch.rs index cd74a403ff6b2..419543b898893 100644 --- a/compiler/rustc_middle/src/mir/patch.rs +++ b/compiler/rustc_middle/src/mir/patch.rs @@ -14,7 +14,8 @@ pub struct MirPatch<'tcx> { resume_block: Option, // Only for unreachable in cleanup path. unreachable_cleanup_block: Option, - terminate_block: Option, + // Cached block for UnwindTerminate(InCleanup) + terminate_in_cleanup_block: Option, body_span: Span, next_local: usize, } @@ -29,19 +30,21 @@ impl<'tcx> MirPatch<'tcx> { next_local: body.local_decls.len(), resume_block: None, unreachable_cleanup_block: None, - terminate_block: None, + terminate_in_cleanup_block: None, body_span: body.span, }; for (bb, block) in body.basic_blocks.iter_enumerated() { // Check if we already have a resume block - if let TerminatorKind::UnwindResume = block.terminator().kind && block.statements.is_empty() { + if matches!(block.terminator().kind, TerminatorKind::UnwindResume) + && block.statements.is_empty() + { result.resume_block = Some(bb); continue; } // Check if we already have an unreachable block - if let TerminatorKind::Unreachable = block.terminator().kind + if matches!(block.terminator().kind, TerminatorKind::Unreachable) && block.statements.is_empty() && block.is_cleanup { @@ -50,8 +53,12 @@ impl<'tcx> MirPatch<'tcx> { } // Check if we already have a terminate block - if let TerminatorKind::UnwindTerminate = block.terminator().kind && block.statements.is_empty() { - result.terminate_block = Some(bb); + if matches!( + block.terminator().kind, + TerminatorKind::UnwindTerminate(UnwindTerminateReason::InCleanup) + ) && block.statements.is_empty() + { + result.terminate_in_cleanup_block = Some(bb); continue; } } @@ -93,8 +100,8 @@ impl<'tcx> MirPatch<'tcx> { bb } - pub fn terminate_block(&mut self) -> BasicBlock { - if let Some(bb) = self.terminate_block { + pub fn terminate_block(&mut self, reason: UnwindTerminateReason) -> BasicBlock { + if let Some(bb) = self.terminate_in_cleanup_block && reason == UnwindTerminateReason::InCleanup { return bb; } @@ -102,11 +109,13 @@ impl<'tcx> MirPatch<'tcx> { statements: vec![], terminator: Some(Terminator { source_info: SourceInfo::outermost(self.body_span), - kind: TerminatorKind::UnwindTerminate, + kind: TerminatorKind::UnwindTerminate(reason), }), is_cleanup: true, }); - self.terminate_block = Some(bb); + if reason == UnwindTerminateReason::InCleanup { + self.terminate_in_cleanup_block = Some(bb); + } bb } diff --git a/compiler/rustc_middle/src/mir/syntax.rs b/compiler/rustc_middle/src/mir/syntax.rs index e91e822f915ab..79b64a491f4e5 100644 --- a/compiler/rustc_middle/src/mir/syntax.rs +++ b/compiler/rustc_middle/src/mir/syntax.rs @@ -621,7 +621,7 @@ pub enum TerminatorKind<'tcx> { /// /// Used to prevent unwinding for foreign items or with `-C unwind=abort`. Only permitted in /// cleanup blocks. - UnwindTerminate, + UnwindTerminate(UnwindTerminateReason), /// Returns from the function. /// @@ -813,7 +813,7 @@ impl TerminatorKind<'_> { TerminatorKind::Goto { .. } => "Goto", TerminatorKind::SwitchInt { .. } => "SwitchInt", TerminatorKind::UnwindResume => "UnwindResume", - TerminatorKind::UnwindTerminate => "UnwindTerminate", + TerminatorKind::UnwindTerminate(_) => "UnwindTerminate", TerminatorKind::Return => "Return", TerminatorKind::Unreachable => "Unreachable", TerminatorKind::Drop { .. } => "Drop", @@ -842,11 +842,22 @@ pub enum UnwindAction { /// Terminates the execution if unwind happens. /// /// Depending on the platform and situation this may cause a non-unwindable panic or abort. - Terminate, + Terminate(UnwindTerminateReason), /// Cleanups to be done. Cleanup(BasicBlock), } +/// The reason we are terminating the process during unwinding. +#[derive(Copy, Clone, Debug, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable)] +#[derive(TypeFoldable, TypeVisitable)] +pub enum UnwindTerminateReason { + /// Unwinding is just not possible given the ABI of this function. + Abi, + /// We were already cleaning up for an ongoing unwind, and a *second*, *nested* unwind was + /// triggered by the drop glue. + InCleanup, +} + /// Information about an assertion failure. #[derive(Clone, Hash, HashStable, PartialEq, Debug)] #[derive(TyEncodable, TyDecodable, TypeFoldable, TypeVisitable)] diff --git a/compiler/rustc_middle/src/mir/terminator.rs b/compiler/rustc_middle/src/mir/terminator.rs index bd87563e2bb4c..c4d7f122ea99b 100644 --- a/compiler/rustc_middle/src/mir/terminator.rs +++ b/compiler/rustc_middle/src/mir/terminator.rs @@ -1,3 +1,4 @@ +use rustc_hir::LangItem; use smallvec::SmallVec; use super::{BasicBlock, InlineAsmOperand, Operand, SourceInfo, TerminatorKind, UnwindAction}; @@ -100,6 +101,32 @@ impl<'a> Iterator for SwitchTargetsIter<'a> { impl<'a> ExactSizeIterator for SwitchTargetsIter<'a> {} +impl UnwindAction { + fn cleanup_block(self) -> Option { + match self { + UnwindAction::Cleanup(bb) => Some(bb), + UnwindAction::Continue | UnwindAction::Unreachable | UnwindAction::Terminate(_) => None, + } + } +} + +impl UnwindTerminateReason { + pub fn as_str(self) -> &'static str { + // Keep this in sync with the messages in `core/src/panicking.rs`. + match self { + UnwindTerminateReason::Abi => "panic in a function that cannot unwind", + UnwindTerminateReason::InCleanup => "panic in a destructor during cleanup", + } + } + + pub fn lang_item(self) -> LangItem { + match self { + UnwindTerminateReason::Abi => LangItem::PanicCannotUnwind, + UnwindTerminateReason::InCleanup => LangItem::PanicInCleanup, + } + } +} + #[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)] pub struct Terminator<'tcx> { pub source_info: SourceInfo, @@ -156,7 +183,7 @@ impl<'tcx> TerminatorKind<'tcx> { Some(t).into_iter().chain((&[]).into_iter().copied()) } UnwindResume - | UnwindTerminate + | UnwindTerminate(_) | GeneratorDrop | Return | Unreachable @@ -198,7 +225,7 @@ impl<'tcx> TerminatorKind<'tcx> { Some(t).into_iter().chain(&mut []) } UnwindResume - | UnwindTerminate + | UnwindTerminate(_) | GeneratorDrop | Return | Unreachable @@ -215,7 +242,7 @@ impl<'tcx> TerminatorKind<'tcx> { match *self { TerminatorKind::Goto { .. } | TerminatorKind::UnwindResume - | TerminatorKind::UnwindTerminate + | TerminatorKind::UnwindTerminate(_) | TerminatorKind::Return | TerminatorKind::Unreachable | TerminatorKind::GeneratorDrop @@ -234,7 +261,7 @@ impl<'tcx> TerminatorKind<'tcx> { match *self { TerminatorKind::Goto { .. } | TerminatorKind::UnwindResume - | TerminatorKind::UnwindTerminate + | TerminatorKind::UnwindTerminate(_) | TerminatorKind::Return | TerminatorKind::Unreachable | TerminatorKind::GeneratorDrop @@ -271,18 +298,27 @@ impl<'tcx> Debug for TerminatorKind<'tcx> { let labels = self.fmt_successor_labels(); assert_eq!(successor_count, labels.len()); - let unwind = match self.unwind() { - // Not needed or included in successors - None | Some(UnwindAction::Cleanup(_)) => None, - Some(UnwindAction::Continue) => Some("unwind continue"), - Some(UnwindAction::Unreachable) => Some("unwind unreachable"), - Some(UnwindAction::Terminate) => Some("unwind terminate"), + // `Cleanup` is already included in successors + let show_unwind = !matches!(self.unwind(), None | Some(UnwindAction::Cleanup(_))); + let fmt_unwind = |fmt: &mut Formatter<'_>| -> fmt::Result { + match self.unwind() { + // Not needed or included in successors + None | Some(UnwindAction::Cleanup(_)) => unreachable!(), + Some(UnwindAction::Continue) => write!(fmt, "unwind continue"), + Some(UnwindAction::Unreachable) => write!(fmt, "unwind unreachable"), + Some(UnwindAction::Terminate(reason)) => { + write!(fmt, "unwind terminate ({})", reason.as_str()) + } + } }; - match (successor_count, unwind) { - (0, None) => Ok(()), - (0, Some(unwind)) => write!(fmt, " -> {unwind}"), - (1, None) => write!(fmt, " -> {:?}", self.successors().next().unwrap()), + match (successor_count, show_unwind) { + (0, false) => Ok(()), + (0, true) => { + write!(fmt, " -> ")?; + fmt_unwind(fmt) + } + (1, false) => write!(fmt, " -> {:?}", self.successors().next().unwrap()), _ => { write!(fmt, " -> [")?; for (i, target) in self.successors().enumerate() { @@ -291,8 +327,9 @@ impl<'tcx> Debug for TerminatorKind<'tcx> { } write!(fmt, "{}: {:?}", labels[i], target)?; } - if let Some(unwind) = unwind { - write!(fmt, ", {unwind}")?; + if show_unwind { + write!(fmt, ", ")?; + fmt_unwind(fmt)?; } write!(fmt, "]") } @@ -312,7 +349,9 @@ impl<'tcx> TerminatorKind<'tcx> { Return => write!(fmt, "return"), GeneratorDrop => write!(fmt, "generator_drop"), UnwindResume => write!(fmt, "resume"), - UnwindTerminate => write!(fmt, "abort"), + UnwindTerminate(reason) => { + write!(fmt, "abort(\"{}\")", reason.as_str()) + } Yield { value, resume_arg, .. } => write!(fmt, "{resume_arg:?} = yield({value:?})"), Unreachable => write!(fmt, "unreachable"), Drop { place, .. } => write!(fmt, "drop({place:?})"), @@ -391,7 +430,7 @@ impl<'tcx> TerminatorKind<'tcx> { pub fn fmt_successor_labels(&self) -> Vec> { use self::TerminatorKind::*; match *self { - Return | UnwindResume | UnwindTerminate | Unreachable | GeneratorDrop => vec![], + Return | UnwindResume | UnwindTerminate(_) | Unreachable | GeneratorDrop => vec![], Goto { .. } => vec!["".into()], SwitchInt { ref targets, .. } => targets .values @@ -443,7 +482,8 @@ pub enum TerminatorEdges<'mir, 'tcx> { /// Special action for `Yield`, `Call` and `InlineAsm` terminators. AssignOnReturn { return_: Option, - unwind: UnwindAction, + /// The cleanup block, if it exists. + cleanup: Option, place: CallReturnPlaces<'mir, 'tcx>, }, /// Special edge for `SwitchInt`. @@ -486,7 +526,7 @@ impl<'tcx> TerminatorKind<'tcx> { pub fn edges(&self) -> TerminatorEdges<'_, 'tcx> { use TerminatorKind::*; match *self { - Return | UnwindResume | UnwindTerminate | GeneratorDrop | Unreachable => { + Return | UnwindResume | UnwindTerminate(_) | GeneratorDrop | Unreachable => { TerminatorEdges::None } @@ -496,7 +536,7 @@ impl<'tcx> TerminatorKind<'tcx> { | Drop { target, unwind, place: _, replace: _ } | FalseUnwind { real_target: target, unwind } => match unwind { UnwindAction::Cleanup(unwind) => TerminatorEdges::Double(target, unwind), - UnwindAction::Continue | UnwindAction::Terminate | UnwindAction::Unreachable => { + UnwindAction::Continue | UnwindAction::Terminate(_) | UnwindAction::Unreachable => { TerminatorEdges::Single(target) } }, @@ -508,7 +548,7 @@ impl<'tcx> TerminatorKind<'tcx> { Yield { resume: target, drop, resume_arg, value: _ } => { TerminatorEdges::AssignOnReturn { return_: Some(target), - unwind: drop.map_or(UnwindAction::Terminate, UnwindAction::Cleanup), + cleanup: drop, place: CallReturnPlaces::Yield(resume_arg), } } @@ -516,7 +556,7 @@ impl<'tcx> TerminatorKind<'tcx> { Call { unwind, destination, target, func: _, args: _, fn_span: _, call_source: _ } => { TerminatorEdges::AssignOnReturn { return_: target, - unwind, + cleanup: unwind.cleanup_block(), place: CallReturnPlaces::Call(destination), } } @@ -530,7 +570,7 @@ impl<'tcx> TerminatorKind<'tcx> { unwind, } => TerminatorEdges::AssignOnReturn { return_: destination, - unwind, + cleanup: unwind.cleanup_block(), place: CallReturnPlaces::InlineAsm(operands), }, diff --git a/compiler/rustc_middle/src/mir/visit.rs b/compiler/rustc_middle/src/mir/visit.rs index b3d3366ae1042..87b04aabe6a39 100644 --- a/compiler/rustc_middle/src/mir/visit.rs +++ b/compiler/rustc_middle/src/mir/visit.rs @@ -470,7 +470,7 @@ macro_rules! make_mir_visitor { match kind { TerminatorKind::Goto { .. } | TerminatorKind::UnwindResume | - TerminatorKind::UnwindTerminate | + TerminatorKind::UnwindTerminate(_) | TerminatorKind::GeneratorDrop | TerminatorKind::Unreachable | TerminatorKind::FalseEdge { .. } | diff --git a/compiler/rustc_mir_build/src/build/scope.rs b/compiler/rustc_mir_build/src/build/scope.rs index 567e7bfb5bf8c..4cf6a349af76c 100644 --- a/compiler/rustc_mir_build/src/build/scope.rs +++ b/compiler/rustc_mir_build/src/build/scope.rs @@ -370,7 +370,7 @@ impl DropTree { let terminator = TerminatorKind::Drop { target: blocks[drop_data.1].unwrap(), // The caller will handle this if needed. - unwind: UnwindAction::Terminate, + unwind: UnwindAction::Terminate(UnwindTerminateReason::InCleanup), place: drop_data.0.local.into(), replace: false, }; @@ -1507,7 +1507,7 @@ impl<'tcx> DropTreeBuilder<'tcx> for Unwind { TerminatorKind::Goto { .. } | TerminatorKind::SwitchInt { .. } | TerminatorKind::UnwindResume - | TerminatorKind::UnwindTerminate + | TerminatorKind::UnwindTerminate(_) | TerminatorKind::Return | TerminatorKind::Unreachable | TerminatorKind::Yield { .. } diff --git a/compiler/rustc_mir_build/src/lints.rs b/compiler/rustc_mir_build/src/lints.rs index 84c80bf41a4d2..94be38beee44c 100644 --- a/compiler/rustc_mir_build/src/lints.rs +++ b/compiler/rustc_mir_build/src/lints.rs @@ -186,7 +186,7 @@ impl<'mir, 'tcx, C: TerminatorClassifier<'tcx>> TriColorVisitor UnwindAction { match self { Unwind::To(bb) => UnwindAction::Cleanup(bb), - Unwind::InCleanup => UnwindAction::Terminate, + Unwind::InCleanup => UnwindAction::Terminate(UnwindTerminateReason::InCleanup), } } diff --git a/compiler/rustc_mir_dataflow/src/framework/direction.rs b/compiler/rustc_mir_dataflow/src/framework/direction.rs index 8a9e37c5a4fda..70451edd50046 100644 --- a/compiler/rustc_mir_dataflow/src/framework/direction.rs +++ b/compiler/rustc_mir_dataflow/src/framework/direction.rs @@ -1,5 +1,5 @@ use rustc_middle::mir::{ - self, BasicBlock, CallReturnPlaces, Location, SwitchTargets, TerminatorEdges, UnwindAction, + self, BasicBlock, CallReturnPlaces, Location, SwitchTargets, TerminatorEdges, }; use std::ops::RangeInclusive; @@ -486,10 +486,10 @@ impl Direction for Forward { propagate(target, exit_state); propagate(unwind, exit_state); } - TerminatorEdges::AssignOnReturn { return_, unwind, place } => { + TerminatorEdges::AssignOnReturn { return_, cleanup, place } => { // This must be done *first*, otherwise the unwind path will see the assignments. - if let UnwindAction::Cleanup(unwind) = unwind { - propagate(unwind, exit_state); + if let Some(cleanup) = cleanup { + propagate(cleanup, exit_state); } if let Some(return_) = return_ { analysis.apply_call_return_effect(exit_state, bb, place); diff --git a/compiler/rustc_mir_dataflow/src/impls/borrowed_locals.rs b/compiler/rustc_mir_dataflow/src/impls/borrowed_locals.rs index 5ed8f20b73f1a..3ad9d3d426404 100644 --- a/compiler/rustc_mir_dataflow/src/impls/borrowed_locals.rs +++ b/compiler/rustc_mir_dataflow/src/impls/borrowed_locals.rs @@ -131,7 +131,7 @@ where } } - TerminatorKind::UnwindTerminate + TerminatorKind::UnwindTerminate(_) | TerminatorKind::Assert { .. } | TerminatorKind::Call { .. } | TerminatorKind::FalseEdge { .. } diff --git a/compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs b/compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs index 531390c2f0772..94d6eb67d4994 100644 --- a/compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs +++ b/compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs @@ -291,7 +291,7 @@ impl<'tcx> crate::GenKillAnalysis<'tcx> for MaybeRequiresStorage<'_, '_, 'tcx> { // Nothing to do for these. Match exhaustively so this fails to compile when new // variants are added. - TerminatorKind::UnwindTerminate + TerminatorKind::UnwindTerminate(_) | TerminatorKind::Assert { .. } | TerminatorKind::Drop { .. } | TerminatorKind::FalseEdge { .. } @@ -328,7 +328,7 @@ impl<'tcx> crate::GenKillAnalysis<'tcx> for MaybeRequiresStorage<'_, '_, 'tcx> { // Nothing to do for these. Match exhaustively so this fails to compile when new // variants are added. TerminatorKind::Yield { .. } - | TerminatorKind::UnwindTerminate + | TerminatorKind::UnwindTerminate(_) | TerminatorKind::Assert { .. } | TerminatorKind::Drop { .. } | TerminatorKind::FalseEdge { .. } diff --git a/compiler/rustc_mir_dataflow/src/move_paths/builder.rs b/compiler/rustc_mir_dataflow/src/move_paths/builder.rs index 4adf3dec61bee..2e3b9577b5030 100644 --- a/compiler/rustc_mir_dataflow/src/move_paths/builder.rs +++ b/compiler/rustc_mir_dataflow/src/move_paths/builder.rs @@ -371,7 +371,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> { // need recording. | TerminatorKind::Return | TerminatorKind::UnwindResume - | TerminatorKind::UnwindTerminate + | TerminatorKind::UnwindTerminate(_) | TerminatorKind::GeneratorDrop | TerminatorKind::Unreachable | TerminatorKind::Drop { .. } => {} diff --git a/compiler/rustc_mir_dataflow/src/value_analysis.rs b/compiler/rustc_mir_dataflow/src/value_analysis.rs index 1eea8eef0adf2..6872ef5e98590 100644 --- a/compiler/rustc_mir_dataflow/src/value_analysis.rs +++ b/compiler/rustc_mir_dataflow/src/value_analysis.rs @@ -270,7 +270,7 @@ pub trait ValueAnalysis<'tcx> { } TerminatorKind::Goto { .. } | TerminatorKind::UnwindResume - | TerminatorKind::UnwindTerminate + | TerminatorKind::UnwindTerminate(_) | TerminatorKind::Return | TerminatorKind::Unreachable | TerminatorKind::Assert { .. } diff --git a/compiler/rustc_mir_transform/src/abort_unwinding_calls.rs b/compiler/rustc_mir_transform/src/abort_unwinding_calls.rs index 5aed89139e2fa..4500bb7ff0f01 100644 --- a/compiler/rustc_mir_transform/src/abort_unwinding_calls.rs +++ b/compiler/rustc_mir_transform/src/abort_unwinding_calls.rs @@ -104,7 +104,7 @@ impl<'tcx> MirPass<'tcx> for AbortUnwindingCalls { for id in calls_to_terminate { let cleanup = body.basic_blocks_mut()[id].terminator_mut().unwind_mut().unwrap(); - *cleanup = UnwindAction::Terminate; + *cleanup = UnwindAction::Terminate(UnwindTerminateReason::Abi); } for id in cleanups_to_remove { diff --git a/compiler/rustc_mir_transform/src/add_call_guards.rs b/compiler/rustc_mir_transform/src/add_call_guards.rs index fb4705e0754cf..b814fbf32b141 100644 --- a/compiler/rustc_mir_transform/src/add_call_guards.rs +++ b/compiler/rustc_mir_transform/src/add_call_guards.rs @@ -53,8 +53,10 @@ impl AddCallGuards { kind: TerminatorKind::Call { target: Some(ref mut destination), unwind, .. }, source_info, }) if pred_count[*destination] > 1 - && (matches!(unwind, UnwindAction::Cleanup(_) | UnwindAction::Terminate) - || self == &AllCallEdges) => + && (matches!( + unwind, + UnwindAction::Cleanup(_) | UnwindAction::Terminate(_) + ) || self == &AllCallEdges) => { // It's a critical edge, break it let call_guard = BasicBlockData { diff --git a/compiler/rustc_mir_transform/src/check_unsafety.rs b/compiler/rustc_mir_transform/src/check_unsafety.rs index e72db1a59a051..0fce9cb19a848 100644 --- a/compiler/rustc_mir_transform/src/check_unsafety.rs +++ b/compiler/rustc_mir_transform/src/check_unsafety.rs @@ -58,7 +58,7 @@ impl<'tcx> Visitor<'tcx> for UnsafetyChecker<'_, 'tcx> { | TerminatorKind::Assert { .. } | TerminatorKind::GeneratorDrop | TerminatorKind::UnwindResume - | TerminatorKind::UnwindTerminate + | TerminatorKind::UnwindTerminate(_) | TerminatorKind::Return | TerminatorKind::Unreachable | TerminatorKind::FalseEdge { .. } diff --git a/compiler/rustc_mir_transform/src/const_prop_lint.rs b/compiler/rustc_mir_transform/src/const_prop_lint.rs index 4f8ca916d5b42..da8913d604b9f 100644 --- a/compiler/rustc_mir_transform/src/const_prop_lint.rs +++ b/compiler/rustc_mir_transform/src/const_prop_lint.rs @@ -679,7 +679,7 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> { // None of these have Operands to const-propagate. TerminatorKind::Goto { .. } | TerminatorKind::UnwindResume - | TerminatorKind::UnwindTerminate + | TerminatorKind::UnwindTerminate(_) | TerminatorKind::Return | TerminatorKind::Unreachable | TerminatorKind::Drop { .. } diff --git a/compiler/rustc_mir_transform/src/coverage/graph.rs b/compiler/rustc_mir_transform/src/coverage/graph.rs index d3d4fcd3a5277..60461691e7f51 100644 --- a/compiler/rustc_mir_transform/src/coverage/graph.rs +++ b/compiler/rustc_mir_transform/src/coverage/graph.rs @@ -116,7 +116,7 @@ impl CoverageGraph { match term.kind { TerminatorKind::Return { .. } - | TerminatorKind::UnwindTerminate + | TerminatorKind::UnwindTerminate(_) | TerminatorKind::Yield { .. } | TerminatorKind::SwitchInt { .. } => { // The `bb` has more than one _outgoing_ edge, or exits the function. Save the diff --git a/compiler/rustc_mir_transform/src/coverage/spans.rs b/compiler/rustc_mir_transform/src/coverage/spans.rs index 6fabaca524a0f..717763a94a0e3 100644 --- a/compiler/rustc_mir_transform/src/coverage/spans.rs +++ b/compiler/rustc_mir_transform/src/coverage/spans.rs @@ -868,7 +868,7 @@ pub(super) fn filtered_terminator_span(terminator: &Terminator<'_>) -> Option (), TerminatorKind::Drop { .. } => { diff --git a/compiler/rustc_mir_transform/src/elaborate_drops.rs b/compiler/rustc_mir_transform/src/elaborate_drops.rs index a80ae480089b0..78d7ffb3698a0 100644 --- a/compiler/rustc_mir_transform/src/elaborate_drops.rs +++ b/compiler/rustc_mir_transform/src/elaborate_drops.rs @@ -362,8 +362,13 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> { UnwindAction::Unreachable => { Unwind::To(self.patch.unreachable_cleanup_block()) } - UnwindAction::Terminate => { - Unwind::To(self.patch.terminate_block()) + UnwindAction::Terminate(reason) => { + debug_assert_ne!( + reason, + UnwindTerminateReason::InCleanup, + "we are not in a cleanup block, InCleanup reason should be impossible" + ); + Unwind::To(self.patch.terminate_block(reason)) } } }; @@ -496,7 +501,8 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> { if let TerminatorKind::Call { destination, target: Some(_), - unwind: UnwindAction::Continue | UnwindAction::Unreachable | UnwindAction::Terminate, + unwind: + UnwindAction::Continue | UnwindAction::Unreachable | UnwindAction::Terminate(_), .. } = data.terminator().kind { diff --git a/compiler/rustc_mir_transform/src/generator.rs b/compiler/rustc_mir_transform/src/generator.rs index 96077322575e5..1e7161189c3a4 100644 --- a/compiler/rustc_mir_transform/src/generator.rs +++ b/compiler/rustc_mir_transform/src/generator.rs @@ -1091,7 +1091,7 @@ fn elaborate_generator_drops<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { UnwindAction::Cleanup(tgt) => tgt, UnwindAction::Continue => elaborator.patch.resume_block(), UnwindAction::Unreachable => elaborator.patch.unreachable_cleanup_block(), - UnwindAction::Terminate => elaborator.patch.terminate_block(), + UnwindAction::Terminate(reason) => elaborator.patch.terminate_block(reason), }) }; elaborate_drop( @@ -1239,7 +1239,7 @@ fn can_unwind<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>) -> bool { // These never unwind. TerminatorKind::Goto { .. } | TerminatorKind::SwitchInt { .. } - | TerminatorKind::UnwindTerminate + | TerminatorKind::UnwindTerminate(_) | TerminatorKind::Return | TerminatorKind::Unreachable | TerminatorKind::GeneratorDrop @@ -1759,7 +1759,7 @@ impl<'tcx> Visitor<'tcx> for EnsureGeneratorFieldAssignmentsNeverAlias<'_> { | TerminatorKind::Goto { .. } | TerminatorKind::SwitchInt { .. } | TerminatorKind::UnwindResume - | TerminatorKind::UnwindTerminate + | TerminatorKind::UnwindTerminate(_) | TerminatorKind::Return | TerminatorKind::Unreachable | TerminatorKind::Drop { .. } diff --git a/compiler/rustc_mir_transform/src/inline.rs b/compiler/rustc_mir_transform/src/inline.rs index 734e93783d109..9551c7a2a8d6b 100644 --- a/compiler/rustc_mir_transform/src/inline.rs +++ b/compiler/rustc_mir_transform/src/inline.rs @@ -906,12 +906,12 @@ impl Integrator<'_, '_> { UnwindAction::Cleanup(_) | UnwindAction::Continue => { bug!("cleanup on cleanup block"); } - UnwindAction::Unreachable | UnwindAction::Terminate => return unwind, + UnwindAction::Unreachable | UnwindAction::Terminate(_) => return unwind, } } match unwind { - UnwindAction::Unreachable | UnwindAction::Terminate => unwind, + UnwindAction::Unreachable | UnwindAction::Terminate(_) => unwind, UnwindAction::Cleanup(target) => UnwindAction::Cleanup(self.map_block(target)), // Add an unwind edge to the original call's cleanup block UnwindAction::Continue => self.cleanup_block, @@ -1022,10 +1022,10 @@ impl<'tcx> MutVisitor<'tcx> for Integrator<'_, 'tcx> { UnwindAction::Cleanup(tgt) => TerminatorKind::Goto { target: tgt }, UnwindAction::Continue => TerminatorKind::UnwindResume, UnwindAction::Unreachable => TerminatorKind::Unreachable, - UnwindAction::Terminate => TerminatorKind::UnwindTerminate, + UnwindAction::Terminate(reason) => TerminatorKind::UnwindTerminate(reason), }; } - TerminatorKind::UnwindTerminate => {} + TerminatorKind::UnwindTerminate(_) => {} TerminatorKind::Unreachable => {} TerminatorKind::FalseEdge { ref mut real_target, ref mut imaginary_target } => { *real_target = self.map_block(*real_target); diff --git a/compiler/rustc_mir_transform/src/remove_noop_landing_pads.rs b/compiler/rustc_mir_transform/src/remove_noop_landing_pads.rs index 5782adbb3ffa3..8c48a667786b1 100644 --- a/compiler/rustc_mir_transform/src/remove_noop_landing_pads.rs +++ b/compiler/rustc_mir_transform/src/remove_noop_landing_pads.rs @@ -72,7 +72,7 @@ impl RemoveNoopLandingPads { TerminatorKind::GeneratorDrop | TerminatorKind::Yield { .. } | TerminatorKind::Return - | TerminatorKind::UnwindTerminate + | TerminatorKind::UnwindTerminate(_) | TerminatorKind::Unreachable | TerminatorKind::Call { .. } | TerminatorKind::Assert { .. } diff --git a/compiler/rustc_mir_transform/src/separate_const_switch.rs b/compiler/rustc_mir_transform/src/separate_const_switch.rs index de1b80585d15c..e1e4acccccd36 100644 --- a/compiler/rustc_mir_transform/src/separate_const_switch.rs +++ b/compiler/rustc_mir_transform/src/separate_const_switch.rs @@ -114,7 +114,7 @@ pub fn separate_const_switch(body: &mut Body<'_>) -> usize { | TerminatorKind::Assert { .. } | TerminatorKind::FalseUnwind { .. } | TerminatorKind::Yield { .. } - | TerminatorKind::UnwindTerminate + | TerminatorKind::UnwindTerminate(_) | TerminatorKind::Return | TerminatorKind::Unreachable | TerminatorKind::InlineAsm { .. } @@ -166,7 +166,7 @@ pub fn separate_const_switch(body: &mut Body<'_>) -> usize { } TerminatorKind::UnwindResume - | TerminatorKind::UnwindTerminate + | TerminatorKind::UnwindTerminate(_) | TerminatorKind::Return | TerminatorKind::Unreachable | TerminatorKind::GeneratorDrop diff --git a/compiler/rustc_mir_transform/src/shim.rs b/compiler/rustc_mir_transform/src/shim.rs index 079cf9eb4e968..e1000d9693239 100644 --- a/compiler/rustc_mir_transform/src/shim.rs +++ b/compiler/rustc_mir_transform/src/shim.rs @@ -570,10 +570,10 @@ impl<'tcx> CloneShimBuilder<'tcx> { TerminatorKind::Drop { place: dest_field, target: unwind, - unwind: UnwindAction::Terminate, + unwind: UnwindAction::Terminate(UnwindTerminateReason::InCleanup), replace: false, }, - true, + /* is_cleanup */ true, ); unwind = next_unwind; } @@ -851,10 +851,10 @@ fn build_call_shim<'tcx>( TerminatorKind::Drop { place: rcvr_place(), target: BasicBlock::new(4), - unwind: UnwindAction::Terminate, + unwind: UnwindAction::Terminate(UnwindTerminateReason::InCleanup), replace: false, }, - true, + /* is_cleanup */ true, ); // BB #4 - resume diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index cd7908e75e201..f917e52109a83 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -737,6 +737,13 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> { let source = self.body.source_info(location).span; let tcx = self.tcx; + let push_mono_lang_item = |this: &mut Self, lang_item: LangItem| { + let instance = Instance::mono(tcx, tcx.require_lang_item(lang_item, Some(source))); + if should_codegen_locally(tcx, &instance) { + this.output.push(create_fn_mono_item(tcx, instance, source)); + } + }; + match terminator.kind { mir::TerminatorKind::Call { ref func, .. } => { let callee_ty = func.ty(self.body, tcx); @@ -771,19 +778,10 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> { mir::AssertKind::BoundsCheck { .. } => LangItem::PanicBoundsCheck, _ => LangItem::Panic, }; - let instance = Instance::mono(tcx, tcx.require_lang_item(lang_item, Some(source))); - if should_codegen_locally(tcx, &instance) { - self.output.push(create_fn_mono_item(tcx, instance, source)); - } + push_mono_lang_item(self, lang_item); } - mir::TerminatorKind::UnwindTerminate { .. } => { - let instance = Instance::mono( - tcx, - tcx.require_lang_item(LangItem::PanicCannotUnwind, Some(source)), - ); - if should_codegen_locally(tcx, &instance) { - self.output.push(create_fn_mono_item(tcx, instance, source)); - } + mir::TerminatorKind::UnwindTerminate(reason) => { + push_mono_lang_item(self, reason.lang_item()); } mir::TerminatorKind::Goto { .. } | mir::TerminatorKind::SwitchInt { .. } @@ -796,14 +794,8 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> { | mir::TerminatorKind::FalseUnwind { .. } => bug!(), } - if let Some(mir::UnwindAction::Terminate) = terminator.unwind() { - let instance = Instance::mono( - tcx, - tcx.require_lang_item(LangItem::PanicCannotUnwind, Some(source)), - ); - if should_codegen_locally(tcx, &instance) { - self.output.push(create_fn_mono_item(tcx, instance, source)); - } + if let Some(mir::UnwindAction::Terminate(reason)) = terminator.unwind() { + push_mono_lang_item(self, reason.lang_item()); } self.super_terminator(terminator, location); diff --git a/compiler/rustc_smir/src/rustc_smir/mod.rs b/compiler/rustc_smir/src/rustc_smir/mod.rs index aea59c31379e7..092d4932a6d62 100644 --- a/compiler/rustc_smir/src/rustc_smir/mod.rs +++ b/compiler/rustc_smir/src/rustc_smir/mod.rs @@ -590,7 +590,7 @@ impl<'tcx> Stable<'tcx> for mir::UnwindAction { match self { UnwindAction::Continue => stable_mir::mir::UnwindAction::Continue, UnwindAction::Unreachable => stable_mir::mir::UnwindAction::Unreachable, - UnwindAction::Terminate => stable_mir::mir::UnwindAction::Terminate, + UnwindAction::Terminate(_) => stable_mir::mir::UnwindAction::Terminate, UnwindAction::Cleanup(bb) => stable_mir::mir::UnwindAction::Cleanup(bb.as_usize()), } } @@ -788,7 +788,7 @@ impl<'tcx> Stable<'tcx> for mir::Terminator<'tcx> { otherwise: targets.otherwise().as_usize(), }, UnwindResume => Terminator::Resume, - UnwindTerminate => Terminator::Abort, + UnwindTerminate(_) => Terminator::Abort, Return => Terminator::Return, Unreachable => Terminator::Unreachable, Drop { place, target, unwind, replace: _ } => Terminator::Drop { diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 8aec12f128ec6..90dc6766cf28e 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1100,6 +1100,7 @@ symbols! { panic_handler, panic_impl, panic_implementation, + panic_in_cleanup, panic_info, panic_location, panic_misaligned_pointer_dereference, diff --git a/library/core/src/panicking.rs b/library/core/src/panicking.rs index 7b6249207fe6f..d5e4c113018c1 100644 --- a/library/core/src/panicking.rs +++ b/library/core/src/panicking.rs @@ -179,6 +179,8 @@ fn panic_misaligned_pointer_dereference(required: usize, found: usize) -> ! { /// Panic because we cannot unwind out of a function. /// +/// This is a separate function to avoid the codesize impact of each crate containing the string to +/// pass to `panic_nounwind`. /// This function is called directly by the codegen backend, and must not have /// any extra arguments (including those synthesized by track_caller). #[cfg_attr(not(feature = "panic_immediate_abort"), inline(never), cold)] @@ -189,6 +191,21 @@ fn panic_cannot_unwind() -> ! { panic_nounwind("panic in a function that cannot unwind") } +/// Panic because we are unwinding out of a destructor during cleanup. +/// +/// This is a separate function to avoid the codesize impact of each crate containing the string to +/// pass to `panic_nounwind`. +/// This function is called directly by the codegen backend, and must not have +/// any extra arguments (including those synthesized by track_caller). +#[cfg(not(bootstrap))] +#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never), cold)] +#[cfg_attr(feature = "panic_immediate_abort", inline)] +#[lang = "panic_in_cleanup"] // needed by codegen for panic in nounwind function +#[rustc_nounwind] +fn panic_in_cleanup() -> ! { + panic_nounwind("panic in a destructor during cleanup") +} + /// This function is used instead of panic_fmt in const eval. #[lang = "const_panic_fmt"] #[rustc_const_unstable(feature = "core_panic", issue = "none")] diff --git a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs index 43523faa23612..17233058c9c93 100644 --- a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs +++ b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs @@ -292,7 +292,7 @@ fn check_terminator<'tcx>( | TerminatorKind::Goto { .. } | TerminatorKind::Return | TerminatorKind::UnwindResume - | TerminatorKind::UnwindTerminate + | TerminatorKind::UnwindTerminate(_) | TerminatorKind::Unreachable => Ok(()), TerminatorKind::Drop { place, .. } => { if !is_ty_const_destruct(tcx, place.ty(&body.local_decls, tcx).ty, body) { diff --git a/src/tools/miri/src/machine.rs b/src/tools/miri/src/machine.rs index 550c9650fb39d..17cfcbb201876 100644 --- a/src/tools/miri/src/machine.rs +++ b/src/tools/miri/src/machine.rs @@ -975,9 +975,9 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> { ecx.start_panic_nounwind(msg) } - fn unwind_terminate(ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx> { + fn unwind_terminate(ecx: &mut InterpCx<'mir, 'tcx, Self>, reason: mir::UnwindTerminateReason) -> InterpResult<'tcx> { // Call the lang item. - let panic = ecx.tcx.lang_items().panic_cannot_unwind().unwrap(); + let panic = ecx.tcx.lang_items().get(reason.lang_item()).unwrap(); let panic = ty::Instance::mono(ecx.tcx.tcx, panic); ecx.call_function( panic, diff --git a/src/tools/miri/tests/fail/panic/double_panic.stderr b/src/tools/miri/tests/fail/panic/double_panic.stderr index 25c9a7c44bcb1..9efba031250be 100644 --- a/src/tools/miri/tests/fail/panic/double_panic.stderr +++ b/src/tools/miri/tests/fail/panic/double_panic.stderr @@ -5,7 +5,7 @@ thread 'main' panicked at $DIR/double_panic.rs:LL:CC: second stack backtrace: thread 'main' panicked at RUSTLIB/core/src/panicking.rs:LL:CC: -panic in a function that cannot unwind +panic in a destructor during cleanup stack backtrace: thread caused non-unwinding panic. aborting. error: abnormal termination: the program aborted execution @@ -20,7 +20,7 @@ LL | ABORT(); = note: inside `std::sys_common::backtrace::__rust_end_short_backtrace::<[closure@std::panicking::begin_panic_handler::{closure#0}], !>` at RUSTLIB/std/src/sys_common/backtrace.rs:LL:CC = note: inside `std::panicking::begin_panic_handler` at RUSTLIB/std/src/panicking.rs:LL:CC = note: inside `core::panicking::panic_nounwind` at RUSTLIB/core/src/panicking.rs:LL:CC - = note: inside `core::panicking::panic_cannot_unwind` at RUSTLIB/core/src/panicking.rs:LL:CC + = note: inside `core::panicking::panic_in_cleanup` at RUSTLIB/core/src/panicking.rs:LL:CC note: inside `main` --> $DIR/double_panic.rs:LL:CC | diff --git a/tests/mir-opt/asm_unwind_panic_abort.main.AbortUnwindingCalls.after.mir b/tests/mir-opt/asm_unwind_panic_abort.main.AbortUnwindingCalls.after.mir index a59ffe97bf013..8b9c853eb8534 100644 --- a/tests/mir-opt/asm_unwind_panic_abort.main.AbortUnwindingCalls.after.mir +++ b/tests/mir-opt/asm_unwind_panic_abort.main.AbortUnwindingCalls.after.mir @@ -9,7 +9,7 @@ fn main() -> () { bb0: { StorageLive(_1); _1 = const (); - asm!("", options(MAY_UNWIND)) -> [return: bb1, unwind terminate]; + asm!("", options(MAY_UNWIND)) -> [return: bb1, unwind terminate (panic in a function that cannot unwind)]; } bb1: { diff --git a/tests/mir-opt/basic_assignment.main.ElaborateDrops.diff b/tests/mir-opt/basic_assignment.main.ElaborateDrops.diff index 15269fb8f6c6a..2b6e0fe489a6f 100644 --- a/tests/mir-opt/basic_assignment.main.ElaborateDrops.diff +++ b/tests/mir-opt/basic_assignment.main.ElaborateDrops.diff @@ -47,7 +47,7 @@ bb2 (cleanup): { _5 = move _6; -- drop(_6) -> [return: bb6, unwind terminate]; +- drop(_6) -> [return: bb6, unwind terminate (panic in a destructor during cleanup)]; + goto -> bb6; } @@ -71,12 +71,12 @@ } bb6 (cleanup): { -- drop(_5) -> [return: bb7, unwind terminate]; +- drop(_5) -> [return: bb7, unwind terminate (panic in a destructor during cleanup)]; + goto -> bb7; } bb7 (cleanup): { -- drop(_4) -> [return: bb8, unwind terminate]; +- drop(_4) -> [return: bb8, unwind terminate (panic in a destructor during cleanup)]; + goto -> bb8; } diff --git a/tests/mir-opt/basic_assignment.main.SimplifyCfg-initial.after.mir b/tests/mir-opt/basic_assignment.main.SimplifyCfg-initial.after.mir index a9bc2e8903448..fac407ae1ea6b 100644 --- a/tests/mir-opt/basic_assignment.main.SimplifyCfg-initial.after.mir +++ b/tests/mir-opt/basic_assignment.main.SimplifyCfg-initial.after.mir @@ -51,7 +51,7 @@ fn main() -> () { bb2 (cleanup): { _5 = move _6; - drop(_6) -> [return: bb6, unwind terminate]; + drop(_6) -> [return: bb6, unwind terminate (panic in a destructor during cleanup)]; } bb3: { @@ -73,11 +73,11 @@ fn main() -> () { } bb6 (cleanup): { - drop(_5) -> [return: bb7, unwind terminate]; + drop(_5) -> [return: bb7, unwind terminate (panic in a destructor during cleanup)]; } bb7 (cleanup): { - drop(_4) -> [return: bb8, unwind terminate]; + drop(_4) -> [return: bb8, unwind terminate (panic in a destructor during cleanup)]; } bb8 (cleanup): { diff --git a/tests/mir-opt/box_expr.main.ElaborateDrops.before.panic-abort.mir b/tests/mir-opt/box_expr.main.ElaborateDrops.before.panic-abort.mir index d196b045a1b8e..f7cfcf27fe5fc 100644 --- a/tests/mir-opt/box_expr.main.ElaborateDrops.before.panic-abort.mir +++ b/tests/mir-opt/box_expr.main.ElaborateDrops.before.panic-abort.mir @@ -54,15 +54,15 @@ fn main() -> () { } bb6 (cleanup): { - drop(_7) -> [return: bb7, unwind terminate]; + drop(_7) -> [return: bb7, unwind terminate (panic in a destructor during cleanup)]; } bb7 (cleanup): { - drop(_1) -> [return: bb9, unwind terminate]; + drop(_1) -> [return: bb9, unwind terminate (panic in a destructor during cleanup)]; } bb8 (cleanup): { - drop(_5) -> [return: bb9, unwind terminate]; + drop(_5) -> [return: bb9, unwind terminate (panic in a destructor during cleanup)]; } bb9 (cleanup): { diff --git a/tests/mir-opt/box_expr.main.ElaborateDrops.before.panic-unwind.mir b/tests/mir-opt/box_expr.main.ElaborateDrops.before.panic-unwind.mir index a72d22a9c9ffb..4cfdc8701c6b9 100644 --- a/tests/mir-opt/box_expr.main.ElaborateDrops.before.panic-unwind.mir +++ b/tests/mir-opt/box_expr.main.ElaborateDrops.before.panic-unwind.mir @@ -54,15 +54,15 @@ fn main() -> () { } bb6 (cleanup): { - drop(_7) -> [return: bb7, unwind terminate]; + drop(_7) -> [return: bb7, unwind terminate (panic in a destructor during cleanup)]; } bb7 (cleanup): { - drop(_1) -> [return: bb9, unwind terminate]; + drop(_1) -> [return: bb9, unwind terminate (panic in a destructor during cleanup)]; } bb8 (cleanup): { - drop(_5) -> [return: bb9, unwind terminate]; + drop(_5) -> [return: bb9, unwind terminate (panic in a destructor during cleanup)]; } bb9 (cleanup): { diff --git a/tests/mir-opt/building/enum_cast.droppy.built.after.mir b/tests/mir-opt/building/enum_cast.droppy.built.after.mir index 1caf9e4a523c7..d1f8b8daf74d7 100644 --- a/tests/mir-opt/building/enum_cast.droppy.built.after.mir +++ b/tests/mir-opt/building/enum_cast.droppy.built.after.mir @@ -62,7 +62,7 @@ fn droppy() -> () { } bb4 (cleanup): { - drop(_2) -> [return: bb5, unwind terminate]; + drop(_2) -> [return: bb5, unwind terminate (panic in a destructor during cleanup)]; } bb5 (cleanup): { diff --git a/tests/mir-opt/building/uniform_array_move_out.move_out_by_subslice.built.after.mir b/tests/mir-opt/building/uniform_array_move_out.move_out_by_subslice.built.after.mir index fea1138ba8d92..f7fc1eb7ce30c 100644 --- a/tests/mir-opt/building/uniform_array_move_out.move_out_by_subslice.built.after.mir +++ b/tests/mir-opt/building/uniform_array_move_out.move_out_by_subslice.built.after.mir @@ -89,15 +89,15 @@ fn move_out_by_subslice() -> () { } bb9 (cleanup): { - drop(_1) -> [return: bb12, unwind terminate]; + drop(_1) -> [return: bb12, unwind terminate (panic in a destructor during cleanup)]; } bb10 (cleanup): { - drop(_7) -> [return: bb11, unwind terminate]; + drop(_7) -> [return: bb11, unwind terminate (panic in a destructor during cleanup)]; } bb11 (cleanup): { - drop(_2) -> [return: bb12, unwind terminate]; + drop(_2) -> [return: bb12, unwind terminate (panic in a destructor during cleanup)]; } bb12 (cleanup): { diff --git a/tests/mir-opt/building/uniform_array_move_out.move_out_from_end.built.after.mir b/tests/mir-opt/building/uniform_array_move_out.move_out_from_end.built.after.mir index 3def40a8578f9..95c061dc9fa92 100644 --- a/tests/mir-opt/building/uniform_array_move_out.move_out_from_end.built.after.mir +++ b/tests/mir-opt/building/uniform_array_move_out.move_out_from_end.built.after.mir @@ -89,15 +89,15 @@ fn move_out_from_end() -> () { } bb9 (cleanup): { - drop(_1) -> [return: bb12, unwind terminate]; + drop(_1) -> [return: bb12, unwind terminate (panic in a destructor during cleanup)]; } bb10 (cleanup): { - drop(_7) -> [return: bb11, unwind terminate]; + drop(_7) -> [return: bb11, unwind terminate (panic in a destructor during cleanup)]; } bb11 (cleanup): { - drop(_2) -> [return: bb12, unwind terminate]; + drop(_2) -> [return: bb12, unwind terminate (panic in a destructor during cleanup)]; } bb12 (cleanup): { diff --git a/tests/mir-opt/combine_clone_of_primitives.{impl#0}-clone.InstSimplify.panic-unwind.diff b/tests/mir-opt/combine_clone_of_primitives.{impl#0}-clone.InstSimplify.panic-unwind.diff index 1a4372afe697f..20f627a567dbe 100644 --- a/tests/mir-opt/combine_clone_of_primitives.{impl#0}-clone.InstSimplify.panic-unwind.diff +++ b/tests/mir-opt/combine_clone_of_primitives.{impl#0}-clone.InstSimplify.panic-unwind.diff @@ -63,7 +63,7 @@ } bb4 (cleanup): { - drop(_2) -> [return: bb5, unwind terminate]; + drop(_2) -> [return: bb5, unwind terminate (panic in a destructor during cleanup)]; } bb5 (cleanup): { diff --git a/tests/mir-opt/derefer_inline_test.main.Derefer.panic-abort.diff b/tests/mir-opt/derefer_inline_test.main.Derefer.panic-abort.diff index 024d9bc7f5141..b59a377d27cad 100644 --- a/tests/mir-opt/derefer_inline_test.main.Derefer.panic-abort.diff +++ b/tests/mir-opt/derefer_inline_test.main.Derefer.panic-abort.diff @@ -28,7 +28,7 @@ } bb4 (cleanup): { - drop(_2) -> [return: bb5, unwind terminate]; + drop(_2) -> [return: bb5, unwind terminate (panic in a destructor during cleanup)]; } bb5 (cleanup): { diff --git a/tests/mir-opt/derefer_inline_test.main.Derefer.panic-unwind.diff b/tests/mir-opt/derefer_inline_test.main.Derefer.panic-unwind.diff index 2ada087b4bd6e..effecc03738d7 100644 --- a/tests/mir-opt/derefer_inline_test.main.Derefer.panic-unwind.diff +++ b/tests/mir-opt/derefer_inline_test.main.Derefer.panic-unwind.diff @@ -28,7 +28,7 @@ } bb4 (cleanup): { - drop(_2) -> [return: bb5, unwind terminate]; + drop(_2) -> [return: bb5, unwind terminate (panic in a destructor during cleanup)]; } bb5 (cleanup): { diff --git a/tests/mir-opt/generator_storage_dead_unwind.main-{closure#0}.StateTransform.before.panic-unwind.mir b/tests/mir-opt/generator_storage_dead_unwind.main-{closure#0}.StateTransform.before.panic-unwind.mir index 6a4c5436fce46..8ec9c46f95f00 100644 --- a/tests/mir-opt/generator_storage_dead_unwind.main-{closure#0}.StateTransform.before.panic-unwind.mir +++ b/tests/mir-opt/generator_storage_dead_unwind.main-{closure#0}.StateTransform.before.panic-unwind.mir @@ -104,7 +104,7 @@ yields () bb13 (cleanup): { StorageDead(_3); - drop(_1) -> [return: bb14, unwind terminate]; + drop(_1) -> [return: bb14, unwind terminate (panic in a destructor during cleanup)]; } bb14 (cleanup): { @@ -113,6 +113,6 @@ yields () bb15 (cleanup): { StorageDead(_3); - drop(_1) -> [return: bb14, unwind terminate]; + drop(_1) -> [return: bb14, unwind terminate (panic in a destructor during cleanup)]; } } diff --git a/tests/mir-opt/inline/asm_unwind.main.Inline.panic-abort.diff b/tests/mir-opt/inline/asm_unwind.main.Inline.panic-abort.diff index 503dc5beb1947..2371297aefb66 100644 --- a/tests/mir-opt/inline/asm_unwind.main.Inline.panic-abort.diff +++ b/tests/mir-opt/inline/asm_unwind.main.Inline.panic-abort.diff @@ -17,7 +17,7 @@ StorageLive(_1); - _1 = foo() -> [return: bb1, unwind unreachable]; + StorageLive(_2); -+ asm!("", options(MAY_UNWIND)) -> [return: bb2, unwind terminate]; ++ asm!("", options(MAY_UNWIND)) -> [return: bb2, unwind terminate (panic in a function that cannot unwind)]; } bb1: { diff --git a/tests/mir-opt/inline/asm_unwind.main.Inline.panic-unwind.diff b/tests/mir-opt/inline/asm_unwind.main.Inline.panic-unwind.diff index 684211b53b337..4c0be81ea2676 100644 --- a/tests/mir-opt/inline/asm_unwind.main.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline/asm_unwind.main.Inline.panic-unwind.diff @@ -32,7 +32,7 @@ + } + + bb3 (cleanup): { -+ drop(_2) -> [return: bb4, unwind terminate]; ++ drop(_2) -> [return: bb4, unwind terminate (panic in a destructor during cleanup)]; + } + + bb4 (cleanup): { diff --git a/tests/mir-opt/inline/cycle.f.Inline.panic-unwind.diff b/tests/mir-opt/inline/cycle.f.Inline.panic-unwind.diff index f3a6ee22c2080..6e95225a43d0d 100644 --- a/tests/mir-opt/inline/cycle.f.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline/cycle.f.Inline.panic-unwind.diff @@ -30,7 +30,7 @@ } bb3 (cleanup): { - drop(_1) -> [return: bb4, unwind terminate]; + drop(_1) -> [return: bb4, unwind terminate (panic in a destructor during cleanup)]; } bb4 (cleanup): { diff --git a/tests/mir-opt/inline/cycle.g.Inline.panic-unwind.diff b/tests/mir-opt/inline/cycle.g.Inline.panic-unwind.diff index ad801fd280ac7..cd3ea5ebd0e62 100644 --- a/tests/mir-opt/inline/cycle.g.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline/cycle.g.Inline.panic-unwind.diff @@ -36,7 +36,7 @@ + } + + bb3 (cleanup): { -+ drop(_2) -> [return: bb4, unwind terminate]; ++ drop(_2) -> [return: bb4, unwind terminate (panic in a destructor during cleanup)]; + } + + bb4 (cleanup): { diff --git a/tests/mir-opt/inline/cycle.main.Inline.panic-unwind.diff b/tests/mir-opt/inline/cycle.main.Inline.panic-unwind.diff index 99dc64115a984..66ce2f92186b1 100644 --- a/tests/mir-opt/inline/cycle.main.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline/cycle.main.Inline.panic-unwind.diff @@ -36,7 +36,7 @@ + } + + bb3 (cleanup): { -+ drop(_2) -> [return: bb4, unwind terminate]; ++ drop(_2) -> [return: bb4, unwind terminate (panic in a destructor during cleanup)]; + } + + bb4 (cleanup): { diff --git a/tests/mir-opt/inline/dont_ice_on_generic_rust_call.call.Inline.panic-unwind.diff b/tests/mir-opt/inline/dont_ice_on_generic_rust_call.call.Inline.panic-unwind.diff index ef85e075eeb37..daabb0ffc2179 100644 --- a/tests/mir-opt/inline/dont_ice_on_generic_rust_call.call.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline/dont_ice_on_generic_rust_call.call.Inline.panic-unwind.diff @@ -27,7 +27,7 @@ } bb3 (cleanup): { - drop(_1) -> [return: bb4, unwind terminate]; + drop(_1) -> [return: bb4, unwind terminate (panic in a destructor during cleanup)]; } bb4 (cleanup): { diff --git a/tests/mir-opt/inline/inline_box_fn.call.Inline.panic-unwind.diff b/tests/mir-opt/inline/inline_box_fn.call.Inline.panic-unwind.diff index 5df730a99302a..b3fee11e7dd36 100644 --- a/tests/mir-opt/inline/inline_box_fn.call.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline/inline_box_fn.call.Inline.panic-unwind.diff @@ -30,7 +30,7 @@ } bb3 (cleanup): { - drop(_1) -> [return: bb4, unwind terminate]; + drop(_1) -> [return: bb4, unwind terminate (panic in a destructor during cleanup)]; } bb4 (cleanup): { diff --git a/tests/mir-opt/inline/inline_diverging.h.Inline.panic-unwind.diff b/tests/mir-opt/inline/inline_diverging.h.Inline.panic-unwind.diff index 073ddeff7cab7..e3f5e9810c6ae 100644 --- a/tests/mir-opt/inline/inline_diverging.h.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline/inline_diverging.h.Inline.panic-unwind.diff @@ -54,11 +54,11 @@ + } + + bb4 (cleanup): { -+ drop(_4) -> [return: bb5, unwind terminate]; ++ drop(_4) -> [return: bb5, unwind terminate (panic in a destructor during cleanup)]; + } + + bb5 (cleanup): { -+ drop(_2) -> [return: bb6, unwind terminate]; ++ drop(_2) -> [return: bb6, unwind terminate (panic in a destructor during cleanup)]; + } + + bb6 (cleanup): { diff --git a/tests/mir-opt/inline/issue_78442.bar.Inline.panic-unwind.diff b/tests/mir-opt/inline/issue_78442.bar.Inline.panic-unwind.diff index b750330df9272..9042121ea9f5d 100644 --- a/tests/mir-opt/inline/issue_78442.bar.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline/issue_78442.bar.Inline.panic-unwind.diff @@ -37,7 +37,7 @@ } bb4 (cleanup): { - drop(_1) -> [return: bb5, unwind terminate]; + drop(_1) -> [return: bb5, unwind terminate (panic in a destructor during cleanup)]; } bb5 (cleanup): { diff --git a/tests/mir-opt/inline/issue_78442.bar.RevealAll.panic-unwind.diff b/tests/mir-opt/inline/issue_78442.bar.RevealAll.panic-unwind.diff index 7765e491d8971..2a55b018f7c03 100644 --- a/tests/mir-opt/inline/issue_78442.bar.RevealAll.panic-unwind.diff +++ b/tests/mir-opt/inline/issue_78442.bar.RevealAll.panic-unwind.diff @@ -40,7 +40,7 @@ } bb4 (cleanup): { - drop(_1) -> [return: bb5, unwind terminate]; + drop(_1) -> [return: bb5, unwind terminate (panic in a destructor during cleanup)]; } bb5 (cleanup): { diff --git a/tests/mir-opt/inline/unsized_argument.caller.Inline.diff b/tests/mir-opt/inline/unsized_argument.caller.Inline.diff index 6ee6a0ffe4cde..0cddc5a36b1be 100644 --- a/tests/mir-opt/inline/unsized_argument.caller.Inline.diff +++ b/tests/mir-opt/inline/unsized_argument.caller.Inline.diff @@ -40,7 +40,7 @@ bb4 (cleanup): { _8 = &mut _3; - _9 = as Drop>::drop(move _8) -> [return: bb1, unwind terminate]; + _9 = as Drop>::drop(move _8) -> [return: bb1, unwind terminate (panic in a destructor during cleanup)]; } } diff --git a/tests/mir-opt/issue_41110.main.ElaborateDrops.panic-abort.diff b/tests/mir-opt/issue_41110.main.ElaborateDrops.panic-abort.diff index 11501907b8812..4f7ca616792d4 100644 --- a/tests/mir-opt/issue_41110.main.ElaborateDrops.panic-abort.diff +++ b/tests/mir-opt/issue_41110.main.ElaborateDrops.panic-abort.diff @@ -40,17 +40,17 @@ } bb3 (cleanup): { -- drop(_3) -> [return: bb5, unwind terminate]; +- drop(_3) -> [return: bb5, unwind terminate (panic in a destructor during cleanup)]; + goto -> bb5; } bb4 (cleanup): { -- drop(_4) -> [return: bb5, unwind terminate]; +- drop(_4) -> [return: bb5, unwind terminate (panic in a destructor during cleanup)]; + goto -> bb5; } bb5 (cleanup): { -- drop(_2) -> [return: bb6, unwind terminate]; +- drop(_2) -> [return: bb6, unwind terminate (panic in a destructor during cleanup)]; + goto -> bb8; } @@ -59,7 +59,7 @@ + } + + bb7 (cleanup): { -+ drop(_2) -> [return: bb6, unwind terminate]; ++ drop(_2) -> [return: bb6, unwind terminate (panic in a destructor during cleanup)]; + } + + bb8 (cleanup): { diff --git a/tests/mir-opt/issue_41110.main.ElaborateDrops.panic-unwind.diff b/tests/mir-opt/issue_41110.main.ElaborateDrops.panic-unwind.diff index 11501907b8812..4f7ca616792d4 100644 --- a/tests/mir-opt/issue_41110.main.ElaborateDrops.panic-unwind.diff +++ b/tests/mir-opt/issue_41110.main.ElaborateDrops.panic-unwind.diff @@ -40,17 +40,17 @@ } bb3 (cleanup): { -- drop(_3) -> [return: bb5, unwind terminate]; +- drop(_3) -> [return: bb5, unwind terminate (panic in a destructor during cleanup)]; + goto -> bb5; } bb4 (cleanup): { -- drop(_4) -> [return: bb5, unwind terminate]; +- drop(_4) -> [return: bb5, unwind terminate (panic in a destructor during cleanup)]; + goto -> bb5; } bb5 (cleanup): { -- drop(_2) -> [return: bb6, unwind terminate]; +- drop(_2) -> [return: bb6, unwind terminate (panic in a destructor during cleanup)]; + goto -> bb8; } @@ -59,7 +59,7 @@ + } + + bb7 (cleanup): { -+ drop(_2) -> [return: bb6, unwind terminate]; ++ drop(_2) -> [return: bb6, unwind terminate (panic in a destructor during cleanup)]; + } + + bb8 (cleanup): { diff --git a/tests/mir-opt/issue_41110.test.ElaborateDrops.panic-abort.diff b/tests/mir-opt/issue_41110.test.ElaborateDrops.panic-abort.diff index 65f4806aaf778..0f38e3961a6fc 100644 --- a/tests/mir-opt/issue_41110.test.ElaborateDrops.panic-abort.diff +++ b/tests/mir-opt/issue_41110.test.ElaborateDrops.panic-abort.diff @@ -47,7 +47,7 @@ bb3 (cleanup): { _2 = move _5; -- drop(_5) -> [return: bb8, unwind terminate]; +- drop(_5) -> [return: bb8, unwind terminate (panic in a destructor during cleanup)]; + goto -> bb8; } @@ -70,17 +70,17 @@ } bb7 (cleanup): { -- drop(_4) -> [return: bb8, unwind terminate]; +- drop(_4) -> [return: bb8, unwind terminate (panic in a destructor during cleanup)]; + goto -> bb8; } bb8 (cleanup): { -- drop(_2) -> [return: bb9, unwind terminate]; +- drop(_2) -> [return: bb9, unwind terminate (panic in a destructor during cleanup)]; + goto -> bb9; } bb9 (cleanup): { -- drop(_1) -> [return: bb10, unwind terminate]; +- drop(_1) -> [return: bb10, unwind terminate (panic in a destructor during cleanup)]; + goto -> bb12; } @@ -89,7 +89,7 @@ + } + + bb11 (cleanup): { -+ drop(_1) -> [return: bb10, unwind terminate]; ++ drop(_1) -> [return: bb10, unwind terminate (panic in a destructor during cleanup)]; + } + + bb12 (cleanup): { diff --git a/tests/mir-opt/issue_41110.test.ElaborateDrops.panic-unwind.diff b/tests/mir-opt/issue_41110.test.ElaborateDrops.panic-unwind.diff index 4845fc732aabf..8da15ec9e23e3 100644 --- a/tests/mir-opt/issue_41110.test.ElaborateDrops.panic-unwind.diff +++ b/tests/mir-opt/issue_41110.test.ElaborateDrops.panic-unwind.diff @@ -47,7 +47,7 @@ bb3 (cleanup): { _2 = move _5; -- drop(_5) -> [return: bb8, unwind terminate]; +- drop(_5) -> [return: bb8, unwind terminate (panic in a destructor during cleanup)]; + goto -> bb8; } @@ -70,17 +70,17 @@ } bb7 (cleanup): { -- drop(_4) -> [return: bb8, unwind terminate]; +- drop(_4) -> [return: bb8, unwind terminate (panic in a destructor during cleanup)]; + goto -> bb8; } bb8 (cleanup): { -- drop(_2) -> [return: bb9, unwind terminate]; +- drop(_2) -> [return: bb9, unwind terminate (panic in a destructor during cleanup)]; + goto -> bb9; } bb9 (cleanup): { -- drop(_1) -> [return: bb10, unwind terminate]; +- drop(_1) -> [return: bb10, unwind terminate (panic in a destructor during cleanup)]; + goto -> bb12; } @@ -89,7 +89,7 @@ + } + + bb11 (cleanup): { -+ drop(_1) -> [return: bb10, unwind terminate]; ++ drop(_1) -> [return: bb10, unwind terminate (panic in a destructor during cleanup)]; + } + + bb12 (cleanup): { diff --git a/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-abort.diff b/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-abort.diff index aca7fe95c183b..562e684f29fdf 100644 --- a/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-abort.diff +++ b/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-abort.diff @@ -58,7 +58,7 @@ + _8 = const true; + _9 = const true; _1 = move _3; -- drop(_3) -> [return: bb11, unwind terminate]; +- drop(_3) -> [return: bb11, unwind terminate (panic in a destructor during cleanup)]; + goto -> bb11; } @@ -102,7 +102,7 @@ } bb11 (cleanup): { -- drop(_1) -> [return: bb12, unwind terminate]; +- drop(_1) -> [return: bb12, unwind terminate (panic in a destructor during cleanup)]; + goto -> bb12; } @@ -124,7 +124,7 @@ + } + + bb16 (cleanup): { -+ drop(_1) -> [return: bb12, unwind terminate]; ++ drop(_1) -> [return: bb12, unwind terminate (panic in a destructor during cleanup)]; + } + + bb17: { diff --git a/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-unwind.diff b/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-unwind.diff index 60ce9cd8ad9d9..c6cc80c09c08b 100644 --- a/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-unwind.diff +++ b/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-unwind.diff @@ -58,7 +58,7 @@ + _8 = const true; + _9 = const true; _1 = move _3; -- drop(_3) -> [return: bb11, unwind terminate]; +- drop(_3) -> [return: bb11, unwind terminate (panic in a destructor during cleanup)]; + goto -> bb11; } @@ -102,7 +102,7 @@ } bb11 (cleanup): { -- drop(_1) -> [return: bb12, unwind terminate]; +- drop(_1) -> [return: bb12, unwind terminate (panic in a destructor during cleanup)]; + goto -> bb12; } @@ -124,7 +124,7 @@ + } + + bb16 (cleanup): { -+ drop(_1) -> [return: bb12, unwind terminate]; ++ drop(_1) -> [return: bb12, unwind terminate (panic in a destructor during cleanup)]; + } + + bb17: { diff --git a/tests/mir-opt/issue_62289.test.ElaborateDrops.before.panic-abort.mir b/tests/mir-opt/issue_62289.test.ElaborateDrops.before.panic-abort.mir index ae0beffae1849..151571f57eb3d 100644 --- a/tests/mir-opt/issue_62289.test.ElaborateDrops.before.panic-abort.mir +++ b/tests/mir-opt/issue_62289.test.ElaborateDrops.before.panic-abort.mir @@ -100,11 +100,11 @@ fn test() -> Option> { } bb11 (cleanup): { - drop(_1) -> [return: bb13, unwind terminate]; + drop(_1) -> [return: bb13, unwind terminate (panic in a destructor during cleanup)]; } bb12 (cleanup): { - drop(_5) -> [return: bb13, unwind terminate]; + drop(_5) -> [return: bb13, unwind terminate (panic in a destructor during cleanup)]; } bb13 (cleanup): { diff --git a/tests/mir-opt/issue_62289.test.ElaborateDrops.before.panic-unwind.mir b/tests/mir-opt/issue_62289.test.ElaborateDrops.before.panic-unwind.mir index 7ecdc428e59e7..bda3080edb9d1 100644 --- a/tests/mir-opt/issue_62289.test.ElaborateDrops.before.panic-unwind.mir +++ b/tests/mir-opt/issue_62289.test.ElaborateDrops.before.panic-unwind.mir @@ -100,11 +100,11 @@ fn test() -> Option> { } bb11 (cleanup): { - drop(_1) -> [return: bb13, unwind terminate]; + drop(_1) -> [return: bb13, unwind terminate (panic in a destructor during cleanup)]; } bb12 (cleanup): { - drop(_5) -> [return: bb13, unwind terminate]; + drop(_5) -> [return: bb13, unwind terminate (panic in a destructor during cleanup)]; } bb13 (cleanup): { diff --git a/tests/mir-opt/issue_91633.bar.built.after.mir b/tests/mir-opt/issue_91633.bar.built.after.mir index 92f52e138a59f..6aa49aab20e35 100644 --- a/tests/mir-opt/issue_91633.bar.built.after.mir +++ b/tests/mir-opt/issue_91633.bar.built.after.mir @@ -28,7 +28,7 @@ fn bar(_1: Box<[T]>) -> () { } bb3 (cleanup): { - drop(_1) -> [return: bb4, unwind terminate]; + drop(_1) -> [return: bb4, unwind terminate (panic in a destructor during cleanup)]; } bb4 (cleanup): { diff --git a/tests/mir-opt/issue_91633.foo.built.after.mir b/tests/mir-opt/issue_91633.foo.built.after.mir index 4529c58a13733..2cf683217432b 100644 --- a/tests/mir-opt/issue_91633.foo.built.after.mir +++ b/tests/mir-opt/issue_91633.foo.built.after.mir @@ -45,7 +45,7 @@ fn foo(_1: Box<[T]>) -> T { } bb5 (cleanup): { - drop(_1) -> [return: bb6, unwind terminate]; + drop(_1) -> [return: bb6, unwind terminate (panic in a destructor during cleanup)]; } bb6 (cleanup): { diff --git a/tests/mir-opt/match_arm_scopes.complicated_match.panic-abort.SimplifyCfg-initial.after-ElaborateDrops.after.diff b/tests/mir-opt/match_arm_scopes.complicated_match.panic-abort.SimplifyCfg-initial.after-ElaborateDrops.after.diff index be09ed641b877..9452ba7e6bc9a 100644 --- a/tests/mir-opt/match_arm_scopes.complicated_match.panic-abort.SimplifyCfg-initial.after-ElaborateDrops.after.diff +++ b/tests/mir-opt/match_arm_scopes.complicated_match.panic-abort.SimplifyCfg-initial.after-ElaborateDrops.after.diff @@ -243,7 +243,7 @@ } - bb25 (cleanup): { -- drop(_2) -> [return: bb26, unwind terminate]; +- drop(_2) -> [return: bb26, unwind terminate (panic in a destructor during cleanup)]; + bb22 (cleanup): { + goto -> bb27; } diff --git a/tests/mir-opt/match_arm_scopes.complicated_match.panic-unwind.SimplifyCfg-initial.after-ElaborateDrops.after.diff b/tests/mir-opt/match_arm_scopes.complicated_match.panic-unwind.SimplifyCfg-initial.after-ElaborateDrops.after.diff index be09ed641b877..9452ba7e6bc9a 100644 --- a/tests/mir-opt/match_arm_scopes.complicated_match.panic-unwind.SimplifyCfg-initial.after-ElaborateDrops.after.diff +++ b/tests/mir-opt/match_arm_scopes.complicated_match.panic-unwind.SimplifyCfg-initial.after-ElaborateDrops.after.diff @@ -243,7 +243,7 @@ } - bb25 (cleanup): { -- drop(_2) -> [return: bb26, unwind terminate]; +- drop(_2) -> [return: bb26, unwind terminate (panic in a destructor during cleanup)]; + bb22 (cleanup): { + goto -> bb27; } diff --git a/tests/mir-opt/no_spurious_drop_after_call.main.ElaborateDrops.before.panic-abort.mir b/tests/mir-opt/no_spurious_drop_after_call.main.ElaborateDrops.before.panic-abort.mir index e22fc7d54bc47..51a009056d741 100644 --- a/tests/mir-opt/no_spurious_drop_after_call.main.ElaborateDrops.before.panic-abort.mir +++ b/tests/mir-opt/no_spurious_drop_after_call.main.ElaborateDrops.before.panic-abort.mir @@ -31,7 +31,7 @@ fn main() -> () { } bb3 (cleanup): { - drop(_2) -> [return: bb4, unwind terminate]; + drop(_2) -> [return: bb4, unwind terminate (panic in a destructor during cleanup)]; } bb4 (cleanup): { diff --git a/tests/mir-opt/no_spurious_drop_after_call.main.ElaborateDrops.before.panic-unwind.mir b/tests/mir-opt/no_spurious_drop_after_call.main.ElaborateDrops.before.panic-unwind.mir index 6fb107929e6bb..95820cfafbc12 100644 --- a/tests/mir-opt/no_spurious_drop_after_call.main.ElaborateDrops.before.panic-unwind.mir +++ b/tests/mir-opt/no_spurious_drop_after_call.main.ElaborateDrops.before.panic-unwind.mir @@ -31,7 +31,7 @@ fn main() -> () { } bb3 (cleanup): { - drop(_2) -> [return: bb4, unwind terminate]; + drop(_2) -> [return: bb4, unwind terminate (panic in a destructor during cleanup)]; } bb4 (cleanup): { diff --git a/tests/mir-opt/packed_struct_drop_aligned.main.SimplifyCfg-elaborate-drops.after.panic-unwind.mir b/tests/mir-opt/packed_struct_drop_aligned.main.SimplifyCfg-elaborate-drops.after.panic-unwind.mir index bc04790028d37..9a43756cbc06a 100644 --- a/tests/mir-opt/packed_struct_drop_aligned.main.SimplifyCfg-elaborate-drops.after.panic-unwind.mir +++ b/tests/mir-opt/packed_struct_drop_aligned.main.SimplifyCfg-elaborate-drops.after.panic-unwind.mir @@ -33,7 +33,7 @@ fn main() -> () { bb1 (cleanup): { (_1.0: Aligned) = move _4; - drop(_1) -> [return: bb3, unwind terminate]; + drop(_1) -> [return: bb3, unwind terminate (panic in a destructor during cleanup)]; } bb2: { diff --git a/tests/mir-opt/retag.main.SimplifyCfg-elaborate-drops.after.panic-unwind.mir b/tests/mir-opt/retag.main.SimplifyCfg-elaborate-drops.after.panic-unwind.mir index 508f964099a16..09ff59ffa2153 100644 --- a/tests/mir-opt/retag.main.SimplifyCfg-elaborate-drops.after.panic-unwind.mir +++ b/tests/mir-opt/retag.main.SimplifyCfg-elaborate-drops.after.panic-unwind.mir @@ -167,11 +167,11 @@ fn main() -> () { } bb7 (cleanup): { - drop(_21) -> [return: bb9, unwind terminate]; + drop(_21) -> [return: bb9, unwind terminate (panic in a destructor during cleanup)]; } bb8 (cleanup): { - drop(_5) -> [return: bb9, unwind terminate]; + drop(_5) -> [return: bb9, unwind terminate (panic in a destructor during cleanup)]; } bb9 (cleanup): { diff --git a/tests/mir-opt/slice_drop_shim.core.ptr-drop_in_place.[String].AddMovesForPackedDrops.before.mir b/tests/mir-opt/slice_drop_shim.core.ptr-drop_in_place.[String].AddMovesForPackedDrops.before.mir index 9bf69acd3563a..8d9f898557890 100644 --- a/tests/mir-opt/slice_drop_shim.core.ptr-drop_in_place.[String].AddMovesForPackedDrops.before.mir +++ b/tests/mir-opt/slice_drop_shim.core.ptr-drop_in_place.[String].AddMovesForPackedDrops.before.mir @@ -24,7 +24,7 @@ fn std::ptr::drop_in_place(_1: *mut [String]) -> () { bb3 (cleanup): { _4 = &raw mut (*_1)[_3]; _3 = Add(move _3, const 1_usize); - drop((*_4)) -> [return: bb4, unwind terminate]; + drop((*_4)) -> [return: bb4, unwind terminate (panic in a destructor during cleanup)]; } bb4 (cleanup): { diff --git a/tests/mir-opt/unusual_item_types.core.ptr-drop_in_place.Vec_i32_.AddMovesForPackedDrops.before.mir b/tests/mir-opt/unusual_item_types.core.ptr-drop_in_place.Vec_i32_.AddMovesForPackedDrops.before.mir index ee90a540720a0..3768d34dd8ec1 100644 --- a/tests/mir-opt/unusual_item_types.core.ptr-drop_in_place.Vec_i32_.AddMovesForPackedDrops.before.mir +++ b/tests/mir-opt/unusual_item_types.core.ptr-drop_in_place.Vec_i32_.AddMovesForPackedDrops.before.mir @@ -22,7 +22,7 @@ fn std::ptr::drop_in_place(_1: *mut Vec) -> () { } bb4 (cleanup): { - drop(((*_1).0: alloc::raw_vec::RawVec)) -> [return: bb2, unwind terminate]; + drop(((*_1).0: alloc::raw_vec::RawVec)) -> [return: bb2, unwind terminate (panic in a destructor during cleanup)]; } bb5: { From ddea3f981ea16ef4bc1dec043c071dd99a5e411d Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 21 Aug 2023 12:25:15 +0200 Subject: [PATCH 2/8] document more things as needing to stay in sync --- compiler/rustc_middle/src/mir/mod.rs | 19 ++++++++++++++++--- library/core/src/panicking.rs | 2 ++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 9ef3a1b30e498..6484c30167cb3 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -1275,9 +1275,11 @@ impl AssertKind { matches!(self, OverflowNeg(..) | Overflow(Add | Sub | Mul | Shl | Shr, ..)) } - /// Getting a description does not require `O` to be printable, and does not - /// require allocation. - /// The caller is expected to handle `BoundsCheck` and `MisalignedPointerDereference` separately. + /// Get the message that is printed at runtime when this assertion fails. + /// + /// The caller is expected to handle `BoundsCheck` and `MisalignedPointerDereference` by + /// invoking the appropriate lang item (panic_bounds_check/panic_misaligned_pointer_dereference) + /// instead of printing a static message. pub fn description(&self) -> &'static str { use AssertKind::*; match self { @@ -1303,6 +1305,11 @@ impl AssertKind { } /// Format the message arguments for the `assert(cond, msg..)` terminator in MIR printing. + /// + /// Needs to be kept in sync with the run-time behavior (which is defined by + /// `AssertKind::description` and the lang items mentioned in its docs). + /// Note that we deliberately show more details here than we do at runtime, such as the actual + /// numbers that overflowed -- it is much easier to do so here than at runtime. pub fn fmt_assert_args(&self, f: &mut W) -> fmt::Result where O: Debug, @@ -1358,6 +1365,12 @@ impl AssertKind { } } + /// Format the diagnostic message for use in a lint (e.g. when the assertion fails during const-eval). + /// + /// Needs to be kept in sync with the run-time behavior (which is defined by + /// `AssertKind::description` and the lang items mentioned in its docs). + /// Note that we deliberately show more details here than we do at runtime, such as the actual + /// numbers that overflowed -- it is much easier to do so here than at runtime. pub fn diagnostic_message(&self) -> DiagnosticMessage { use crate::fluent_generated::*; use AssertKind::*; diff --git a/library/core/src/panicking.rs b/library/core/src/panicking.rs index d5e4c113018c1..ab6aa0df42828 100644 --- a/library/core/src/panicking.rs +++ b/library/core/src/panicking.rs @@ -188,6 +188,7 @@ fn panic_misaligned_pointer_dereference(required: usize, found: usize) -> ! { #[lang = "panic_cannot_unwind"] // needed by codegen for panic in nounwind function #[rustc_nounwind] fn panic_cannot_unwind() -> ! { + // Keep the text in sync with `UnwindTerminateReason::as_str` in `rustc_middle`. panic_nounwind("panic in a function that cannot unwind") } @@ -203,6 +204,7 @@ fn panic_cannot_unwind() -> ! { #[lang = "panic_in_cleanup"] // needed by codegen for panic in nounwind function #[rustc_nounwind] fn panic_in_cleanup() -> ! { + // Keep the text in sync with `UnwindTerminateReason::as_str` in `rustc_middle`. panic_nounwind("panic in a destructor during cleanup") } From 114fde6ac74ffbaaca4d7241c3ee4e11303ae50d Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 22 Aug 2023 13:57:09 +0200 Subject: [PATCH 3/8] cache the terminate block with the last reason that we saw --- compiler/rustc_codegen_ssa/src/mir/block.rs | 8 +++----- compiler/rustc_codegen_ssa/src/mir/mod.rs | 7 ++++--- compiler/rustc_middle/src/mir/patch.rs | 22 +++++++++------------ 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index 0af587e8de834..6aef16643949e 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -1581,8 +1581,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } fn terminate_block(&mut self, reason: UnwindTerminateReason) -> Bx::BasicBlock { - if let Some(bb) = self.terminate_in_cleanup_block && reason == UnwindTerminateReason::InCleanup { - return bb; + if let Some((cached_bb, cached_reason)) = self.terminate_block && reason == cached_reason { + return cached_bb; } let funclet; @@ -1653,9 +1653,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { bx.unreachable(); - if reason == UnwindTerminateReason::InCleanup { - self.terminate_in_cleanup_block = Some(llbb); - } + self.terminate_block = Some((llbb, reason)); llbb } diff --git a/compiler/rustc_codegen_ssa/src/mir/mod.rs b/compiler/rustc_codegen_ssa/src/mir/mod.rs index 7f38c54c36f0a..37a209cec5ef6 100644 --- a/compiler/rustc_codegen_ssa/src/mir/mod.rs +++ b/compiler/rustc_codegen_ssa/src/mir/mod.rs @@ -5,6 +5,7 @@ use rustc_index::IndexVec; use rustc_middle::mir; use rustc_middle::mir::interpret::ErrorHandled; use rustc_middle::mir::traversal; +use rustc_middle::mir::UnwindTerminateReason; use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, TyAndLayout}; use rustc_middle::ty::{self, Instance, Ty, TyCtxt, TypeFoldable, TypeVisitableExt}; use rustc_target::abi::call::{FnAbi, PassMode}; @@ -83,8 +84,8 @@ pub struct FunctionCx<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> { /// Cached unreachable block unreachable_block: Option, - /// Cached terminate upon unwinding (reason: InCleanup) block - terminate_in_cleanup_block: Option, + /// Cached terminate upon unwinding block and its reason + terminate_block: Option<(Bx::BasicBlock, UnwindTerminateReason)>, /// The location where each MIR arg/var/tmp/ret is stored. This is /// usually an `PlaceRef` representing an alloca, but not always: @@ -199,7 +200,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( personality_slot: None, cached_llbbs, unreachable_block: None, - terminate_in_cleanup_block: None, + terminate_block: None, cleanup_kinds, landing_pads: IndexVec::from_elem(None, &mir.basic_blocks), funclets: IndexVec::from_fn_n(|_| None, mir.basic_blocks.len()), diff --git a/compiler/rustc_middle/src/mir/patch.rs b/compiler/rustc_middle/src/mir/patch.rs index 419543b898893..da486c3465a6c 100644 --- a/compiler/rustc_middle/src/mir/patch.rs +++ b/compiler/rustc_middle/src/mir/patch.rs @@ -14,8 +14,8 @@ pub struct MirPatch<'tcx> { resume_block: Option, // Only for unreachable in cleanup path. unreachable_cleanup_block: Option, - // Cached block for UnwindTerminate(InCleanup) - terminate_in_cleanup_block: Option, + // Cached block for UnwindTerminate (with reason) + terminate_block: Option<(BasicBlock, UnwindTerminateReason)>, body_span: Span, next_local: usize, } @@ -30,7 +30,7 @@ impl<'tcx> MirPatch<'tcx> { next_local: body.local_decls.len(), resume_block: None, unreachable_cleanup_block: None, - terminate_in_cleanup_block: None, + terminate_block: None, body_span: body.span, }; @@ -53,12 +53,10 @@ impl<'tcx> MirPatch<'tcx> { } // Check if we already have a terminate block - if matches!( - block.terminator().kind, - TerminatorKind::UnwindTerminate(UnwindTerminateReason::InCleanup) - ) && block.statements.is_empty() + if let TerminatorKind::UnwindTerminate(reason) = block.terminator().kind + && block.statements.is_empty() { - result.terminate_in_cleanup_block = Some(bb); + result.terminate_block = Some((bb, reason)); continue; } } @@ -101,8 +99,8 @@ impl<'tcx> MirPatch<'tcx> { } pub fn terminate_block(&mut self, reason: UnwindTerminateReason) -> BasicBlock { - if let Some(bb) = self.terminate_in_cleanup_block && reason == UnwindTerminateReason::InCleanup { - return bb; + if let Some((cached_bb, cached_reason)) = self.terminate_block && reason == cached_reason { + return cached_bb; } let bb = self.new_block(BasicBlockData { @@ -113,9 +111,7 @@ impl<'tcx> MirPatch<'tcx> { }), is_cleanup: true, }); - if reason == UnwindTerminateReason::InCleanup { - self.terminate_in_cleanup_block = Some(bb); - } + self.terminate_block = Some((bb, reason)); bb } From af29a26378cdd90d663c5a93d671e70184772266 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 22 Aug 2023 14:41:55 +0200 Subject: [PATCH 4/8] add tests for both kinds of unwind-terminate messages --- tests/ui/backtrace.rs | 13 ++++++++----- tests/ui/panics/panic-in-cleanup.rs | 19 +++++++++++++++++++ tests/ui/panics/panic-in-cleanup.run.stderr | 10 ++++++++++ tests/ui/panics/panic-in-ffi.rs | 15 +++++++++++++++ tests/ui/panics/panic-in-ffi.run.stderr | 7 +++++++ 5 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 tests/ui/panics/panic-in-cleanup.rs create mode 100644 tests/ui/panics/panic-in-cleanup.run.stderr create mode 100644 tests/ui/panics/panic-in-ffi.rs create mode 100644 tests/ui/panics/panic-in-ffi.run.stderr diff --git a/tests/ui/backtrace.rs b/tests/ui/backtrace.rs index 66b378f62d63c..95783945529a5 100644 --- a/tests/ui/backtrace.rs +++ b/tests/ui/backtrace.rs @@ -100,14 +100,17 @@ fn runtest(me: &str) { let s = str::from_utf8(&out.stderr).unwrap(); // loosened the following from double::h to double:: due to // spurious failures on mac, 32bit, optimized - assert!(s.contains("stack backtrace") && contains_verbose_expected(s, "double"), - "bad output3: {}", s); + assert!( + s.contains("stack backtrace") && + s.contains("panic in a destructor during cleanup") && + contains_verbose_expected(s, "double"), + "bad output3: {}", s + ); // Make sure a stack trace isn't printed too many times // - // Currently it is printed 3 times ("once", "twice" and "panic in a - // function that cannot unwind") but in the future the last one may be - // removed. + // Currently it is printed 3 times ("once", "twice" and "panic in a destructor during + // cleanup") but in the future the last one may be removed. let p = template(me).arg("double-fail") .env("RUST_BACKTRACE", "1").spawn().unwrap(); let out = p.wait_with_output().unwrap(); diff --git a/tests/ui/panics/panic-in-cleanup.rs b/tests/ui/panics/panic-in-cleanup.rs new file mode 100644 index 0000000000000..b4519da4e6a77 --- /dev/null +++ b/tests/ui/panics/panic-in-cleanup.rs @@ -0,0 +1,19 @@ +// run-fail +// check-run-results +// error-pattern: panic in a destructor during cleanup +// normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> "" +// normalize-stderr-test: "\n +at [^\n]+" -> "" +// ignore-emscripten no processes + +struct Bomb; + +impl Drop for Bomb { + fn drop(&mut self) { + panic!("BOOM"); + } +} + +fn main() { + let _b = Bomb; + panic!(); +} diff --git a/tests/ui/panics/panic-in-cleanup.run.stderr b/tests/ui/panics/panic-in-cleanup.run.stderr new file mode 100644 index 0000000000000..fa201b9667f25 --- /dev/null +++ b/tests/ui/panics/panic-in-cleanup.run.stderr @@ -0,0 +1,10 @@ +thread 'main' panicked at $DIR/panic-in-cleanup.rs:18:5: +explicit panic +note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace +thread 'main' panicked at $DIR/panic-in-cleanup.rs:12:9: +BOOM +stack backtrace: +thread 'main' panicked at library/core/src/panicking.rs:126:5: +panic in a destructor during cleanup +stack backtrace: +thread caused non-unwinding panic. aborting. diff --git a/tests/ui/panics/panic-in-ffi.rs b/tests/ui/panics/panic-in-ffi.rs new file mode 100644 index 0000000000000..bb30398531f0a --- /dev/null +++ b/tests/ui/panics/panic-in-ffi.rs @@ -0,0 +1,15 @@ +// run-fail +// check-run-results +// error-pattern: panic in a function that cannot unwind +// normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> "" +// normalize-stderr-test: "\n +at [^\n]+" -> "" +// ignore-emscripten no processes +#![feature(c_unwind)] + +extern "C" fn panic_in_ffi() { + panic!("Test"); +} + +fn main() { + panic_in_ffi(); +} diff --git a/tests/ui/panics/panic-in-ffi.run.stderr b/tests/ui/panics/panic-in-ffi.run.stderr new file mode 100644 index 0000000000000..a6de98c4913e3 --- /dev/null +++ b/tests/ui/panics/panic-in-ffi.run.stderr @@ -0,0 +1,7 @@ +thread 'main' panicked at $DIR/panic-in-ffi.rs:10:5: +Test +note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace +thread 'main' panicked at library/core/src/panicking.rs:126:5: +panic in a function that cannot unwind +stack backtrace: +thread caused non-unwinding panic. aborting. From 290ce462526872f4fee675a23011f6fa27960ff0 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 24 Aug 2023 13:31:43 +0200 Subject: [PATCH 5/8] bless more mir-opt tests by hand --- .../inline/inline_into_box_place.main.Inline.panic-unwind.diff | 2 +- .../pre-codegen/loops.filter_mapped.PreCodegen.after.mir | 2 +- tests/mir-opt/pre-codegen/loops.mapped.PreCodegen.after.mir | 2 +- tests/mir-opt/pre-codegen/loops.vec_move.PreCodegen.after.mir | 2 +- .../range_iter.forward_loop.PreCodegen.after.panic-unwind.mir | 2 +- .../range_iter.inclusive_loop.PreCodegen.after.panic-unwind.mir | 2 +- ...slice_iter.enumerated_loop.PreCodegen.after.panic-unwind.mir | 2 +- .../slice_iter.forward_loop.PreCodegen.after.panic-unwind.mir | 2 +- .../slice_iter.range_loop.PreCodegen.after.panic-unwind.mir | 2 +- .../slice_iter.reverse_loop.PreCodegen.after.panic-unwind.mir | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/mir-opt/inline/inline_into_box_place.main.Inline.panic-unwind.diff b/tests/mir-opt/inline/inline_into_box_place.main.Inline.panic-unwind.diff index 54c33aac9e80f..d017900fc4c5e 100644 --- a/tests/mir-opt/inline/inline_into_box_place.main.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline/inline_into_box_place.main.Inline.panic-unwind.diff @@ -155,7 +155,7 @@ - StorageDead(_1); - return; + bb3 (cleanup): { -+ drop(_2) -> [return: bb2, unwind terminate]; ++ drop(_2) -> [return: bb2, unwind terminate (panic in a destructor during cleanup)]; } - bb4 (cleanup): { diff --git a/tests/mir-opt/pre-codegen/loops.filter_mapped.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/loops.filter_mapped.PreCodegen.after.mir index 940b9ae11561f..d7059d21488a4 100644 --- a/tests/mir-opt/pre-codegen/loops.filter_mapped.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/loops.filter_mapped.PreCodegen.after.mir @@ -83,7 +83,7 @@ fn filter_mapped(_1: impl Iterator, _2: impl Fn(T) -> Option) -> () } bb9 (cleanup): { - drop(_5) -> [return: bb10, unwind terminate]; + drop(_5) -> [return: bb10, unwind terminate (panic in a destructor during cleanup)]; } bb10 (cleanup): { diff --git a/tests/mir-opt/pre-codegen/loops.mapped.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/loops.mapped.PreCodegen.after.mir index 2614160363e82..9a10f5cb575a7 100644 --- a/tests/mir-opt/pre-codegen/loops.mapped.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/loops.mapped.PreCodegen.after.mir @@ -75,7 +75,7 @@ fn mapped(_1: impl Iterator, _2: impl Fn(T) -> U) -> () { } bb9 (cleanup): { - drop(_5) -> [return: bb10, unwind terminate]; + drop(_5) -> [return: bb10, unwind terminate (panic in a destructor during cleanup)]; } bb10 (cleanup): { diff --git a/tests/mir-opt/pre-codegen/loops.vec_move.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/loops.vec_move.PreCodegen.after.mir index 8eff46fb9312a..431661af705be 100644 --- a/tests/mir-opt/pre-codegen/loops.vec_move.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/loops.vec_move.PreCodegen.after.mir @@ -67,7 +67,7 @@ fn vec_move(_1: Vec) -> () { } bb9 (cleanup): { - drop(_3) -> [return: bb10, unwind terminate]; + drop(_3) -> [return: bb10, unwind terminate (panic in a destructor during cleanup)]; } bb10 (cleanup): { diff --git a/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-unwind.mir index 4d7c017dad407..7cada9c148d4d 100644 --- a/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-unwind.mir @@ -127,7 +127,7 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () { } bb11 (cleanup): { - drop(_3) -> [return: bb12, unwind terminate]; + drop(_3) -> [return: bb12, unwind terminate (panic in a destructor during cleanup)]; } bb12 (cleanup): { diff --git a/tests/mir-opt/pre-codegen/range_iter.inclusive_loop.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/range_iter.inclusive_loop.PreCodegen.after.panic-unwind.mir index bbab4e47a3aba..ef1f934c52b2d 100644 --- a/tests/mir-opt/pre-codegen/range_iter.inclusive_loop.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/range_iter.inclusive_loop.PreCodegen.after.panic-unwind.mir @@ -82,7 +82,7 @@ fn inclusive_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () { } bb8 (cleanup): { - drop(_3) -> [return: bb9, unwind terminate]; + drop(_3) -> [return: bb9, unwind terminate (panic in a destructor during cleanup)]; } bb9 (cleanup): { diff --git a/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-unwind.mir index 836fa2677b18a..b9636712f826d 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-unwind.mir @@ -195,7 +195,7 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { } bb11 (cleanup): { - drop(_2) -> [return: bb12, unwind terminate]; + drop(_2) -> [return: bb12, unwind terminate (panic in a destructor during cleanup)]; } bb12 (cleanup): { diff --git a/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-unwind.mir index 65baaf64a9e7b..0f323a56e61de 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-unwind.mir @@ -182,7 +182,7 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { } bb11 (cleanup): { - drop(_2) -> [return: bb12, unwind terminate]; + drop(_2) -> [return: bb12, unwind terminate (panic in a destructor during cleanup)]; } bb12 (cleanup): { diff --git a/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-unwind.mir index f7b19e80e448a..96160b272b980 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-unwind.mir @@ -143,7 +143,7 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { } bb12 (cleanup): { - drop(_2) -> [return: bb13, unwind terminate]; + drop(_2) -> [return: bb13, unwind terminate (panic in a destructor during cleanup)]; } bb13 (cleanup): { diff --git a/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-unwind.mir index 43f8806e165a0..67d8442ab206f 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-unwind.mir @@ -196,7 +196,7 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { } bb11 (cleanup): { - drop(_2) -> [return: bb12, unwind terminate]; + drop(_2) -> [return: bb12, unwind terminate (panic in a destructor during cleanup)]; } bb12 (cleanup): { From 6f8ae03f9b485c41a3c4fbc1f0d854b30b6e283a Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 24 Aug 2023 14:26:26 +0200 Subject: [PATCH 6/8] make MIR less verbose --- compiler/rustc_middle/src/mir/terminator.rs | 17 +++++++++++++---- ...nic_abort.main.AbortUnwindingCalls.after.mir | 2 +- .../basic_assignment.main.ElaborateDrops.diff | 6 +++--- ...ssignment.main.SimplifyCfg-initial.after.mir | 6 +++--- ...r.main.ElaborateDrops.before.panic-abort.mir | 6 +++--- ....main.ElaborateDrops.before.panic-unwind.mir | 6 +++--- .../building/enum_cast.droppy.built.after.mir | 2 +- ...ove_out.move_out_by_subslice.built.after.mir | 6 +++--- ...y_move_out.move_out_from_end.built.after.mir | 6 +++--- ...impl#0}-clone.InstSimplify.panic-unwind.diff | 2 +- ...er_inline_test.main.Derefer.panic-abort.diff | 2 +- ...r_inline_test.main.Derefer.panic-unwind.diff | 2 +- ...re#0}.StateTransform.before.panic-unwind.mir | 4 ++-- .../asm_unwind.main.Inline.panic-abort.diff | 2 +- .../asm_unwind.main.Inline.panic-unwind.diff | 2 +- .../inline/cycle.f.Inline.panic-unwind.diff | 2 +- .../inline/cycle.g.Inline.panic-unwind.diff | 2 +- .../inline/cycle.main.Inline.panic-unwind.diff | 2 +- ...eric_rust_call.call.Inline.panic-unwind.diff | 2 +- .../inline_box_fn.call.Inline.panic-unwind.diff | 2 +- .../inline_diverging.h.Inline.panic-unwind.diff | 4 ++-- ...into_box_place.main.Inline.panic-unwind.diff | 2 +- .../issue_78442.bar.Inline.panic-unwind.diff | 2 +- .../issue_78442.bar.RevealAll.panic-unwind.diff | 2 +- .../inline/unsized_argument.caller.Inline.diff | 2 +- ...e_41110.main.ElaborateDrops.panic-abort.diff | 8 ++++---- ..._41110.main.ElaborateDrops.panic-unwind.diff | 8 ++++---- ...e_41110.test.ElaborateDrops.panic-abort.diff | 10 +++++----- ..._41110.test.ElaborateDrops.panic-unwind.diff | 10 +++++----- ...e_41888.main.ElaborateDrops.panic-abort.diff | 6 +++--- ..._41888.main.ElaborateDrops.panic-unwind.diff | 6 +++--- ...9.test.ElaborateDrops.before.panic-abort.mir | 4 ++-- ....test.ElaborateDrops.before.panic-unwind.mir | 4 ++-- tests/mir-opt/issue_91633.bar.built.after.mir | 2 +- tests/mir-opt/issue_91633.foo.built.after.mir | 2 +- ...yCfg-initial.after-ElaborateDrops.after.diff | 2 +- ...yCfg-initial.after-ElaborateDrops.after.diff | 2 +- ...l.main.ElaborateDrops.before.panic-abort.mir | 2 +- ....main.ElaborateDrops.before.panic-unwind.mir | 2 +- ...fyCfg-elaborate-drops.after.panic-unwind.mir | 2 +- .../loops.filter_mapped.PreCodegen.after.mir | 2 +- .../loops.mapped.PreCodegen.after.mir | 2 +- .../loops.vec_move.PreCodegen.after.mir | 2 +- ...rward_loop.PreCodegen.after.panic-unwind.mir | 2 +- ...usive_loop.PreCodegen.after.panic-unwind.mir | 2 +- ...rated_loop.PreCodegen.after.panic-unwind.mir | 2 +- ...rward_loop.PreCodegen.after.panic-unwind.mir | 2 +- ...range_loop.PreCodegen.after.panic-unwind.mir | 2 +- ...verse_loop.PreCodegen.after.panic-unwind.mir | 2 +- ...fyCfg-elaborate-drops.after.panic-unwind.mir | 4 ++-- ...e.[String].AddMovesForPackedDrops.before.mir | 2 +- ...e.Vec_i32_.AddMovesForPackedDrops.before.mir | 2 +- 52 files changed, 99 insertions(+), 90 deletions(-) diff --git a/compiler/rustc_middle/src/mir/terminator.rs b/compiler/rustc_middle/src/mir/terminator.rs index c4d7f122ea99b..7eddf13b3fb50 100644 --- a/compiler/rustc_middle/src/mir/terminator.rs +++ b/compiler/rustc_middle/src/mir/terminator.rs @@ -119,6 +119,14 @@ impl UnwindTerminateReason { } } + /// A short representation of this used for MIR printing. + pub fn as_short_str(self) -> &'static str { + match self { + UnwindTerminateReason::Abi => "abi", + UnwindTerminateReason::InCleanup => "cleanup", + } + } + pub fn lang_item(self) -> LangItem { match self { UnwindTerminateReason::Abi => LangItem::PanicCannotUnwind, @@ -301,13 +309,14 @@ impl<'tcx> Debug for TerminatorKind<'tcx> { // `Cleanup` is already included in successors let show_unwind = !matches!(self.unwind(), None | Some(UnwindAction::Cleanup(_))); let fmt_unwind = |fmt: &mut Formatter<'_>| -> fmt::Result { + write!(fmt, "unwind ")?; match self.unwind() { // Not needed or included in successors None | Some(UnwindAction::Cleanup(_)) => unreachable!(), - Some(UnwindAction::Continue) => write!(fmt, "unwind continue"), - Some(UnwindAction::Unreachable) => write!(fmt, "unwind unreachable"), + Some(UnwindAction::Continue) => write!(fmt, "continue"), + Some(UnwindAction::Unreachable) => write!(fmt, "unreachable"), Some(UnwindAction::Terminate(reason)) => { - write!(fmt, "unwind terminate ({})", reason.as_str()) + write!(fmt, "terminate({})", reason.as_short_str()) } } }; @@ -350,7 +359,7 @@ impl<'tcx> TerminatorKind<'tcx> { GeneratorDrop => write!(fmt, "generator_drop"), UnwindResume => write!(fmt, "resume"), UnwindTerminate(reason) => { - write!(fmt, "abort(\"{}\")", reason.as_str()) + write!(fmt, "abort({})", reason.as_short_str()) } Yield { value, resume_arg, .. } => write!(fmt, "{resume_arg:?} = yield({value:?})"), Unreachable => write!(fmt, "unreachable"), diff --git a/tests/mir-opt/asm_unwind_panic_abort.main.AbortUnwindingCalls.after.mir b/tests/mir-opt/asm_unwind_panic_abort.main.AbortUnwindingCalls.after.mir index 8b9c853eb8534..6c3128f8c36f6 100644 --- a/tests/mir-opt/asm_unwind_panic_abort.main.AbortUnwindingCalls.after.mir +++ b/tests/mir-opt/asm_unwind_panic_abort.main.AbortUnwindingCalls.after.mir @@ -9,7 +9,7 @@ fn main() -> () { bb0: { StorageLive(_1); _1 = const (); - asm!("", options(MAY_UNWIND)) -> [return: bb1, unwind terminate (panic in a function that cannot unwind)]; + asm!("", options(MAY_UNWIND)) -> [return: bb1, unwind terminate(abi)]; } bb1: { diff --git a/tests/mir-opt/basic_assignment.main.ElaborateDrops.diff b/tests/mir-opt/basic_assignment.main.ElaborateDrops.diff index 2b6e0fe489a6f..f187f95972795 100644 --- a/tests/mir-opt/basic_assignment.main.ElaborateDrops.diff +++ b/tests/mir-opt/basic_assignment.main.ElaborateDrops.diff @@ -47,7 +47,7 @@ bb2 (cleanup): { _5 = move _6; -- drop(_6) -> [return: bb6, unwind terminate (panic in a destructor during cleanup)]; +- drop(_6) -> [return: bb6, unwind terminate(cleanup)]; + goto -> bb6; } @@ -71,12 +71,12 @@ } bb6 (cleanup): { -- drop(_5) -> [return: bb7, unwind terminate (panic in a destructor during cleanup)]; +- drop(_5) -> [return: bb7, unwind terminate(cleanup)]; + goto -> bb7; } bb7 (cleanup): { -- drop(_4) -> [return: bb8, unwind terminate (panic in a destructor during cleanup)]; +- drop(_4) -> [return: bb8, unwind terminate(cleanup)]; + goto -> bb8; } diff --git a/tests/mir-opt/basic_assignment.main.SimplifyCfg-initial.after.mir b/tests/mir-opt/basic_assignment.main.SimplifyCfg-initial.after.mir index fac407ae1ea6b..75070ffda11fb 100644 --- a/tests/mir-opt/basic_assignment.main.SimplifyCfg-initial.after.mir +++ b/tests/mir-opt/basic_assignment.main.SimplifyCfg-initial.after.mir @@ -51,7 +51,7 @@ fn main() -> () { bb2 (cleanup): { _5 = move _6; - drop(_6) -> [return: bb6, unwind terminate (panic in a destructor during cleanup)]; + drop(_6) -> [return: bb6, unwind terminate(cleanup)]; } bb3: { @@ -73,11 +73,11 @@ fn main() -> () { } bb6 (cleanup): { - drop(_5) -> [return: bb7, unwind terminate (panic in a destructor during cleanup)]; + drop(_5) -> [return: bb7, unwind terminate(cleanup)]; } bb7 (cleanup): { - drop(_4) -> [return: bb8, unwind terminate (panic in a destructor during cleanup)]; + drop(_4) -> [return: bb8, unwind terminate(cleanup)]; } bb8 (cleanup): { diff --git a/tests/mir-opt/box_expr.main.ElaborateDrops.before.panic-abort.mir b/tests/mir-opt/box_expr.main.ElaborateDrops.before.panic-abort.mir index f7cfcf27fe5fc..1c7ef7f83456c 100644 --- a/tests/mir-opt/box_expr.main.ElaborateDrops.before.panic-abort.mir +++ b/tests/mir-opt/box_expr.main.ElaborateDrops.before.panic-abort.mir @@ -54,15 +54,15 @@ fn main() -> () { } bb6 (cleanup): { - drop(_7) -> [return: bb7, unwind terminate (panic in a destructor during cleanup)]; + drop(_7) -> [return: bb7, unwind terminate(cleanup)]; } bb7 (cleanup): { - drop(_1) -> [return: bb9, unwind terminate (panic in a destructor during cleanup)]; + drop(_1) -> [return: bb9, unwind terminate(cleanup)]; } bb8 (cleanup): { - drop(_5) -> [return: bb9, unwind terminate (panic in a destructor during cleanup)]; + drop(_5) -> [return: bb9, unwind terminate(cleanup)]; } bb9 (cleanup): { diff --git a/tests/mir-opt/box_expr.main.ElaborateDrops.before.panic-unwind.mir b/tests/mir-opt/box_expr.main.ElaborateDrops.before.panic-unwind.mir index 4cfdc8701c6b9..4ad1c2de12987 100644 --- a/tests/mir-opt/box_expr.main.ElaborateDrops.before.panic-unwind.mir +++ b/tests/mir-opt/box_expr.main.ElaborateDrops.before.panic-unwind.mir @@ -54,15 +54,15 @@ fn main() -> () { } bb6 (cleanup): { - drop(_7) -> [return: bb7, unwind terminate (panic in a destructor during cleanup)]; + drop(_7) -> [return: bb7, unwind terminate(cleanup)]; } bb7 (cleanup): { - drop(_1) -> [return: bb9, unwind terminate (panic in a destructor during cleanup)]; + drop(_1) -> [return: bb9, unwind terminate(cleanup)]; } bb8 (cleanup): { - drop(_5) -> [return: bb9, unwind terminate (panic in a destructor during cleanup)]; + drop(_5) -> [return: bb9, unwind terminate(cleanup)]; } bb9 (cleanup): { diff --git a/tests/mir-opt/building/enum_cast.droppy.built.after.mir b/tests/mir-opt/building/enum_cast.droppy.built.after.mir index d1f8b8daf74d7..ea0edb610f5cc 100644 --- a/tests/mir-opt/building/enum_cast.droppy.built.after.mir +++ b/tests/mir-opt/building/enum_cast.droppy.built.after.mir @@ -62,7 +62,7 @@ fn droppy() -> () { } bb4 (cleanup): { - drop(_2) -> [return: bb5, unwind terminate (panic in a destructor during cleanup)]; + drop(_2) -> [return: bb5, unwind terminate(cleanup)]; } bb5 (cleanup): { diff --git a/tests/mir-opt/building/uniform_array_move_out.move_out_by_subslice.built.after.mir b/tests/mir-opt/building/uniform_array_move_out.move_out_by_subslice.built.after.mir index f7fc1eb7ce30c..82424de03926d 100644 --- a/tests/mir-opt/building/uniform_array_move_out.move_out_by_subslice.built.after.mir +++ b/tests/mir-opt/building/uniform_array_move_out.move_out_by_subslice.built.after.mir @@ -89,15 +89,15 @@ fn move_out_by_subslice() -> () { } bb9 (cleanup): { - drop(_1) -> [return: bb12, unwind terminate (panic in a destructor during cleanup)]; + drop(_1) -> [return: bb12, unwind terminate(cleanup)]; } bb10 (cleanup): { - drop(_7) -> [return: bb11, unwind terminate (panic in a destructor during cleanup)]; + drop(_7) -> [return: bb11, unwind terminate(cleanup)]; } bb11 (cleanup): { - drop(_2) -> [return: bb12, unwind terminate (panic in a destructor during cleanup)]; + drop(_2) -> [return: bb12, unwind terminate(cleanup)]; } bb12 (cleanup): { diff --git a/tests/mir-opt/building/uniform_array_move_out.move_out_from_end.built.after.mir b/tests/mir-opt/building/uniform_array_move_out.move_out_from_end.built.after.mir index 95c061dc9fa92..0872d1b6ac0c2 100644 --- a/tests/mir-opt/building/uniform_array_move_out.move_out_from_end.built.after.mir +++ b/tests/mir-opt/building/uniform_array_move_out.move_out_from_end.built.after.mir @@ -89,15 +89,15 @@ fn move_out_from_end() -> () { } bb9 (cleanup): { - drop(_1) -> [return: bb12, unwind terminate (panic in a destructor during cleanup)]; + drop(_1) -> [return: bb12, unwind terminate(cleanup)]; } bb10 (cleanup): { - drop(_7) -> [return: bb11, unwind terminate (panic in a destructor during cleanup)]; + drop(_7) -> [return: bb11, unwind terminate(cleanup)]; } bb11 (cleanup): { - drop(_2) -> [return: bb12, unwind terminate (panic in a destructor during cleanup)]; + drop(_2) -> [return: bb12, unwind terminate(cleanup)]; } bb12 (cleanup): { diff --git a/tests/mir-opt/combine_clone_of_primitives.{impl#0}-clone.InstSimplify.panic-unwind.diff b/tests/mir-opt/combine_clone_of_primitives.{impl#0}-clone.InstSimplify.panic-unwind.diff index 20f627a567dbe..f2b87221f2b98 100644 --- a/tests/mir-opt/combine_clone_of_primitives.{impl#0}-clone.InstSimplify.panic-unwind.diff +++ b/tests/mir-opt/combine_clone_of_primitives.{impl#0}-clone.InstSimplify.panic-unwind.diff @@ -63,7 +63,7 @@ } bb4 (cleanup): { - drop(_2) -> [return: bb5, unwind terminate (panic in a destructor during cleanup)]; + drop(_2) -> [return: bb5, unwind terminate(cleanup)]; } bb5 (cleanup): { diff --git a/tests/mir-opt/derefer_inline_test.main.Derefer.panic-abort.diff b/tests/mir-opt/derefer_inline_test.main.Derefer.panic-abort.diff index b59a377d27cad..8ac6acd0e4a8b 100644 --- a/tests/mir-opt/derefer_inline_test.main.Derefer.panic-abort.diff +++ b/tests/mir-opt/derefer_inline_test.main.Derefer.panic-abort.diff @@ -28,7 +28,7 @@ } bb4 (cleanup): { - drop(_2) -> [return: bb5, unwind terminate (panic in a destructor during cleanup)]; + drop(_2) -> [return: bb5, unwind terminate(cleanup)]; } bb5 (cleanup): { diff --git a/tests/mir-opt/derefer_inline_test.main.Derefer.panic-unwind.diff b/tests/mir-opt/derefer_inline_test.main.Derefer.panic-unwind.diff index effecc03738d7..aa9fcb505e640 100644 --- a/tests/mir-opt/derefer_inline_test.main.Derefer.panic-unwind.diff +++ b/tests/mir-opt/derefer_inline_test.main.Derefer.panic-unwind.diff @@ -28,7 +28,7 @@ } bb4 (cleanup): { - drop(_2) -> [return: bb5, unwind terminate (panic in a destructor during cleanup)]; + drop(_2) -> [return: bb5, unwind terminate(cleanup)]; } bb5 (cleanup): { diff --git a/tests/mir-opt/generator_storage_dead_unwind.main-{closure#0}.StateTransform.before.panic-unwind.mir b/tests/mir-opt/generator_storage_dead_unwind.main-{closure#0}.StateTransform.before.panic-unwind.mir index 8ec9c46f95f00..6fcceb6c66bff 100644 --- a/tests/mir-opt/generator_storage_dead_unwind.main-{closure#0}.StateTransform.before.panic-unwind.mir +++ b/tests/mir-opt/generator_storage_dead_unwind.main-{closure#0}.StateTransform.before.panic-unwind.mir @@ -104,7 +104,7 @@ yields () bb13 (cleanup): { StorageDead(_3); - drop(_1) -> [return: bb14, unwind terminate (panic in a destructor during cleanup)]; + drop(_1) -> [return: bb14, unwind terminate(cleanup)]; } bb14 (cleanup): { @@ -113,6 +113,6 @@ yields () bb15 (cleanup): { StorageDead(_3); - drop(_1) -> [return: bb14, unwind terminate (panic in a destructor during cleanup)]; + drop(_1) -> [return: bb14, unwind terminate(cleanup)]; } } diff --git a/tests/mir-opt/inline/asm_unwind.main.Inline.panic-abort.diff b/tests/mir-opt/inline/asm_unwind.main.Inline.panic-abort.diff index 2371297aefb66..aa9429c46d84f 100644 --- a/tests/mir-opt/inline/asm_unwind.main.Inline.panic-abort.diff +++ b/tests/mir-opt/inline/asm_unwind.main.Inline.panic-abort.diff @@ -17,7 +17,7 @@ StorageLive(_1); - _1 = foo() -> [return: bb1, unwind unreachable]; + StorageLive(_2); -+ asm!("", options(MAY_UNWIND)) -> [return: bb2, unwind terminate (panic in a function that cannot unwind)]; ++ asm!("", options(MAY_UNWIND)) -> [return: bb2, unwind terminate(abi)]; } bb1: { diff --git a/tests/mir-opt/inline/asm_unwind.main.Inline.panic-unwind.diff b/tests/mir-opt/inline/asm_unwind.main.Inline.panic-unwind.diff index 4c0be81ea2676..ea9c360aa7b34 100644 --- a/tests/mir-opt/inline/asm_unwind.main.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline/asm_unwind.main.Inline.panic-unwind.diff @@ -32,7 +32,7 @@ + } + + bb3 (cleanup): { -+ drop(_2) -> [return: bb4, unwind terminate (panic in a destructor during cleanup)]; ++ drop(_2) -> [return: bb4, unwind terminate(cleanup)]; + } + + bb4 (cleanup): { diff --git a/tests/mir-opt/inline/cycle.f.Inline.panic-unwind.diff b/tests/mir-opt/inline/cycle.f.Inline.panic-unwind.diff index 6e95225a43d0d..b7fea4f2e147e 100644 --- a/tests/mir-opt/inline/cycle.f.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline/cycle.f.Inline.panic-unwind.diff @@ -30,7 +30,7 @@ } bb3 (cleanup): { - drop(_1) -> [return: bb4, unwind terminate (panic in a destructor during cleanup)]; + drop(_1) -> [return: bb4, unwind terminate(cleanup)]; } bb4 (cleanup): { diff --git a/tests/mir-opt/inline/cycle.g.Inline.panic-unwind.diff b/tests/mir-opt/inline/cycle.g.Inline.panic-unwind.diff index cd3ea5ebd0e62..1fd1014ba1d53 100644 --- a/tests/mir-opt/inline/cycle.g.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline/cycle.g.Inline.panic-unwind.diff @@ -36,7 +36,7 @@ + } + + bb3 (cleanup): { -+ drop(_2) -> [return: bb4, unwind terminate (panic in a destructor during cleanup)]; ++ drop(_2) -> [return: bb4, unwind terminate(cleanup)]; + } + + bb4 (cleanup): { diff --git a/tests/mir-opt/inline/cycle.main.Inline.panic-unwind.diff b/tests/mir-opt/inline/cycle.main.Inline.panic-unwind.diff index 66ce2f92186b1..e8299db47db72 100644 --- a/tests/mir-opt/inline/cycle.main.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline/cycle.main.Inline.panic-unwind.diff @@ -36,7 +36,7 @@ + } + + bb3 (cleanup): { -+ drop(_2) -> [return: bb4, unwind terminate (panic in a destructor during cleanup)]; ++ drop(_2) -> [return: bb4, unwind terminate(cleanup)]; + } + + bb4 (cleanup): { diff --git a/tests/mir-opt/inline/dont_ice_on_generic_rust_call.call.Inline.panic-unwind.diff b/tests/mir-opt/inline/dont_ice_on_generic_rust_call.call.Inline.panic-unwind.diff index daabb0ffc2179..b82961c2815d6 100644 --- a/tests/mir-opt/inline/dont_ice_on_generic_rust_call.call.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline/dont_ice_on_generic_rust_call.call.Inline.panic-unwind.diff @@ -27,7 +27,7 @@ } bb3 (cleanup): { - drop(_1) -> [return: bb4, unwind terminate (panic in a destructor during cleanup)]; + drop(_1) -> [return: bb4, unwind terminate(cleanup)]; } bb4 (cleanup): { diff --git a/tests/mir-opt/inline/inline_box_fn.call.Inline.panic-unwind.diff b/tests/mir-opt/inline/inline_box_fn.call.Inline.panic-unwind.diff index b3fee11e7dd36..47fd0ed079995 100644 --- a/tests/mir-opt/inline/inline_box_fn.call.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline/inline_box_fn.call.Inline.panic-unwind.diff @@ -30,7 +30,7 @@ } bb3 (cleanup): { - drop(_1) -> [return: bb4, unwind terminate (panic in a destructor during cleanup)]; + drop(_1) -> [return: bb4, unwind terminate(cleanup)]; } bb4 (cleanup): { diff --git a/tests/mir-opt/inline/inline_diverging.h.Inline.panic-unwind.diff b/tests/mir-opt/inline/inline_diverging.h.Inline.panic-unwind.diff index e3f5e9810c6ae..9f8c5806c90f8 100644 --- a/tests/mir-opt/inline/inline_diverging.h.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline/inline_diverging.h.Inline.panic-unwind.diff @@ -54,11 +54,11 @@ + } + + bb4 (cleanup): { -+ drop(_4) -> [return: bb5, unwind terminate (panic in a destructor during cleanup)]; ++ drop(_4) -> [return: bb5, unwind terminate(cleanup)]; + } + + bb5 (cleanup): { -+ drop(_2) -> [return: bb6, unwind terminate (panic in a destructor during cleanup)]; ++ drop(_2) -> [return: bb6, unwind terminate(cleanup)]; + } + + bb6 (cleanup): { diff --git a/tests/mir-opt/inline/inline_into_box_place.main.Inline.panic-unwind.diff b/tests/mir-opt/inline/inline_into_box_place.main.Inline.panic-unwind.diff index d017900fc4c5e..675292f06d669 100644 --- a/tests/mir-opt/inline/inline_into_box_place.main.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline/inline_into_box_place.main.Inline.panic-unwind.diff @@ -155,7 +155,7 @@ - StorageDead(_1); - return; + bb3 (cleanup): { -+ drop(_2) -> [return: bb2, unwind terminate (panic in a destructor during cleanup)]; ++ drop(_2) -> [return: bb2, unwind terminate(cleanup)]; } - bb4 (cleanup): { diff --git a/tests/mir-opt/inline/issue_78442.bar.Inline.panic-unwind.diff b/tests/mir-opt/inline/issue_78442.bar.Inline.panic-unwind.diff index 9042121ea9f5d..5a946712ea43b 100644 --- a/tests/mir-opt/inline/issue_78442.bar.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline/issue_78442.bar.Inline.panic-unwind.diff @@ -37,7 +37,7 @@ } bb4 (cleanup): { - drop(_1) -> [return: bb5, unwind terminate (panic in a destructor during cleanup)]; + drop(_1) -> [return: bb5, unwind terminate(cleanup)]; } bb5 (cleanup): { diff --git a/tests/mir-opt/inline/issue_78442.bar.RevealAll.panic-unwind.diff b/tests/mir-opt/inline/issue_78442.bar.RevealAll.panic-unwind.diff index 2a55b018f7c03..cbfb39115b370 100644 --- a/tests/mir-opt/inline/issue_78442.bar.RevealAll.panic-unwind.diff +++ b/tests/mir-opt/inline/issue_78442.bar.RevealAll.panic-unwind.diff @@ -40,7 +40,7 @@ } bb4 (cleanup): { - drop(_1) -> [return: bb5, unwind terminate (panic in a destructor during cleanup)]; + drop(_1) -> [return: bb5, unwind terminate(cleanup)]; } bb5 (cleanup): { diff --git a/tests/mir-opt/inline/unsized_argument.caller.Inline.diff b/tests/mir-opt/inline/unsized_argument.caller.Inline.diff index 0cddc5a36b1be..ab81f7071486a 100644 --- a/tests/mir-opt/inline/unsized_argument.caller.Inline.diff +++ b/tests/mir-opt/inline/unsized_argument.caller.Inline.diff @@ -40,7 +40,7 @@ bb4 (cleanup): { _8 = &mut _3; - _9 = as Drop>::drop(move _8) -> [return: bb1, unwind terminate (panic in a destructor during cleanup)]; + _9 = as Drop>::drop(move _8) -> [return: bb1, unwind terminate(cleanup)]; } } diff --git a/tests/mir-opt/issue_41110.main.ElaborateDrops.panic-abort.diff b/tests/mir-opt/issue_41110.main.ElaborateDrops.panic-abort.diff index 4f7ca616792d4..4469270a9b232 100644 --- a/tests/mir-opt/issue_41110.main.ElaborateDrops.panic-abort.diff +++ b/tests/mir-opt/issue_41110.main.ElaborateDrops.panic-abort.diff @@ -40,17 +40,17 @@ } bb3 (cleanup): { -- drop(_3) -> [return: bb5, unwind terminate (panic in a destructor during cleanup)]; +- drop(_3) -> [return: bb5, unwind terminate(cleanup)]; + goto -> bb5; } bb4 (cleanup): { -- drop(_4) -> [return: bb5, unwind terminate (panic in a destructor during cleanup)]; +- drop(_4) -> [return: bb5, unwind terminate(cleanup)]; + goto -> bb5; } bb5 (cleanup): { -- drop(_2) -> [return: bb6, unwind terminate (panic in a destructor during cleanup)]; +- drop(_2) -> [return: bb6, unwind terminate(cleanup)]; + goto -> bb8; } @@ -59,7 +59,7 @@ + } + + bb7 (cleanup): { -+ drop(_2) -> [return: bb6, unwind terminate (panic in a destructor during cleanup)]; ++ drop(_2) -> [return: bb6, unwind terminate(cleanup)]; + } + + bb8 (cleanup): { diff --git a/tests/mir-opt/issue_41110.main.ElaborateDrops.panic-unwind.diff b/tests/mir-opt/issue_41110.main.ElaborateDrops.panic-unwind.diff index 4f7ca616792d4..4469270a9b232 100644 --- a/tests/mir-opt/issue_41110.main.ElaborateDrops.panic-unwind.diff +++ b/tests/mir-opt/issue_41110.main.ElaborateDrops.panic-unwind.diff @@ -40,17 +40,17 @@ } bb3 (cleanup): { -- drop(_3) -> [return: bb5, unwind terminate (panic in a destructor during cleanup)]; +- drop(_3) -> [return: bb5, unwind terminate(cleanup)]; + goto -> bb5; } bb4 (cleanup): { -- drop(_4) -> [return: bb5, unwind terminate (panic in a destructor during cleanup)]; +- drop(_4) -> [return: bb5, unwind terminate(cleanup)]; + goto -> bb5; } bb5 (cleanup): { -- drop(_2) -> [return: bb6, unwind terminate (panic in a destructor during cleanup)]; +- drop(_2) -> [return: bb6, unwind terminate(cleanup)]; + goto -> bb8; } @@ -59,7 +59,7 @@ + } + + bb7 (cleanup): { -+ drop(_2) -> [return: bb6, unwind terminate (panic in a destructor during cleanup)]; ++ drop(_2) -> [return: bb6, unwind terminate(cleanup)]; + } + + bb8 (cleanup): { diff --git a/tests/mir-opt/issue_41110.test.ElaborateDrops.panic-abort.diff b/tests/mir-opt/issue_41110.test.ElaborateDrops.panic-abort.diff index 0f38e3961a6fc..78184f6aeeb1c 100644 --- a/tests/mir-opt/issue_41110.test.ElaborateDrops.panic-abort.diff +++ b/tests/mir-opt/issue_41110.test.ElaborateDrops.panic-abort.diff @@ -47,7 +47,7 @@ bb3 (cleanup): { _2 = move _5; -- drop(_5) -> [return: bb8, unwind terminate (panic in a destructor during cleanup)]; +- drop(_5) -> [return: bb8, unwind terminate(cleanup)]; + goto -> bb8; } @@ -70,17 +70,17 @@ } bb7 (cleanup): { -- drop(_4) -> [return: bb8, unwind terminate (panic in a destructor during cleanup)]; +- drop(_4) -> [return: bb8, unwind terminate(cleanup)]; + goto -> bb8; } bb8 (cleanup): { -- drop(_2) -> [return: bb9, unwind terminate (panic in a destructor during cleanup)]; +- drop(_2) -> [return: bb9, unwind terminate(cleanup)]; + goto -> bb9; } bb9 (cleanup): { -- drop(_1) -> [return: bb10, unwind terminate (panic in a destructor during cleanup)]; +- drop(_1) -> [return: bb10, unwind terminate(cleanup)]; + goto -> bb12; } @@ -89,7 +89,7 @@ + } + + bb11 (cleanup): { -+ drop(_1) -> [return: bb10, unwind terminate (panic in a destructor during cleanup)]; ++ drop(_1) -> [return: bb10, unwind terminate(cleanup)]; + } + + bb12 (cleanup): { diff --git a/tests/mir-opt/issue_41110.test.ElaborateDrops.panic-unwind.diff b/tests/mir-opt/issue_41110.test.ElaborateDrops.panic-unwind.diff index 8da15ec9e23e3..688887c3c1f52 100644 --- a/tests/mir-opt/issue_41110.test.ElaborateDrops.panic-unwind.diff +++ b/tests/mir-opt/issue_41110.test.ElaborateDrops.panic-unwind.diff @@ -47,7 +47,7 @@ bb3 (cleanup): { _2 = move _5; -- drop(_5) -> [return: bb8, unwind terminate (panic in a destructor during cleanup)]; +- drop(_5) -> [return: bb8, unwind terminate(cleanup)]; + goto -> bb8; } @@ -70,17 +70,17 @@ } bb7 (cleanup): { -- drop(_4) -> [return: bb8, unwind terminate (panic in a destructor during cleanup)]; +- drop(_4) -> [return: bb8, unwind terminate(cleanup)]; + goto -> bb8; } bb8 (cleanup): { -- drop(_2) -> [return: bb9, unwind terminate (panic in a destructor during cleanup)]; +- drop(_2) -> [return: bb9, unwind terminate(cleanup)]; + goto -> bb9; } bb9 (cleanup): { -- drop(_1) -> [return: bb10, unwind terminate (panic in a destructor during cleanup)]; +- drop(_1) -> [return: bb10, unwind terminate(cleanup)]; + goto -> bb12; } @@ -89,7 +89,7 @@ + } + + bb11 (cleanup): { -+ drop(_1) -> [return: bb10, unwind terminate (panic in a destructor during cleanup)]; ++ drop(_1) -> [return: bb10, unwind terminate(cleanup)]; + } + + bb12 (cleanup): { diff --git a/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-abort.diff b/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-abort.diff index 562e684f29fdf..b57fe348c2d9d 100644 --- a/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-abort.diff +++ b/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-abort.diff @@ -58,7 +58,7 @@ + _8 = const true; + _9 = const true; _1 = move _3; -- drop(_3) -> [return: bb11, unwind terminate (panic in a destructor during cleanup)]; +- drop(_3) -> [return: bb11, unwind terminate(cleanup)]; + goto -> bb11; } @@ -102,7 +102,7 @@ } bb11 (cleanup): { -- drop(_1) -> [return: bb12, unwind terminate (panic in a destructor during cleanup)]; +- drop(_1) -> [return: bb12, unwind terminate(cleanup)]; + goto -> bb12; } @@ -124,7 +124,7 @@ + } + + bb16 (cleanup): { -+ drop(_1) -> [return: bb12, unwind terminate (panic in a destructor during cleanup)]; ++ drop(_1) -> [return: bb12, unwind terminate(cleanup)]; + } + + bb17: { diff --git a/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-unwind.diff b/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-unwind.diff index c6cc80c09c08b..2156850e38c0e 100644 --- a/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-unwind.diff +++ b/tests/mir-opt/issue_41888.main.ElaborateDrops.panic-unwind.diff @@ -58,7 +58,7 @@ + _8 = const true; + _9 = const true; _1 = move _3; -- drop(_3) -> [return: bb11, unwind terminate (panic in a destructor during cleanup)]; +- drop(_3) -> [return: bb11, unwind terminate(cleanup)]; + goto -> bb11; } @@ -102,7 +102,7 @@ } bb11 (cleanup): { -- drop(_1) -> [return: bb12, unwind terminate (panic in a destructor during cleanup)]; +- drop(_1) -> [return: bb12, unwind terminate(cleanup)]; + goto -> bb12; } @@ -124,7 +124,7 @@ + } + + bb16 (cleanup): { -+ drop(_1) -> [return: bb12, unwind terminate (panic in a destructor during cleanup)]; ++ drop(_1) -> [return: bb12, unwind terminate(cleanup)]; + } + + bb17: { diff --git a/tests/mir-opt/issue_62289.test.ElaborateDrops.before.panic-abort.mir b/tests/mir-opt/issue_62289.test.ElaborateDrops.before.panic-abort.mir index 151571f57eb3d..7346296785033 100644 --- a/tests/mir-opt/issue_62289.test.ElaborateDrops.before.panic-abort.mir +++ b/tests/mir-opt/issue_62289.test.ElaborateDrops.before.panic-abort.mir @@ -100,11 +100,11 @@ fn test() -> Option> { } bb11 (cleanup): { - drop(_1) -> [return: bb13, unwind terminate (panic in a destructor during cleanup)]; + drop(_1) -> [return: bb13, unwind terminate(cleanup)]; } bb12 (cleanup): { - drop(_5) -> [return: bb13, unwind terminate (panic in a destructor during cleanup)]; + drop(_5) -> [return: bb13, unwind terminate(cleanup)]; } bb13 (cleanup): { diff --git a/tests/mir-opt/issue_62289.test.ElaborateDrops.before.panic-unwind.mir b/tests/mir-opt/issue_62289.test.ElaborateDrops.before.panic-unwind.mir index bda3080edb9d1..8264e2cabbc55 100644 --- a/tests/mir-opt/issue_62289.test.ElaborateDrops.before.panic-unwind.mir +++ b/tests/mir-opt/issue_62289.test.ElaborateDrops.before.panic-unwind.mir @@ -100,11 +100,11 @@ fn test() -> Option> { } bb11 (cleanup): { - drop(_1) -> [return: bb13, unwind terminate (panic in a destructor during cleanup)]; + drop(_1) -> [return: bb13, unwind terminate(cleanup)]; } bb12 (cleanup): { - drop(_5) -> [return: bb13, unwind terminate (panic in a destructor during cleanup)]; + drop(_5) -> [return: bb13, unwind terminate(cleanup)]; } bb13 (cleanup): { diff --git a/tests/mir-opt/issue_91633.bar.built.after.mir b/tests/mir-opt/issue_91633.bar.built.after.mir index 6aa49aab20e35..cce1a1fd2ef4a 100644 --- a/tests/mir-opt/issue_91633.bar.built.after.mir +++ b/tests/mir-opt/issue_91633.bar.built.after.mir @@ -28,7 +28,7 @@ fn bar(_1: Box<[T]>) -> () { } bb3 (cleanup): { - drop(_1) -> [return: bb4, unwind terminate (panic in a destructor during cleanup)]; + drop(_1) -> [return: bb4, unwind terminate(cleanup)]; } bb4 (cleanup): { diff --git a/tests/mir-opt/issue_91633.foo.built.after.mir b/tests/mir-opt/issue_91633.foo.built.after.mir index 2cf683217432b..a66769f0d112e 100644 --- a/tests/mir-opt/issue_91633.foo.built.after.mir +++ b/tests/mir-opt/issue_91633.foo.built.after.mir @@ -45,7 +45,7 @@ fn foo(_1: Box<[T]>) -> T { } bb5 (cleanup): { - drop(_1) -> [return: bb6, unwind terminate (panic in a destructor during cleanup)]; + drop(_1) -> [return: bb6, unwind terminate(cleanup)]; } bb6 (cleanup): { diff --git a/tests/mir-opt/match_arm_scopes.complicated_match.panic-abort.SimplifyCfg-initial.after-ElaborateDrops.after.diff b/tests/mir-opt/match_arm_scopes.complicated_match.panic-abort.SimplifyCfg-initial.after-ElaborateDrops.after.diff index 9452ba7e6bc9a..3e817ff433b8a 100644 --- a/tests/mir-opt/match_arm_scopes.complicated_match.panic-abort.SimplifyCfg-initial.after-ElaborateDrops.after.diff +++ b/tests/mir-opt/match_arm_scopes.complicated_match.panic-abort.SimplifyCfg-initial.after-ElaborateDrops.after.diff @@ -243,7 +243,7 @@ } - bb25 (cleanup): { -- drop(_2) -> [return: bb26, unwind terminate (panic in a destructor during cleanup)]; +- drop(_2) -> [return: bb26, unwind terminate(cleanup)]; + bb22 (cleanup): { + goto -> bb27; } diff --git a/tests/mir-opt/match_arm_scopes.complicated_match.panic-unwind.SimplifyCfg-initial.after-ElaborateDrops.after.diff b/tests/mir-opt/match_arm_scopes.complicated_match.panic-unwind.SimplifyCfg-initial.after-ElaborateDrops.after.diff index 9452ba7e6bc9a..3e817ff433b8a 100644 --- a/tests/mir-opt/match_arm_scopes.complicated_match.panic-unwind.SimplifyCfg-initial.after-ElaborateDrops.after.diff +++ b/tests/mir-opt/match_arm_scopes.complicated_match.panic-unwind.SimplifyCfg-initial.after-ElaborateDrops.after.diff @@ -243,7 +243,7 @@ } - bb25 (cleanup): { -- drop(_2) -> [return: bb26, unwind terminate (panic in a destructor during cleanup)]; +- drop(_2) -> [return: bb26, unwind terminate(cleanup)]; + bb22 (cleanup): { + goto -> bb27; } diff --git a/tests/mir-opt/no_spurious_drop_after_call.main.ElaborateDrops.before.panic-abort.mir b/tests/mir-opt/no_spurious_drop_after_call.main.ElaborateDrops.before.panic-abort.mir index 51a009056d741..99a7a6b6154d5 100644 --- a/tests/mir-opt/no_spurious_drop_after_call.main.ElaborateDrops.before.panic-abort.mir +++ b/tests/mir-opt/no_spurious_drop_after_call.main.ElaborateDrops.before.panic-abort.mir @@ -31,7 +31,7 @@ fn main() -> () { } bb3 (cleanup): { - drop(_2) -> [return: bb4, unwind terminate (panic in a destructor during cleanup)]; + drop(_2) -> [return: bb4, unwind terminate(cleanup)]; } bb4 (cleanup): { diff --git a/tests/mir-opt/no_spurious_drop_after_call.main.ElaborateDrops.before.panic-unwind.mir b/tests/mir-opt/no_spurious_drop_after_call.main.ElaborateDrops.before.panic-unwind.mir index 95820cfafbc12..7364b329e123a 100644 --- a/tests/mir-opt/no_spurious_drop_after_call.main.ElaborateDrops.before.panic-unwind.mir +++ b/tests/mir-opt/no_spurious_drop_after_call.main.ElaborateDrops.before.panic-unwind.mir @@ -31,7 +31,7 @@ fn main() -> () { } bb3 (cleanup): { - drop(_2) -> [return: bb4, unwind terminate (panic in a destructor during cleanup)]; + drop(_2) -> [return: bb4, unwind terminate(cleanup)]; } bb4 (cleanup): { diff --git a/tests/mir-opt/packed_struct_drop_aligned.main.SimplifyCfg-elaborate-drops.after.panic-unwind.mir b/tests/mir-opt/packed_struct_drop_aligned.main.SimplifyCfg-elaborate-drops.after.panic-unwind.mir index 9a43756cbc06a..0ef19180459dc 100644 --- a/tests/mir-opt/packed_struct_drop_aligned.main.SimplifyCfg-elaborate-drops.after.panic-unwind.mir +++ b/tests/mir-opt/packed_struct_drop_aligned.main.SimplifyCfg-elaborate-drops.after.panic-unwind.mir @@ -33,7 +33,7 @@ fn main() -> () { bb1 (cleanup): { (_1.0: Aligned) = move _4; - drop(_1) -> [return: bb3, unwind terminate (panic in a destructor during cleanup)]; + drop(_1) -> [return: bb3, unwind terminate(cleanup)]; } bb2: { diff --git a/tests/mir-opt/pre-codegen/loops.filter_mapped.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/loops.filter_mapped.PreCodegen.after.mir index d7059d21488a4..4db829a5ec349 100644 --- a/tests/mir-opt/pre-codegen/loops.filter_mapped.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/loops.filter_mapped.PreCodegen.after.mir @@ -83,7 +83,7 @@ fn filter_mapped(_1: impl Iterator, _2: impl Fn(T) -> Option) -> () } bb9 (cleanup): { - drop(_5) -> [return: bb10, unwind terminate (panic in a destructor during cleanup)]; + drop(_5) -> [return: bb10, unwind terminate(cleanup)]; } bb10 (cleanup): { diff --git a/tests/mir-opt/pre-codegen/loops.mapped.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/loops.mapped.PreCodegen.after.mir index 9a10f5cb575a7..c30df7425d204 100644 --- a/tests/mir-opt/pre-codegen/loops.mapped.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/loops.mapped.PreCodegen.after.mir @@ -75,7 +75,7 @@ fn mapped(_1: impl Iterator, _2: impl Fn(T) -> U) -> () { } bb9 (cleanup): { - drop(_5) -> [return: bb10, unwind terminate (panic in a destructor during cleanup)]; + drop(_5) -> [return: bb10, unwind terminate(cleanup)]; } bb10 (cleanup): { diff --git a/tests/mir-opt/pre-codegen/loops.vec_move.PreCodegen.after.mir b/tests/mir-opt/pre-codegen/loops.vec_move.PreCodegen.after.mir index 431661af705be..cb29473d7627f 100644 --- a/tests/mir-opt/pre-codegen/loops.vec_move.PreCodegen.after.mir +++ b/tests/mir-opt/pre-codegen/loops.vec_move.PreCodegen.after.mir @@ -67,7 +67,7 @@ fn vec_move(_1: Vec) -> () { } bb9 (cleanup): { - drop(_3) -> [return: bb10, unwind terminate (panic in a destructor during cleanup)]; + drop(_3) -> [return: bb10, unwind terminate(cleanup)]; } bb10 (cleanup): { diff --git a/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-unwind.mir index 7cada9c148d4d..35f7356d47a61 100644 --- a/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/range_iter.forward_loop.PreCodegen.after.panic-unwind.mir @@ -127,7 +127,7 @@ fn forward_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () { } bb11 (cleanup): { - drop(_3) -> [return: bb12, unwind terminate (panic in a destructor during cleanup)]; + drop(_3) -> [return: bb12, unwind terminate(cleanup)]; } bb12 (cleanup): { diff --git a/tests/mir-opt/pre-codegen/range_iter.inclusive_loop.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/range_iter.inclusive_loop.PreCodegen.after.panic-unwind.mir index ef1f934c52b2d..a677e8b439fa0 100644 --- a/tests/mir-opt/pre-codegen/range_iter.inclusive_loop.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/range_iter.inclusive_loop.PreCodegen.after.panic-unwind.mir @@ -82,7 +82,7 @@ fn inclusive_loop(_1: u32, _2: u32, _3: impl Fn(u32)) -> () { } bb8 (cleanup): { - drop(_3) -> [return: bb9, unwind terminate (panic in a destructor during cleanup)]; + drop(_3) -> [return: bb9, unwind terminate(cleanup)]; } bb9 (cleanup): { diff --git a/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-unwind.mir index b9636712f826d..3d76bab7ce70e 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.enumerated_loop.PreCodegen.after.panic-unwind.mir @@ -195,7 +195,7 @@ fn enumerated_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { } bb11 (cleanup): { - drop(_2) -> [return: bb12, unwind terminate (panic in a destructor during cleanup)]; + drop(_2) -> [return: bb12, unwind terminate(cleanup)]; } bb12 (cleanup): { diff --git a/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-unwind.mir index 0f323a56e61de..e8586cec981c3 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.panic-unwind.mir @@ -182,7 +182,7 @@ fn forward_loop(_1: &[T], _2: impl Fn(&T)) -> () { } bb11 (cleanup): { - drop(_2) -> [return: bb12, unwind terminate (panic in a destructor during cleanup)]; + drop(_2) -> [return: bb12, unwind terminate(cleanup)]; } bb12 (cleanup): { diff --git a/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-unwind.mir index 96160b272b980..8bd072fd625e7 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.range_loop.PreCodegen.after.panic-unwind.mir @@ -143,7 +143,7 @@ fn range_loop(_1: &[T], _2: impl Fn(usize, &T)) -> () { } bb12 (cleanup): { - drop(_2) -> [return: bb13, unwind terminate (panic in a destructor during cleanup)]; + drop(_2) -> [return: bb13, unwind terminate(cleanup)]; } bb13 (cleanup): { diff --git a/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-unwind.mir b/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-unwind.mir index 67d8442ab206f..3cdc49f6056bd 100644 --- a/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-unwind.mir +++ b/tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.panic-unwind.mir @@ -196,7 +196,7 @@ fn reverse_loop(_1: &[T], _2: impl Fn(&T)) -> () { } bb11 (cleanup): { - drop(_2) -> [return: bb12, unwind terminate (panic in a destructor during cleanup)]; + drop(_2) -> [return: bb12, unwind terminate(cleanup)]; } bb12 (cleanup): { diff --git a/tests/mir-opt/retag.main.SimplifyCfg-elaborate-drops.after.panic-unwind.mir b/tests/mir-opt/retag.main.SimplifyCfg-elaborate-drops.after.panic-unwind.mir index 09ff59ffa2153..7d3346faba6c6 100644 --- a/tests/mir-opt/retag.main.SimplifyCfg-elaborate-drops.after.panic-unwind.mir +++ b/tests/mir-opt/retag.main.SimplifyCfg-elaborate-drops.after.panic-unwind.mir @@ -167,11 +167,11 @@ fn main() -> () { } bb7 (cleanup): { - drop(_21) -> [return: bb9, unwind terminate (panic in a destructor during cleanup)]; + drop(_21) -> [return: bb9, unwind terminate(cleanup)]; } bb8 (cleanup): { - drop(_5) -> [return: bb9, unwind terminate (panic in a destructor during cleanup)]; + drop(_5) -> [return: bb9, unwind terminate(cleanup)]; } bb9 (cleanup): { diff --git a/tests/mir-opt/slice_drop_shim.core.ptr-drop_in_place.[String].AddMovesForPackedDrops.before.mir b/tests/mir-opt/slice_drop_shim.core.ptr-drop_in_place.[String].AddMovesForPackedDrops.before.mir index 8d9f898557890..3a8b457a7a109 100644 --- a/tests/mir-opt/slice_drop_shim.core.ptr-drop_in_place.[String].AddMovesForPackedDrops.before.mir +++ b/tests/mir-opt/slice_drop_shim.core.ptr-drop_in_place.[String].AddMovesForPackedDrops.before.mir @@ -24,7 +24,7 @@ fn std::ptr::drop_in_place(_1: *mut [String]) -> () { bb3 (cleanup): { _4 = &raw mut (*_1)[_3]; _3 = Add(move _3, const 1_usize); - drop((*_4)) -> [return: bb4, unwind terminate (panic in a destructor during cleanup)]; + drop((*_4)) -> [return: bb4, unwind terminate(cleanup)]; } bb4 (cleanup): { diff --git a/tests/mir-opt/unusual_item_types.core.ptr-drop_in_place.Vec_i32_.AddMovesForPackedDrops.before.mir b/tests/mir-opt/unusual_item_types.core.ptr-drop_in_place.Vec_i32_.AddMovesForPackedDrops.before.mir index 3768d34dd8ec1..b587941835515 100644 --- a/tests/mir-opt/unusual_item_types.core.ptr-drop_in_place.Vec_i32_.AddMovesForPackedDrops.before.mir +++ b/tests/mir-opt/unusual_item_types.core.ptr-drop_in_place.Vec_i32_.AddMovesForPackedDrops.before.mir @@ -22,7 +22,7 @@ fn std::ptr::drop_in_place(_1: *mut Vec) -> () { } bb4 (cleanup): { - drop(((*_1).0: alloc::raw_vec::RawVec)) -> [return: bb2, unwind terminate (panic in a destructor during cleanup)]; + drop(((*_1).0: alloc::raw_vec::RawVec)) -> [return: bb2, unwind terminate(cleanup)]; } bb5: { From 339d636120cbec1a593557498389e616b47a032a Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 24 Aug 2023 18:22:32 +0200 Subject: [PATCH 7/8] attempt to better normalize remote-test-client output for tests --- src/tools/compiletest/src/runtest.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 4ef79af3124a8..f8e5a158bfdbd 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -3634,26 +3634,30 @@ impl<'test> TestCx<'test> { let expected_stderr = self.load_expected_output(stderr_kind); let expected_stdout = self.load_expected_output(stdout_kind); - let normalized_stdout = match output_kind { + let mut normalized_stdout = + self.normalize_output(&proc_res.stdout, &self.props.normalize_stdout); + match output_kind { TestOutput::Run if self.config.remote_test_client.is_some() => { // When tests are run using the remote-test-client, the string // 'uploaded "$TEST_BUILD_DIR/, waiting for result"' // is printed to stdout by the client and then captured in the ProcRes, - // so it needs to be removed when comparing the run-pass test execution output + // so it needs to be removed when comparing the run-pass test execution output. static REMOTE_TEST_RE: Lazy = Lazy::new(|| { Regex::new( "^uploaded \"\\$TEST_BUILD_DIR(/[[:alnum:]_\\-.]+)+\", waiting for result\n" ) .unwrap() }); - REMOTE_TEST_RE - .replace( - &self.normalize_output(&proc_res.stdout, &self.props.normalize_stdout), - "", - ) - .to_string() + normalized_stdout = REMOTE_TEST_RE.replace(&normalized_stdout, "").to_string(); + // When there is a panic, the remote-test-client also prints "died due to signal"; + // that needs to be removed as well. + static SIGNAL_DIED_RE: Lazy = + Lazy::new(|| Regex::new("^died due to signal [0-9]+\n").unwrap()); + normalized_stdout = SIGNAL_DIED_RE.replace(&normalized_stdout, "").to_string(); + // FIXME: it would be much nicer if we could just tell the remote-test-client to not + // print these things. } - _ => self.normalize_output(&proc_res.stdout, &self.props.normalize_stdout), + _ => {} }; let stderr = if explicit_format { From df5a248cb1d557f8df9c9d0660e8d704bc1e0919 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 24 Aug 2023 20:08:22 +0200 Subject: [PATCH 8/8] keep trying which flags we need for this test until it passes bors --- tests/ui/panics/panic-in-cleanup.rs | 5 ++++- tests/ui/panics/panic-in-cleanup.run.stderr | 4 ++-- tests/ui/panics/panic-in-ffi.rs | 4 +++- tests/ui/panics/panic-in-ffi.run.stderr | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/ui/panics/panic-in-cleanup.rs b/tests/ui/panics/panic-in-cleanup.rs index b4519da4e6a77..a1c797268d107 100644 --- a/tests/ui/panics/panic-in-cleanup.rs +++ b/tests/ui/panics/panic-in-cleanup.rs @@ -1,9 +1,12 @@ // run-fail +// exec-env:RUST_BACKTRACE=0 // check-run-results // error-pattern: panic in a destructor during cleanup // normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> "" // normalize-stderr-test: "\n +at [^\n]+" -> "" -// ignore-emscripten no processes +// needs-unwind +// ignore-emscripten "RuntimeError" junk in output +// ignore-msvc SEH doesn't do panic-during-cleanup the same way as everyone else struct Bomb; diff --git a/tests/ui/panics/panic-in-cleanup.run.stderr b/tests/ui/panics/panic-in-cleanup.run.stderr index fa201b9667f25..923bac69c50ef 100644 --- a/tests/ui/panics/panic-in-cleanup.run.stderr +++ b/tests/ui/panics/panic-in-cleanup.run.stderr @@ -1,7 +1,7 @@ -thread 'main' panicked at $DIR/panic-in-cleanup.rs:18:5: +thread 'main' panicked at $DIR/panic-in-cleanup.rs:21:5: explicit panic note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -thread 'main' panicked at $DIR/panic-in-cleanup.rs:12:9: +thread 'main' panicked at $DIR/panic-in-cleanup.rs:15:9: BOOM stack backtrace: thread 'main' panicked at library/core/src/panicking.rs:126:5: diff --git a/tests/ui/panics/panic-in-ffi.rs b/tests/ui/panics/panic-in-ffi.rs index bb30398531f0a..da2b24945bed1 100644 --- a/tests/ui/panics/panic-in-ffi.rs +++ b/tests/ui/panics/panic-in-ffi.rs @@ -1,9 +1,11 @@ // run-fail +// exec-env:RUST_BACKTRACE=0 // check-run-results // error-pattern: panic in a function that cannot unwind // normalize-stderr-test: "\n +[0-9]+:[^\n]+" -> "" // normalize-stderr-test: "\n +at [^\n]+" -> "" -// ignore-emscripten no processes +// needs-unwind +// ignore-emscripten "RuntimeError" junk in output #![feature(c_unwind)] extern "C" fn panic_in_ffi() { diff --git a/tests/ui/panics/panic-in-ffi.run.stderr b/tests/ui/panics/panic-in-ffi.run.stderr index a6de98c4913e3..3422f5ccc4d3c 100644 --- a/tests/ui/panics/panic-in-ffi.run.stderr +++ b/tests/ui/panics/panic-in-ffi.run.stderr @@ -1,4 +1,4 @@ -thread 'main' panicked at $DIR/panic-in-ffi.rs:10:5: +thread 'main' panicked at $DIR/panic-in-ffi.rs:12:5: Test note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace thread 'main' panicked at library/core/src/panicking.rs:126:5: