@@ -18,17 +18,16 @@ impl<'a, 'gcc, 'tcx> AbiBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
18
18
fn get_param ( & mut self , index : usize ) -> Self :: Value {
19
19
let func = self . current_func ( ) ;
20
20
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
+ } ;
28
28
if on_stack {
29
29
param. to_lvalue ( ) . get_address ( None )
30
- }
31
- else {
30
+ } else {
32
31
param. to_rvalue ( )
33
32
}
34
33
}
@@ -37,13 +36,14 @@ impl<'a, 'gcc, 'tcx> AbiBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
37
36
impl GccType for CastTarget {
38
37
fn gcc_type < ' gcc > ( & self , cx : & CodegenCx < ' gcc , ' _ > ) -> Type < ' gcc > {
39
38
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
+ } ;
47
47
48
48
if self . prefix . iter ( ) . all ( |x| x. is_none ( ) ) {
49
49
// Simplify to a single unit when there is no prefix and size <= unit size
@@ -61,9 +61,7 @@ impl GccType for CastTarget {
61
61
let mut args: Vec < _ > = self
62
62
. prefix
63
63
. 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) ) )
67
65
. chain ( ( 0 ..rest_count) . map ( |_| rest_gcc_unit) )
68
66
. collect ( ) ;
69
67
@@ -86,12 +84,10 @@ impl GccType for Reg {
86
84
fn gcc_type < ' gcc > ( & self , cx : & CodegenCx < ' gcc , ' _ > ) -> Type < ' gcc > {
87
85
match self . kind {
88
86
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 ) ,
95
91
} ,
96
92
RegKind :: Vector => unimplemented ! ( ) , //cx.type_vector(cx.type_i8(), self.size.bytes()),
97
93
}
@@ -119,19 +115,18 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
119
115
120
116
// This capacity calculation is approximate.
121
117
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 } ,
123
119
) ;
124
120
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
+ } ;
135
130
#[ cfg( feature = "master" ) ]
136
131
let mut non_null_args = Vec :: new ( ) ;
137
132
@@ -149,17 +144,23 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
149
144
ty
150
145
} ;
151
146
#[ 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;
155
148
156
149
for arg in self . args . iter ( ) {
157
150
let arg_ty = match arg. mode {
158
151
PassMode :: Ignore => continue ,
159
152
PassMode :: Pair ( a, b) => {
160
153
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
+ ) ) ;
163
164
continue ;
164
165
}
165
166
PassMode :: Cast { ref cast, pad_i32 } => {
@@ -174,14 +175,17 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
174
175
// This is a "byval" argument, so we don't apply the `restrict` attribute on it.
175
176
on_stack_param_indices. insert ( argument_tys. len ( ) ) ;
176
177
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
+ }
179
182
PassMode :: Indirect { attrs, meta_attrs : None , on_stack : false } => {
180
183
apply_attrs ( cx. type_ptr_to ( arg. memory_ty ( cx) ) , & attrs, argument_tys. len ( ) )
181
184
}
182
185
PassMode :: Indirect { attrs, meta_attrs : Some ( meta_attrs) , on_stack } => {
183
186
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 ( ) ) ;
185
189
apply_attrs ( ty, & meta_attrs, argument_tys. len ( ) )
186
190
}
187
191
} ;
@@ -207,15 +211,14 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
207
211
208
212
fn ptr_to_gcc_type ( & self , cx : & CodegenCx < ' gcc , ' tcx > ) -> Type < ' gcc > {
209
213
// 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" ) ,
214
220
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
+ ) ;
219
222
pointer_type
220
223
}
221
224
}
0 commit comments