@@ -24,6 +24,7 @@ use smallvec::{SmallVec, smallvec};
24
24
25
25
use self :: pass_mode:: * ;
26
26
pub ( crate ) use self :: returning:: codegen_return;
27
+ use crate :: base:: codegen_unwind_terminate;
27
28
use crate :: prelude:: * ;
28
29
29
30
fn clif_sig_from_fn_abi < ' tcx > (
@@ -584,7 +585,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
584
585
with_no_trimmed_paths ! ( fx. add_comment( nop_inst, format!( "abi: {:?}" , fn_abi) ) ) ;
585
586
}
586
587
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 )
588
589
} ) ;
589
590
590
591
if let Some ( dest) = target {
@@ -743,6 +744,7 @@ pub(crate) fn codegen_drop<'tcx>(
743
744
let sig = fx. bcx . import_signature ( sig) ;
744
745
codegen_call_with_unwind_action (
745
746
fx,
747
+ source_info. span ,
746
748
CallTarget :: Indirect ( sig, drop_fn) ,
747
749
unwind,
748
750
& [ ptr] ,
@@ -792,6 +794,7 @@ pub(crate) fn codegen_drop<'tcx>(
792
794
let sig = fx. bcx . import_signature ( sig) ;
793
795
codegen_call_with_unwind_action (
794
796
fx,
797
+ source_info. span ,
795
798
CallTarget :: Indirect ( sig, drop_fn) ,
796
799
unwind,
797
800
& [ data] ,
@@ -823,6 +826,7 @@ pub(crate) fn codegen_drop<'tcx>(
823
826
let func_ref = fx. get_function_ref ( drop_instance) ;
824
827
codegen_call_with_unwind_action (
825
828
fx,
829
+ source_info. span ,
826
830
CallTarget :: Direct ( func_ref) ,
827
831
unwind,
828
832
& call_args,
@@ -841,6 +845,7 @@ pub(crate) enum CallTarget {
841
845
842
846
pub ( crate ) fn codegen_call_with_unwind_action (
843
847
fx : & mut FunctionCx < ' _ , ' _ , ' _ > ,
848
+ span : Span ,
844
849
func_ref : CallTarget ,
845
850
unwind : UnwindAction ,
846
851
call_args : & [ Value ] ,
@@ -854,10 +859,8 @@ pub(crate) fn codegen_call_with_unwind_action(
854
859
if target_block. is_some ( ) {
855
860
assert ! ( fx. bcx. func. dfg. signatures[ sig_ref] . returns. is_empty( ) ) ;
856
861
}
857
-
858
862
match unwind {
859
- // FIXME abort on unreachable and terminate unwinds
860
- UnwindAction :: Continue | UnwindAction :: Unreachable | UnwindAction :: Terminate ( _) => {
863
+ UnwindAction :: Continue | UnwindAction :: Unreachable => {
861
864
let call_inst = match func_ref {
862
865
CallTarget :: Direct ( func_ref) => fx. bcx . ins ( ) . call ( func_ref, & call_args) ,
863
866
CallTarget :: Indirect ( sig, func_ptr) => {
@@ -878,7 +881,7 @@ pub(crate) fn codegen_call_with_unwind_action(
878
881
. collect :: < SmallVec < [ Value ; 2 ] > > ( )
879
882
}
880
883
}
881
- UnwindAction :: Cleanup ( cleanup ) => {
884
+ UnwindAction :: Cleanup ( _ ) | UnwindAction :: Terminate ( _ ) => {
882
885
let returns_types = fx. bcx . func . dfg . signatures [ sig_ref]
883
886
. returns
884
887
. iter ( )
@@ -916,10 +919,22 @@ pub(crate) fn codegen_call_with_unwind_action(
916
919
fx. bcx . seal_block ( pre_cleanup_block) ;
917
920
fx. bcx . switch_to_block ( pre_cleanup_block) ;
918
921
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
+ }
923
938
924
939
if target_block. is_none ( ) {
925
940
fx. bcx . seal_block ( fallthrough_block) ;
0 commit comments