@@ -18,17 +18,16 @@ impl<'a, 'gcc, 'tcx> AbiBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
1818 fn get_param ( & mut self , index : usize ) -> Self :: Value {
1919 let func = self . current_func ( ) ;
2020 let param = func. get_param ( index as i32 ) ;
21- let on_stack =
22- if let Some ( on_stack_param_indices ) = self . on_stack_function_params . borrow ( ) . get ( & func) {
23- on_stack_param_indices . contains ( & index )
24- }
25- else {
26- false
27- } ;
21+ let on_stack = if let Some ( on_stack_param_indices ) =
22+ self . on_stack_function_params . borrow ( ) . get ( & func)
23+ {
24+ on_stack_param_indices . contains ( & index )
25+ } else {
26+ false
27+ } ;
2828 if on_stack {
2929 param. to_lvalue ( ) . get_address ( None )
30- }
31- else {
30+ } else {
3231 param. to_rvalue ( )
3332 }
3433 }
@@ -37,13 +36,14 @@ impl<'a, 'gcc, 'tcx> AbiBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
3736impl GccType for CastTarget {
3837 fn gcc_type < ' gcc > ( & self , cx : & CodegenCx < ' gcc , ' _ > ) -> Type < ' gcc > {
3938 let rest_gcc_unit = self . rest . unit . gcc_type ( cx) ;
40- let ( rest_count, rem_bytes) =
41- if self . rest . unit . size . bytes ( ) == 0 {
42- ( 0 , 0 )
43- }
44- else {
45- ( self . rest . total . bytes ( ) / self . rest . unit . size . bytes ( ) , self . rest . total . bytes ( ) % self . rest . unit . size . bytes ( ) )
46- } ;
39+ let ( rest_count, rem_bytes) = if self . rest . unit . size . bytes ( ) == 0 {
40+ ( 0 , 0 )
41+ } else {
42+ (
43+ self . rest . total . bytes ( ) / self . rest . unit . size . bytes ( ) ,
44+ self . rest . total . bytes ( ) % self . rest . unit . size . bytes ( ) ,
45+ )
46+ } ;
4747
4848 if self . prefix . iter ( ) . all ( |x| x. is_none ( ) ) {
4949 // Simplify to a single unit when there is no prefix and size <= unit size
@@ -61,9 +61,7 @@ impl GccType for CastTarget {
6161 let mut args: Vec < _ > = self
6262 . prefix
6363 . iter ( )
64- . flat_map ( |option_reg| {
65- option_reg. map ( |reg| reg. gcc_type ( cx) )
66- } )
64+ . flat_map ( |option_reg| option_reg. map ( |reg| reg. gcc_type ( cx) ) )
6765 . chain ( ( 0 ..rest_count) . map ( |_| rest_gcc_unit) )
6866 . collect ( ) ;
6967
@@ -86,12 +84,10 @@ impl GccType for Reg {
8684 fn gcc_type < ' gcc > ( & self , cx : & CodegenCx < ' gcc , ' _ > ) -> Type < ' gcc > {
8785 match self . kind {
8886 RegKind :: Integer => cx. type_ix ( self . size . bits ( ) ) ,
89- RegKind :: Float => {
90- match self . size . bits ( ) {
91- 32 => cx. type_f32 ( ) ,
92- 64 => cx. type_f64 ( ) ,
93- _ => bug ! ( "unsupported float: {:?}" , self ) ,
94- }
87+ RegKind :: Float => match self . size . bits ( ) {
88+ 32 => cx. type_f32 ( ) ,
89+ 64 => cx. type_f64 ( ) ,
90+ _ => bug ! ( "unsupported float: {:?}" , self ) ,
9591 } ,
9692 RegKind :: Vector => unimplemented ! ( ) , //cx.type_vector(cx.type_i8(), self.size.bytes()),
9793 }
@@ -119,19 +115,18 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
119115
120116 // This capacity calculation is approximate.
121117 let mut argument_tys = Vec :: with_capacity (
122- self . args . len ( ) + if let PassMode :: Indirect { .. } = self . ret . mode { 1 } else { 0 }
118+ self . args . len ( ) + if let PassMode :: Indirect { .. } = self . ret . mode { 1 } else { 0 } ,
123119 ) ;
124120
125- let return_type =
126- match self . ret . mode {
127- PassMode :: Ignore => cx. type_void ( ) ,
128- PassMode :: Direct ( _) | PassMode :: Pair ( ..) => self . ret . layout . immediate_gcc_type ( cx) ,
129- PassMode :: Cast { ref cast, .. } => cast. gcc_type ( cx) ,
130- PassMode :: Indirect { .. } => {
131- argument_tys. push ( cx. type_ptr_to ( self . ret . memory_ty ( cx) ) ) ;
132- cx. type_void ( )
133- }
134- } ;
121+ let return_type = match self . ret . mode {
122+ PassMode :: Ignore => cx. type_void ( ) ,
123+ PassMode :: Direct ( _) | PassMode :: Pair ( ..) => self . ret . layout . immediate_gcc_type ( cx) ,
124+ PassMode :: Cast { ref cast, .. } => cast. gcc_type ( cx) ,
125+ PassMode :: Indirect { .. } => {
126+ argument_tys. push ( cx. type_ptr_to ( self . ret . memory_ty ( cx) ) ) ;
127+ cx. type_void ( )
128+ }
129+ } ;
135130 #[ cfg( feature = "master" ) ]
136131 let mut non_null_args = Vec :: new ( ) ;
137132
@@ -149,17 +144,23 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
149144 ty
150145 } ;
151146 #[ cfg( not( feature = "master" ) ) ]
152- let apply_attrs = |ty : Type < ' gcc > , _attrs : & ArgAttributes , _arg_index : usize | {
153- ty
154- } ;
147+ let apply_attrs = |ty : Type < ' gcc > , _attrs : & ArgAttributes , _arg_index : usize | ty;
155148
156149 for arg in self . args . iter ( ) {
157150 let arg_ty = match arg. mode {
158151 PassMode :: Ignore => continue ,
159152 PassMode :: Pair ( a, b) => {
160153 let arg_pos = argument_tys. len ( ) ;
161- argument_tys. push ( apply_attrs ( arg. layout . scalar_pair_element_gcc_type ( cx, 0 ) , & a, arg_pos) ) ;
162- argument_tys. push ( apply_attrs ( arg. layout . scalar_pair_element_gcc_type ( cx, 1 ) , & b, arg_pos + 1 ) ) ;
154+ argument_tys. push ( apply_attrs (
155+ arg. layout . scalar_pair_element_gcc_type ( cx, 0 ) ,
156+ & a,
157+ arg_pos,
158+ ) ) ;
159+ argument_tys. push ( apply_attrs (
160+ arg. layout . scalar_pair_element_gcc_type ( cx, 1 ) ,
161+ & b,
162+ arg_pos + 1 ,
163+ ) ) ;
163164 continue ;
164165 }
165166 PassMode :: Cast { ref cast, pad_i32 } => {
@@ -174,14 +175,17 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
174175 // This is a "byval" argument, so we don't apply the `restrict` attribute on it.
175176 on_stack_param_indices. insert ( argument_tys. len ( ) ) ;
176177 arg. memory_ty ( cx)
177- } ,
178- PassMode :: Direct ( attrs) => apply_attrs ( arg. layout . immediate_gcc_type ( cx) , & attrs, argument_tys. len ( ) ) ,
178+ }
179+ PassMode :: Direct ( attrs) => {
180+ apply_attrs ( arg. layout . immediate_gcc_type ( cx) , & attrs, argument_tys. len ( ) )
181+ }
179182 PassMode :: Indirect { attrs, meta_attrs : None , on_stack : false } => {
180183 apply_attrs ( cx. type_ptr_to ( arg. memory_ty ( cx) ) , & attrs, argument_tys. len ( ) )
181184 }
182185 PassMode :: Indirect { attrs, meta_attrs : Some ( meta_attrs) , on_stack } => {
183186 assert ! ( !on_stack) ;
184- let ty = apply_attrs ( cx. type_ptr_to ( arg. memory_ty ( cx) ) , & attrs, argument_tys. len ( ) ) ;
187+ let ty =
188+ apply_attrs ( cx. type_ptr_to ( arg. memory_ty ( cx) ) , & attrs, argument_tys. len ( ) ) ;
185189 apply_attrs ( ty, & meta_attrs, argument_tys. len ( ) )
186190 }
187191 } ;
@@ -207,15 +211,14 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
207211
208212 fn ptr_to_gcc_type ( & self , cx : & CodegenCx < ' gcc , ' tcx > ) -> Type < ' gcc > {
209213 // FIXME(antoyo): Should we do something with `FnAbiGcc::fn_attributes`?
210- let FnAbiGcc {
211- return_type,
212- arguments_type,
213- is_c_variadic,
214+ let FnAbiGcc { return_type, arguments_type, is_c_variadic, on_stack_param_indices, .. } =
215+ self . gcc_type ( cx) ;
216+ let pointer_type =
217+ cx. context . new_function_pointer_type ( None , return_type, & arguments_type, is_c_variadic) ;
218+ cx. on_stack_params . borrow_mut ( ) . insert (
219+ pointer_type. dyncast_function_ptr_type ( ) . expect ( "function ptr type" ) ,
214220 on_stack_param_indices,
215- ..
216- } = self . gcc_type ( cx) ;
217- let pointer_type = cx. context . new_function_pointer_type ( None , return_type, & arguments_type, is_c_variadic) ;
218- cx. on_stack_params . borrow_mut ( ) . insert ( pointer_type. dyncast_function_ptr_type ( ) . expect ( "function ptr type" ) , on_stack_param_indices) ;
221+ ) ;
219222 pointer_type
220223 }
221224}
0 commit comments