1- #[ cfg( feature= "master" ) ]
1+ #[ cfg( feature = "master" ) ]
22use gccjit:: FnAttribute ;
33use gccjit:: { FunctionType , GlobalKind , ToRValue } ;
44use rustc_ast:: expand:: allocator:: {
5- alloc_error_handler_name , default_fn_name, global_fn_name, AllocatorKind , AllocatorTy ,
6- ALLOCATOR_METHODS , NO_ALLOC_SHIM_IS_UNSTABLE ,
5+ default_fn_name, global_fn_name, AllocatorKind , AllocatorTy , ALLOCATOR_METHODS ,
6+ NO_ALLOC_SHIM_IS_UNSTABLE ,
77} ;
88use rustc_middle:: bug;
99use rustc_middle:: ty:: TyCtxt ;
1010use rustc_session:: config:: OomStrategy ;
1111
1212use crate :: GccContext ;
1313
14- pub ( crate ) unsafe fn codegen ( tcx : TyCtxt < ' _ > , mods : & mut GccContext , _module_name : & str , kind : AllocatorKind , alloc_error_handler_kind : AllocatorKind ) {
14+ pub ( crate ) unsafe fn codegen (
15+ tcx : TyCtxt < ' _ > ,
16+ mods : & mut GccContext ,
17+ _module_name : & str ,
18+ kind : AllocatorKind ,
19+ ) {
1520 let context = & mods. context ;
16- let usize =
17- match tcx. sess . target . pointer_width {
18- 16 => context. new_type :: < u16 > ( ) ,
19- 32 => context. new_type :: < u32 > ( ) ,
20- 64 => context. new_type :: < u64 > ( ) ,
21- tws => bug ! ( "Unsupported target word size for int: {}" , tws) ,
22- } ;
21+ let usize = match tcx. sess . target . pointer_width {
22+ 16 => context. new_type :: < u16 > ( ) ,
23+ 32 => context. new_type :: < u32 > ( ) ,
24+ 64 => context. new_type :: < u64 > ( ) ,
25+ tws => bug ! ( "Unsupported target word size for int: {}" , tws) ,
26+ } ;
2327 let i8 = context. new_type :: < i8 > ( ) ;
2428 let i8p = i8. make_pointer ( ) ;
2529 let void = context. new_type :: < ( ) > ( ) ;
@@ -49,25 +53,43 @@ pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut GccContext, _module_nam
4953 } ;
5054 let name = global_fn_name ( method. name ) ;
5155
52- let args: Vec < _ > = types. iter ( ) . enumerate ( )
56+ let args: Vec < _ > = types
57+ . iter ( )
58+ . enumerate ( )
5359 . map ( |( index, typ) | context. new_parameter ( None , * typ, & format ! ( "param{}" , index) ) )
5460 . collect ( ) ;
55- let func = context. new_function ( None , FunctionType :: Exported , output. unwrap_or ( void) , & args, name, false ) ;
61+ let func = context. new_function (
62+ None ,
63+ FunctionType :: Exported ,
64+ output. unwrap_or ( void) ,
65+ & args,
66+ name,
67+ false ,
68+ ) ;
5669
5770 if tcx. sess . target . options . default_hidden_visibility {
58- #[ cfg( feature= "master" ) ]
71+ #[ cfg( feature = "master" ) ]
5972 func. add_attribute ( FnAttribute :: Visibility ( gccjit:: Visibility :: Hidden ) ) ;
6073 }
6174 if tcx. sess . must_emit_unwind_tables ( ) {
6275 // TODO(antoyo): emit unwind tables.
6376 }
6477
6578 let callee = default_fn_name ( method. name ) ;
66- let args: Vec < _ > = types. iter ( ) . enumerate ( )
79+ let args: Vec < _ > = types
80+ . iter ( )
81+ . enumerate ( )
6782 . map ( |( index, typ) | context. new_parameter ( None , * typ, & format ! ( "param{}" , index) ) )
6883 . collect ( ) ;
69- let callee = context. new_function ( None , FunctionType :: Extern , output. unwrap_or ( void) , & args, callee, false ) ;
70- #[ cfg( feature="master" ) ]
84+ let callee = context. new_function (
85+ None ,
86+ FunctionType :: Extern ,
87+ output. unwrap_or ( void) ,
88+ & args,
89+ callee,
90+ false ,
91+ ) ;
92+ #[ cfg( feature = "master" ) ]
7193 callee. add_attribute ( FnAttribute :: Visibility ( gccjit:: Visibility :: Hidden ) ) ;
7294
7395 let block = func. new_block ( "entry" ) ;
@@ -81,8 +103,7 @@ pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut GccContext, _module_nam
81103 //llvm::LLVMSetTailCall(ret, True);
82104 if output. is_some ( ) {
83105 block. end_with_return ( None , ret) ;
84- }
85- else {
106+ } else {
86107 block. end_with_void_return ( None ) ;
87108 }
88109
@@ -91,37 +112,6 @@ pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut GccContext, _module_nam
91112 }
92113 }
93114
94- let types = [ usize, usize] ;
95- let name = "__rust_alloc_error_handler" . to_string ( ) ;
96- let args: Vec < _ > = types. iter ( ) . enumerate ( )
97- . map ( |( index, typ) | context. new_parameter ( None , * typ, & format ! ( "param{}" , index) ) )
98- . collect ( ) ;
99- let func = context. new_function ( None , FunctionType :: Exported , void, & args, name, false ) ;
100-
101- if tcx. sess . target . default_hidden_visibility {
102- #[ cfg( feature="master" ) ]
103- func. add_attribute ( FnAttribute :: Visibility ( gccjit:: Visibility :: Hidden ) ) ;
104- }
105-
106- let callee = alloc_error_handler_name ( alloc_error_handler_kind) ;
107- let args: Vec < _ > = types. iter ( ) . enumerate ( )
108- . map ( |( index, typ) | context. new_parameter ( None , * typ, & format ! ( "param{}" , index) ) )
109- . collect ( ) ;
110- let callee = context. new_function ( None , FunctionType :: Extern , void, & args, callee, false ) ;
111- #[ cfg( feature="master" ) ]
112- callee. add_attribute ( FnAttribute :: Visibility ( gccjit:: Visibility :: Hidden ) ) ;
113-
114- let block = func. new_block ( "entry" ) ;
115-
116- let args = args
117- . iter ( )
118- . enumerate ( )
119- . map ( |( i, _) | func. get_param ( i as i32 ) . to_rvalue ( ) )
120- . collect :: < Vec < _ > > ( ) ;
121- let _ret = context. new_call ( None , callee, & args) ;
122- //llvm::LLVMSetTailCall(ret, True);
123- block. end_with_void_return ( None ) ;
124-
125115 let name = OomStrategy :: SYMBOL . to_string ( ) ;
126116 let global = context. new_global ( None , GlobalKind :: Exported , i8, name) ;
127117 let value = tcx. sess . opts . unstable_opts . oom . should_panic ( ) ;
0 commit comments