Skip to content

Commit 1a39299

Browse files
committed
Handle UnwindAction::Terminate
1 parent a07265e commit 1a39299

File tree

2 files changed

+36
-19
lines changed

2 files changed

+36
-19
lines changed

Diff for: src/abi/mod.rs

+24-9
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use smallvec::{SmallVec, smallvec};
2424

2525
use self::pass_mode::*;
2626
pub(crate) use self::returning::codegen_return;
27+
use crate::base::codegen_unwind_terminate;
2728
use crate::prelude::*;
2829

2930
fn clif_sig_from_fn_abi<'tcx>(
@@ -584,7 +585,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
584585
with_no_trimmed_paths!(fx.add_comment(nop_inst, format!("abi: {:?}", fn_abi)));
585586
}
586587

587-
codegen_call_with_unwind_action(fx, func_ref, unwind, &call_args, None)
588+
codegen_call_with_unwind_action(fx, source_info.span, func_ref, unwind, &call_args, None)
588589
});
589590

590591
if let Some(dest) = target {
@@ -743,6 +744,7 @@ pub(crate) fn codegen_drop<'tcx>(
743744
let sig = fx.bcx.import_signature(sig);
744745
codegen_call_with_unwind_action(
745746
fx,
747+
source_info.span,
746748
CallTarget::Indirect(sig, drop_fn),
747749
unwind,
748750
&[ptr],
@@ -792,6 +794,7 @@ pub(crate) fn codegen_drop<'tcx>(
792794
let sig = fx.bcx.import_signature(sig);
793795
codegen_call_with_unwind_action(
794796
fx,
797+
source_info.span,
795798
CallTarget::Indirect(sig, drop_fn),
796799
unwind,
797800
&[data],
@@ -823,6 +826,7 @@ pub(crate) fn codegen_drop<'tcx>(
823826
let func_ref = fx.get_function_ref(drop_instance);
824827
codegen_call_with_unwind_action(
825828
fx,
829+
source_info.span,
826830
CallTarget::Direct(func_ref),
827831
unwind,
828832
&call_args,
@@ -841,6 +845,7 @@ pub(crate) enum CallTarget {
841845

842846
pub(crate) fn codegen_call_with_unwind_action(
843847
fx: &mut FunctionCx<'_, '_, '_>,
848+
span: Span,
844849
func_ref: CallTarget,
845850
unwind: UnwindAction,
846851
call_args: &[Value],
@@ -854,10 +859,8 @@ pub(crate) fn codegen_call_with_unwind_action(
854859
if target_block.is_some() {
855860
assert!(fx.bcx.func.dfg.signatures[sig_ref].returns.is_empty());
856861
}
857-
858862
match unwind {
859-
// FIXME abort on unreachable and terminate unwinds
860-
UnwindAction::Continue | UnwindAction::Unreachable | UnwindAction::Terminate(_) => {
863+
UnwindAction::Continue | UnwindAction::Unreachable => {
861864
let call_inst = match func_ref {
862865
CallTarget::Direct(func_ref) => fx.bcx.ins().call(func_ref, &call_args),
863866
CallTarget::Indirect(sig, func_ptr) => {
@@ -878,7 +881,7 @@ pub(crate) fn codegen_call_with_unwind_action(
878881
.collect::<SmallVec<[Value; 2]>>()
879882
}
880883
}
881-
UnwindAction::Cleanup(cleanup) => {
884+
UnwindAction::Cleanup(_) | UnwindAction::Terminate(_) => {
882885
let returns_types = fx.bcx.func.dfg.signatures[sig_ref]
883886
.returns
884887
.iter()
@@ -916,10 +919,22 @@ pub(crate) fn codegen_call_with_unwind_action(
916919
fx.bcx.seal_block(pre_cleanup_block);
917920
fx.bcx.switch_to_block(pre_cleanup_block);
918921
fx.bcx.set_cold_block(pre_cleanup_block);
919-
let exception_ptr = fx.bcx.append_block_param(pre_cleanup_block, fx.pointer_type);
920-
fx.bcx.def_var(fx.exception_slot, exception_ptr);
921-
let cleanup_block = fx.get_block(cleanup);
922-
fx.bcx.ins().jump(cleanup_block, &[]);
922+
match unwind {
923+
UnwindAction::Continue | UnwindAction::Unreachable => unreachable!(),
924+
UnwindAction::Cleanup(cleanup) => {
925+
let exception_ptr =
926+
fx.bcx.append_block_param(pre_cleanup_block, fx.pointer_type);
927+
fx.bcx.def_var(fx.exception_slot, exception_ptr);
928+
let cleanup_block = fx.get_block(cleanup);
929+
fx.bcx.ins().jump(cleanup_block, &[]);
930+
}
931+
UnwindAction::Terminate(reason) => {
932+
// FIXME dedup terminate blocks
933+
fx.bcx.append_block_param(pre_cleanup_block, fx.pointer_type);
934+
935+
codegen_unwind_terminate(fx, span, reason);
936+
}
937+
}
923938

924939
if target_block.is_none() {
925940
fx.bcx.seal_block(fallthrough_block);

Diff for: src/base.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_middle::ty::TypeVisitableExt;
1414
use rustc_middle::ty::adjustment::PointerCoercion;
1515
use rustc_middle::ty::layout::{FnAbiOf, HasTypingEnv};
1616
use rustc_middle::ty::print::with_no_trimmed_paths;
17+
use rustc_span::DUMMY_SP;
1718

1819
use crate::constant::ConstantCx;
1920
use crate::debuginfo::{FunctionDebugContext, TypeDebugContext};
@@ -566,7 +567,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
566567
);
567568
}
568569
TerminatorKind::UnwindTerminate(reason) => {
569-
codegen_unwind_terminate(fx, source_info, *reason);
570+
codegen_unwind_terminate(fx, source_info.span, *reason);
570571
}
571572
TerminatorKind::UnwindResume => {
572573
let exception_ptr = fx.bcx.use_var(fx.exception_slot);
@@ -1123,16 +1124,10 @@ pub(crate) fn codegen_panic_nounwind<'tcx>(
11231124

11241125
pub(crate) fn codegen_unwind_terminate<'tcx>(
11251126
fx: &mut FunctionCx<'_, '_, 'tcx>,
1126-
source_info: mir::SourceInfo,
1127+
span: Span,
11271128
reason: UnwindTerminateReason,
11281129
) {
1129-
codegen_panic_inner(
1130-
fx,
1131-
reason.lang_item(),
1132-
&[],
1133-
UnwindAction::Terminate(UnwindTerminateReason::Abi),
1134-
Some(source_info.span),
1135-
);
1130+
codegen_panic_inner(fx, reason.lang_item(), &[], UnwindAction::Unreachable, Some(span));
11361131
}
11371132

11381133
fn codegen_panic_inner<'tcx>(
@@ -1171,7 +1166,14 @@ fn codegen_panic_inner<'tcx>(
11711166
fx.add_comment(nop_inst, format!("panic {}", symbol_name));
11721167
}
11731168

1174-
codegen_call_with_unwind_action(fx, CallTarget::Direct(func_ref), unwind, &args, None);
1169+
codegen_call_with_unwind_action(
1170+
fx,
1171+
span.unwrap_or(DUMMY_SP),
1172+
CallTarget::Direct(func_ref),
1173+
unwind,
1174+
&args,
1175+
None,
1176+
);
11751177

11761178
fx.bcx.ins().trap(TrapCode::user(1 /* unreachable */).unwrap());
11771179
}

0 commit comments

Comments
 (0)