1
- use gccjit:: { Context , FunctionType , GlobalKind , ToRValue , Type } ;
2
1
#[ cfg( feature = "master" ) ]
3
- use gccjit:: { FnAttribute , VarAttribute } ;
2
+ use gccjit:: FnAttribute ;
3
+ use gccjit:: { Context , FunctionType , RValue , ToRValue , Type } ;
4
4
use rustc_ast:: expand:: allocator:: {
5
5
ALLOCATOR_METHODS , AllocatorKind , AllocatorTy , NO_ALLOC_SHIM_IS_UNSTABLE ,
6
6
alloc_error_handler_name, default_fn_name, global_fn_name,
@@ -71,15 +71,13 @@ pub(crate) unsafe fn codegen(
71
71
None ,
72
72
) ;
73
73
74
- let name = mangle_internal_symbol ( tcx, OomStrategy :: SYMBOL ) ;
75
- let global = context. new_global ( None , GlobalKind :: Exported , i8, name) ;
76
- #[ cfg( feature = "master" ) ]
77
- global. add_attribute ( VarAttribute :: Visibility ( symbol_visibility_to_gcc (
78
- tcx. sess . default_visibility ( ) ,
79
- ) ) ) ;
80
- let value = tcx. sess . opts . unstable_opts . oom . should_panic ( ) ;
81
- let value = context. new_rvalue_from_int ( i8, value as i32 ) ;
82
- global. global_set_initializer_rvalue ( value) ;
74
+ create_const_value_function (
75
+ tcx,
76
+ context,
77
+ & mangle_internal_symbol ( tcx, OomStrategy :: SYMBOL ) ,
78
+ i8,
79
+ context. new_rvalue_from_int ( i8, tcx. sess . opts . unstable_opts . oom . should_panic ( ) as i32 ) ,
80
+ ) ;
83
81
84
82
create_wrapper_function (
85
83
tcx,
@@ -91,6 +89,30 @@ pub(crate) unsafe fn codegen(
91
89
) ;
92
90
}
93
91
92
+ fn create_const_value_function (
93
+ tcx : TyCtxt < ' _ > ,
94
+ context : & Context < ' _ > ,
95
+ name : & str ,
96
+ output : Type < ' _ > ,
97
+ value : RValue < ' _ > ,
98
+ ) {
99
+ let func = context. new_function ( None , FunctionType :: Exported , output, & [ ] , name, false ) ;
100
+
101
+ #[ cfg( feature = "master" ) ]
102
+ func. add_attribute ( FnAttribute :: Visibility ( symbol_visibility_to_gcc (
103
+ tcx. sess . default_visibility ( ) ,
104
+ ) ) ) ;
105
+
106
+ func. add_attribute ( FnAttribute :: AlwaysInline ) ;
107
+
108
+ if tcx. sess . must_emit_unwind_tables ( ) {
109
+ // TODO(antoyo): emit unwind tables.
110
+ }
111
+
112
+ let block = func. new_block ( "entry" ) ;
113
+ block. end_with_return ( None , value) ;
114
+ }
115
+
94
116
fn create_wrapper_function (
95
117
tcx : TyCtxt < ' _ > ,
96
118
context : & Context < ' _ > ,
0 commit comments