22// Adapted from rustc
33
44use cranelift_frontend:: { FunctionBuilder , FunctionBuilderContext } ;
5- use rustc_ast:: expand:: allocator:: {
6- AllocatorKind , NO_ALLOC_SHIM_IS_UNSTABLE , alloc_error_handler_name,
7- } ;
5+ use rustc_ast:: expand:: allocator:: NO_ALLOC_SHIM_IS_UNSTABLE ;
86use rustc_codegen_ssa:: base:: needs_allocator_shim;
97use rustc_session:: config:: OomStrategy ;
108use rustc_symbol_mangling:: mangle_internal_symbol;
@@ -14,46 +12,15 @@ use crate::prelude::*;
1412/// Returns whether an allocator shim was created
1513pub ( crate ) fn codegen ( tcx : TyCtxt < ' _ > , module : & mut dyn Module ) -> bool {
1614 if needs_allocator_shim ( tcx) {
17- codegen_inner (
18- tcx,
19- module,
20- tcx. alloc_error_handler_kind ( ( ) ) . unwrap ( ) ,
21- tcx. sess . opts . unstable_opts . oom ,
22- ) ;
15+ codegen_inner ( tcx, module, tcx. sess . opts . unstable_opts . oom ) ;
2316 true
2417 } else {
2518 false
2619 }
2720}
2821
29- fn codegen_inner (
30- tcx : TyCtxt < ' _ > ,
31- module : & mut dyn Module ,
32- alloc_error_handler_kind : AllocatorKind ,
33- oom_strategy : OomStrategy ,
34- ) {
35- let usize_ty = module. target_config ( ) . pointer_type ( ) ;
36-
37- let sig = Signature {
38- call_conv : module. target_config ( ) . default_call_conv ,
39- params : vec ! [ AbiParam :: new( usize_ty) , AbiParam :: new( usize_ty) ] ,
40- returns : vec ! [ ] ,
41- } ;
42- crate :: common:: create_wrapper_function (
43- module,
44- sig,
45- & mangle_internal_symbol ( tcx, "__rust_alloc_error_handler" ) ,
46- & mangle_internal_symbol ( tcx, alloc_error_handler_name ( alloc_error_handler_kind) ) ,
47- ) ;
48-
49- let data_id = module
50- . declare_data (
51- & mangle_internal_symbol ( tcx, OomStrategy :: SYMBOL ) ,
52- Linkage :: Export ,
53- false ,
54- false ,
55- )
56- . unwrap ( ) ;
22+ fn codegen_inner ( tcx : TyCtxt < ' _ > , module : & mut dyn Module , oom_strategy : OomStrategy ) {
23+ let data_id = module. declare_data ( OomStrategy :: SYMBOL , Linkage :: Export , false , false ) . unwrap ( ) ;
5724 let mut data = DataDescription :: new ( ) ;
5825 data. set_align ( 1 ) ;
5926 let val = oom_strategy. should_panic ( ) ;
0 commit comments