22
33use cranelift_codegen:: CodegenError ;
44use cranelift_codegen:: ir:: { BlockArg , ExceptionTableData , ExceptionTag , UserFuncName } ;
5- use cranelift_frontend:: { FunctionBuilder , FunctionBuilderContext } ;
5+ use cranelift_frontend:: { FunctionBuilder , FunctionBuilderContext , Variable } ;
66use cranelift_module:: ModuleError ;
77use rustc_ast:: InlineAsmOptions ;
88use rustc_codegen_ssa:: base:: is_call_from_compiler_builtins_to_upstream_monomorphization;
@@ -110,22 +110,16 @@ pub(crate) fn codegen_fn<'tcx>(
110110 // Make FunctionCx
111111 let target_config = module. target_config ( ) ;
112112 let pointer_type = target_config. pointer_type ( ) ;
113- let mut clif_comments = crate :: pretty_clif:: CommentWriter :: new ( tcx, instance, fn_abi) ;
113+ let clif_comments = crate :: pretty_clif:: CommentWriter :: new ( tcx, instance, fn_abi) ;
114114
115115 let func_debug_cx = if let Some ( debug_context) = & mut cx. debug_context {
116116 Some ( debug_context. define_function ( tcx, type_dbg, instance, fn_abi, & symbol_name, mir. span ) )
117117 } else {
118118 None
119119 } ;
120120
121- let exception_slot = bcx. func . create_sized_stack_slot ( StackSlotData {
122- kind : StackSlotKind :: ExplicitSlot ,
123- size : pointer_type. bytes ( ) ,
124- align_shift : 4 ,
125- } ) ;
126- if clif_comments. enabled ( ) {
127- clif_comments. add_comment ( exception_slot, "exception slot" ) ;
128- }
121+ let exception_slot = Variable :: from_u32 ( 0 ) ;
122+ bcx. declare_var ( exception_slot, pointer_type) ;
129123
130124 let mut fx = FunctionCx {
131125 cx,
@@ -145,10 +139,10 @@ pub(crate) fn codegen_fn<'tcx>(
145139 block_map,
146140 local_map : IndexVec :: with_capacity ( mir. local_decls . len ( ) ) ,
147141 caller_location : None , // set by `codegen_fn_prelude`
148- exception_slot : Pointer :: stack_slot ( exception_slot ) ,
142+ exception_slot,
149143
150144 clif_comments,
151- next_ssa_var : 0 ,
145+ next_ssa_var : 1 , // var0 is used for the exception slot
152146 } ;
153147
154148 tcx. prof . generic_activity ( "codegen clif ir" ) . run ( || codegen_fn_body ( & mut fx, start_block) ) ;
@@ -575,8 +569,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
575569 codegen_unwind_terminate ( fx, source_info, * reason) ;
576570 }
577571 TerminatorKind :: UnwindResume => {
578- let exception_ptr =
579- fx. exception_slot . load ( fx, fx. pointer_type , MemFlags :: trusted ( ) ) ;
572+ let exception_ptr = fx. bcx . use_var ( fx. exception_slot ) ;
580573 fx. lib_call (
581574 "_Unwind_Resume" ,
582575 vec ! [ AbiParam :: new( fx. pointer_type) ] ,
@@ -1204,7 +1197,7 @@ fn codegen_panic_inner<'tcx>(
12041197 fx. bcx . switch_to_block ( cleanup_block) ;
12051198 fx. bcx . set_cold_block ( cleanup_block) ;
12061199 let exception_ptr = fx. bcx . append_block_param ( cleanup_block, fx. pointer_type ) ;
1207- fx. exception_slot . store ( fx, exception_ptr, MemFlags :: trusted ( ) ) ;
1200+ fx. bcx . def_var ( fx. exception_slot , exception_ptr) ;
12081201 let cleanup_block = fx. get_block ( cleanup) ;
12091202 fx. bcx . ins ( ) . jump ( cleanup_block, & [ ] ) ;
12101203
0 commit comments