2
2
3
3
use cranelift_codegen:: CodegenError ;
4
4
use cranelift_codegen:: ir:: { BlockArg , ExceptionTableData , ExceptionTag , UserFuncName } ;
5
- use cranelift_frontend:: { FunctionBuilder , FunctionBuilderContext } ;
5
+ use cranelift_frontend:: { FunctionBuilder , FunctionBuilderContext , Variable } ;
6
6
use cranelift_module:: ModuleError ;
7
7
use rustc_ast:: InlineAsmOptions ;
8
8
use rustc_codegen_ssa:: base:: is_call_from_compiler_builtins_to_upstream_monomorphization;
@@ -110,22 +110,16 @@ pub(crate) fn codegen_fn<'tcx>(
110
110
// Make FunctionCx
111
111
let target_config = module. target_config ( ) ;
112
112
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) ;
114
114
115
115
let func_debug_cx = if let Some ( debug_context) = & mut cx. debug_context {
116
116
Some ( debug_context. define_function ( tcx, type_dbg, instance, fn_abi, & symbol_name, mir. span ) )
117
117
} else {
118
118
None
119
119
} ;
120
120
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) ;
129
123
130
124
let mut fx = FunctionCx {
131
125
cx,
@@ -145,10 +139,10 @@ pub(crate) fn codegen_fn<'tcx>(
145
139
block_map,
146
140
local_map : IndexVec :: with_capacity ( mir. local_decls . len ( ) ) ,
147
141
caller_location : None , // set by `codegen_fn_prelude`
148
- exception_slot : Pointer :: stack_slot ( exception_slot ) ,
142
+ exception_slot,
149
143
150
144
clif_comments,
151
- next_ssa_var : 0 ,
145
+ next_ssa_var : 1 , // var0 is used for the exception slot
152
146
} ;
153
147
154
148
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) {
575
569
codegen_unwind_terminate ( fx, source_info, * reason) ;
576
570
}
577
571
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 ) ;
580
573
fx. lib_call (
581
574
"_Unwind_Resume" ,
582
575
vec ! [ AbiParam :: new( fx. pointer_type) ] ,
@@ -1204,7 +1197,7 @@ fn codegen_panic_inner<'tcx>(
1204
1197
fx. bcx . switch_to_block ( cleanup_block) ;
1205
1198
fx. bcx . set_cold_block ( cleanup_block) ;
1206
1199
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) ;
1208
1201
let cleanup_block = fx. get_block ( cleanup) ;
1209
1202
fx. bcx . ins ( ) . jump ( cleanup_block, & [ ] ) ;
1210
1203
0 commit comments