@@ -6,9 +6,10 @@ mod pass_mode;
6
6
mod returning;
7
7
8
8
use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrFlags ;
9
+ use rustc_target:: abi:: call:: PassMode as RustcPassMode ;
9
10
use rustc_target:: spec:: abi:: Abi ;
10
11
11
- use cranelift_codegen:: ir:: { AbiParam , ArgumentPurpose } ;
12
+ use cranelift_codegen:: ir:: AbiParam ;
12
13
13
14
use self :: pass_mode:: * ;
14
15
use crate :: prelude:: * ;
@@ -96,7 +97,6 @@ fn clif_sig_from_fn_sig<'tcx>(
96
97
tcx : TyCtxt < ' tcx > ,
97
98
triple : & target_lexicon:: Triple ,
98
99
sig : FnSig < ' tcx > ,
99
- span : Span ,
100
100
is_vtable_fn : bool ,
101
101
requires_caller_location : bool ,
102
102
) -> Signature {
@@ -147,54 +147,26 @@ fn clif_sig_from_fn_sig<'tcx>(
147
147
. layout_of ( ParamEnv :: reveal_all ( ) . and ( tcx. mk_mut_ptr ( tcx. mk_unit ( ) ) ) )
148
148
. unwrap ( ) ;
149
149
}
150
- let pass_mode = get_pass_mode ( tcx, layout) ;
150
+ let mut arg_abi = get_arg_abi ( tcx, layout) ;
151
151
if abi != Abi :: Rust && abi != Abi :: RustCall && abi != Abi :: RustIntrinsic {
152
- match pass_mode {
153
- PassMode :: NoPass | PassMode :: ByVal ( _) => { }
154
- PassMode :: ByRef { size : Some ( size) } => {
155
- let purpose = ArgumentPurpose :: StructArgument ( u32:: try_from ( size. bytes ( ) ) . expect ( "struct too big to pass on stack" ) ) ;
156
- return EmptySinglePair :: Single ( AbiParam :: special ( pointer_ty ( tcx) , purpose) ) . into_iter ( ) ;
157
- }
158
- PassMode :: ByValPair ( _, _) | PassMode :: ByRef { size : None } => {
159
- tcx. sess . span_warn (
160
- span,
161
- & format ! (
162
- "Argument of type `{:?}` with pass mode `{:?}` is not yet supported \
163
- for non-rust abi `{}`. Calling this function may result in a crash.",
164
- layout. ty,
165
- pass_mode,
166
- abi,
167
- ) ,
168
- ) ;
169
- }
152
+ match arg_abi. mode {
153
+ RustcPassMode :: Indirect {
154
+ ref mut on_stack, ..
155
+ } => * on_stack = true ,
156
+ _ => { }
170
157
}
171
158
}
172
- pass_mode . get_param_ty ( tcx) . map ( AbiParam :: new ) . into_iter ( )
159
+ arg_abi . get_abi_param ( tcx) . into_iter ( )
173
160
} )
174
161
. flatten ( ) ;
175
162
176
- let ( mut params , returns ) : ( Vec < _ > , Vec < _ > ) = match get_pass_mode (
163
+ let return_arg_abi = get_arg_abi (
177
164
tcx,
178
165
tcx. layout_of ( ParamEnv :: reveal_all ( ) . and ( output) ) . unwrap ( ) ,
179
- ) {
180
- PassMode :: NoPass => ( inputs. collect ( ) , vec ! [ ] ) ,
181
- PassMode :: ByVal ( ret_ty) => ( inputs. collect ( ) , vec ! [ AbiParam :: new( ret_ty) ] ) ,
182
- PassMode :: ByValPair ( ret_ty_a, ret_ty_b) => (
183
- inputs. collect ( ) ,
184
- vec ! [ AbiParam :: new( ret_ty_a) , AbiParam :: new( ret_ty_b) ] ,
185
- ) ,
186
- PassMode :: ByRef { size : Some ( _) } => {
187
- (
188
- Some ( pointer_ty ( tcx) ) // First param is place to put return val
189
- . into_iter ( )
190
- . map ( |ty| AbiParam :: special ( ty, ArgumentPurpose :: StructReturn ) )
191
- . chain ( inputs)
192
- . collect ( ) ,
193
- vec ! [ ] ,
194
- )
195
- }
196
- PassMode :: ByRef { size : None } => todo ! ( ) ,
197
- } ;
166
+ ) ;
167
+ let ( return_ptr, returns) = return_arg_abi. get_abi_return ( tcx) ;
168
+ // Sometimes the first param is an pointer to the place where the return value needs to be stored.
169
+ let mut params: Vec < _ > = return_ptr. into_iter ( ) . chain ( inputs) . collect ( ) ;
198
170
199
171
if requires_caller_location {
200
172
params. push ( AbiParam :: new ( pointer_ty ( tcx) ) ) ;
@@ -226,7 +198,6 @@ pub(crate) fn get_function_name_and_sig<'tcx>(
226
198
tcx,
227
199
triple,
228
200
fn_sig,
229
- tcx. def_span ( inst. def_id ( ) ) ,
230
201
false ,
231
202
inst. def . requires_caller_location ( tcx) ,
232
203
) ;
@@ -584,7 +555,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
584
555
nop_inst,
585
556
format ! (
586
557
"virtual call; self arg pass mode: {:?}" ,
587
- get_pass_mode ( fx. tcx, args[ 0 ] . layout( ) )
558
+ get_arg_abi ( fx. tcx, args[ 0 ] . layout( ) ) . mode ,
588
559
) ,
589
560
) ;
590
561
}
@@ -647,7 +618,6 @@ pub(crate) fn codegen_terminator_call<'tcx>(
647
618
fx. tcx ,
648
619
fx. triple ( ) ,
649
620
fn_sig,
650
- span,
651
621
is_virtual_call,
652
622
false , // calls through function pointers never pass the caller location
653
623
) ;
@@ -723,7 +693,6 @@ pub(crate) fn codegen_drop<'tcx>(
723
693
fx. tcx ,
724
694
fx. triple ( ) ,
725
695
fn_sig,
726
- span,
727
696
true ,
728
697
false , // `drop_in_place` is never `#[track_caller]`
729
698
) ;
0 commit comments