@@ -3,8 +3,8 @@ mod comments;
3
3
mod pass_mode;
4
4
mod returning;
5
5
6
- use rustc_target:: spec:: abi:: Abi ;
7
6
use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrFlags ;
7
+ use rustc_target:: spec:: abi:: Abi ;
8
8
9
9
use cranelift_codegen:: ir:: { AbiParam , ArgumentPurpose } ;
10
10
@@ -14,6 +14,7 @@ use crate::prelude::*;
14
14
pub ( crate ) use self :: returning:: { can_return_to_ssa_var, codegen_return} ;
15
15
16
16
// Copied from https://github.com/rust-lang/rust/blob/f52c72948aa1dd718cc1f168d21c91c584c0a662/src/librustc_middle/ty/layout.rs#L2301
17
+ #[ rustfmt:: skip]
17
18
pub ( crate ) fn fn_sig_for_fn_abi < ' tcx > ( tcx : TyCtxt < ' tcx > , instance : Instance < ' tcx > ) -> ty:: PolyFnSig < ' tcx > {
18
19
use rustc_middle:: ty:: subst:: Subst ;
19
20
@@ -102,8 +103,16 @@ fn clif_sig_from_fn_sig<'tcx>(
102
103
abi => abi,
103
104
} ;
104
105
let ( call_conv, inputs, output) : ( CallConv , Vec < Ty < ' tcx > > , Ty < ' tcx > ) = match abi {
105
- Abi :: Rust => ( CallConv :: triple_default ( triple) , sig. inputs ( ) . to_vec ( ) , sig. output ( ) ) ,
106
- Abi :: C | Abi :: Unadjusted => ( CallConv :: triple_default ( triple) , sig. inputs ( ) . to_vec ( ) , sig. output ( ) ) ,
106
+ Abi :: Rust => (
107
+ CallConv :: triple_default ( triple) ,
108
+ sig. inputs ( ) . to_vec ( ) ,
109
+ sig. output ( ) ,
110
+ ) ,
111
+ Abi :: C | Abi :: Unadjusted => (
112
+ CallConv :: triple_default ( triple) ,
113
+ sig. inputs ( ) . to_vec ( ) ,
114
+ sig. output ( ) ,
115
+ ) ,
107
116
Abi :: SysV64 => ( CallConv :: SystemV , sig. inputs ( ) . to_vec ( ) , sig. output ( ) ) ,
108
117
Abi :: RustCall => {
109
118
assert_eq ! ( sig. inputs( ) . len( ) , 2 ) ;
@@ -116,7 +125,11 @@ fn clif_sig_from_fn_sig<'tcx>(
116
125
( CallConv :: triple_default ( triple) , inputs, sig. output ( ) )
117
126
}
118
127
Abi :: System => unreachable ! ( ) ,
119
- Abi :: RustIntrinsic => ( CallConv :: triple_default ( triple) , sig. inputs ( ) . to_vec ( ) , sig. output ( ) ) ,
128
+ Abi :: RustIntrinsic => (
129
+ CallConv :: triple_default ( triple) ,
130
+ sig. inputs ( ) . to_vec ( ) ,
131
+ sig. output ( ) ,
132
+ ) ,
120
133
_ => unimplemented ! ( "unsupported abi {:?}" , sig. abi) ,
121
134
} ;
122
135
@@ -163,10 +176,7 @@ fn clif_sig_from_fn_sig<'tcx>(
163
176
tcx. layout_of ( ParamEnv :: reveal_all ( ) . and ( output) ) . unwrap ( ) ,
164
177
) {
165
178
PassMode :: NoPass => ( inputs. collect ( ) , vec ! [ ] ) ,
166
- PassMode :: ByVal ( ret_ty) => (
167
- inputs. collect ( ) ,
168
- vec ! [ AbiParam :: new( ret_ty) ] ,
169
- ) ,
179
+ PassMode :: ByVal ( ret_ty) => ( inputs. collect ( ) , vec ! [ AbiParam :: new( ret_ty) ] ) ,
170
180
PassMode :: ByValPair ( ret_ty_a, ret_ty_b) => (
171
181
inputs. collect ( ) ,
172
182
vec ! [ AbiParam :: new( ret_ty_a) , AbiParam :: new( ret_ty_b) ] ,
@@ -202,12 +212,24 @@ pub(crate) fn get_function_name_and_sig<'tcx>(
202
212
support_vararg : bool ,
203
213
) -> ( String , Signature ) {
204
214
assert ! ( !inst. substs. needs_infer( ) ) ;
205
- let fn_sig =
206
- tcx. normalize_erasing_late_bound_regions ( ParamEnv :: reveal_all ( ) , & fn_sig_for_fn_abi ( tcx, inst) ) ;
215
+ let fn_sig = tcx. normalize_erasing_late_bound_regions (
216
+ ParamEnv :: reveal_all ( ) ,
217
+ & fn_sig_for_fn_abi ( tcx, inst) ,
218
+ ) ;
207
219
if fn_sig. c_variadic && !support_vararg {
208
- tcx. sess . span_fatal ( tcx. def_span ( inst. def_id ( ) ) , "Variadic function definitions are not yet supported" ) ;
220
+ tcx. sess . span_fatal (
221
+ tcx. def_span ( inst. def_id ( ) ) ,
222
+ "Variadic function definitions are not yet supported" ,
223
+ ) ;
209
224
}
210
- let sig = clif_sig_from_fn_sig ( tcx, triple, fn_sig, tcx. def_span ( inst. def_id ( ) ) , false , inst. def . requires_caller_location ( tcx) ) ;
225
+ let sig = clif_sig_from_fn_sig (
226
+ tcx,
227
+ triple,
228
+ fn_sig,
229
+ tcx. def_span ( inst. def_id ( ) ) ,
230
+ false ,
231
+ inst. def . requires_caller_location ( tcx) ,
232
+ ) ;
211
233
( tcx. symbol_name ( inst) . name . to_string ( ) , sig)
212
234
}
213
235
@@ -228,7 +250,8 @@ impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
228
250
pub ( crate ) fn get_function_ref ( & mut self , inst : Instance < ' tcx > ) -> FuncRef {
229
251
let func_id = import_function ( self . tcx , & mut self . cx . module , inst) ;
230
252
let func_ref = self
231
- . cx . module
253
+ . cx
254
+ . module
232
255
. declare_func_in_func ( func_id, & mut self . bcx . func ) ;
233
256
234
257
#[ cfg( debug_assertions) ]
@@ -250,11 +273,13 @@ impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
250
273
call_conv : CallConv :: triple_default ( self . triple ( ) ) ,
251
274
} ;
252
275
let func_id = self
253
- . cx . module
276
+ . cx
277
+ . module
254
278
. declare_function ( & name, Linkage :: Import , & sig)
255
279
. unwrap ( ) ;
256
280
let func_ref = self
257
- . cx . module
281
+ . cx
282
+ . module
258
283
. declare_func_in_func ( func_id, & mut self . bcx . func ) ;
259
284
let call_inst = self . bcx . ins ( ) . call ( func_ref, args) ;
260
285
#[ cfg( debug_assertions) ]
@@ -376,7 +401,9 @@ pub(crate) fn codegen_fn_prelude<'tcx>(
376
401
assert ! ( fx. caller_location. is_none( ) ) ;
377
402
if fx. instance . def . requires_caller_location ( fx. tcx ) {
378
403
// Store caller location for `#[track_caller]`.
379
- fx. caller_location = Some ( cvalue_for_param ( fx, start_block, None , None , fx. tcx . caller_location_ty ( ) ) . unwrap ( ) ) ;
404
+ fx. caller_location = Some (
405
+ cvalue_for_param ( fx, start_block, None , None , fx. tcx . caller_location_ty ( ) ) . unwrap ( ) ,
406
+ ) ;
380
407
}
381
408
382
409
fx. bcx . switch_to_block ( start_block) ;
@@ -502,17 +529,20 @@ pub(crate) fn codegen_terminator_call<'tcx>(
502
529
fx. bcx . ins ( ) . jump ( ret_block, & [ ] ) ;
503
530
return ;
504
531
}
505
- _ => Some ( instance)
532
+ _ => Some ( instance) ,
506
533
}
507
534
} else {
508
535
None
509
536
} ;
510
537
511
- let is_cold =
512
- instance. map ( |inst|
513
- fx. tcx . codegen_fn_attrs ( inst. def_id ( ) )
514
- . flags . contains ( CodegenFnAttrFlags :: COLD ) )
515
- . unwrap_or ( false ) ;
538
+ let is_cold = instance
539
+ . map ( |inst| {
540
+ fx. tcx
541
+ . codegen_fn_attrs ( inst. def_id ( ) )
542
+ . flags
543
+ . contains ( CodegenFnAttrFlags :: COLD )
544
+ } )
545
+ . unwrap_or ( false ) ;
516
546
if is_cold {
517
547
fx. cold_blocks . insert ( current_block) ;
518
548
}
@@ -524,9 +554,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
524
554
let pack_arg = trans_operand ( fx, & args[ 1 ] ) ;
525
555
526
556
let tupled_arguments = match pack_arg. layout ( ) . ty . kind {
527
- ty:: Tuple ( ref tupled_arguments) => {
528
- tupled_arguments
529
- }
557
+ ty:: Tuple ( ref tupled_arguments) => tupled_arguments,
530
558
_ => bug ! ( "argument to function with \" rust-call\" ABI is not a tuple" ) ,
531
559
} ;
532
560
@@ -582,8 +610,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
582
610
let nop_inst = fx. bcx . ins ( ) . nop ( ) ;
583
611
fx. add_comment ( nop_inst, "indirect call" ) ;
584
612
}
585
- let func = trans_operand ( fx, func)
586
- . load_scalar ( fx) ;
613
+ let func = trans_operand ( fx, func) . load_scalar ( fx) ;
587
614
(
588
615
Some ( func) ,
589
616
args. get ( 0 )
@@ -608,7 +635,10 @@ pub(crate) fn codegen_terminator_call<'tcx>(
608
635
)
609
636
. collect :: < Vec < _ > > ( ) ;
610
637
611
- if instance. map ( |inst| inst. def . requires_caller_location ( fx. tcx ) ) . unwrap_or ( false ) {
638
+ if instance
639
+ . map ( |inst| inst. def . requires_caller_location ( fx. tcx ) )
640
+ . unwrap_or ( false )
641
+ {
612
642
// Pass the caller location for `#[track_caller]`.
613
643
let caller_location = fx. get_caller_location ( span) ;
614
644
call_args. extend ( adjust_arg_for_abi ( fx, caller_location) . into_iter ( ) ) ;
@@ -637,7 +667,10 @@ pub(crate) fn codegen_terminator_call<'tcx>(
637
667
// FIXME find a cleaner way to support varargs
638
668
if fn_sig. c_variadic {
639
669
if fn_sig. abi != Abi :: C {
640
- fx. tcx . sess . span_fatal ( span, & format ! ( "Variadic call for non-C abi {:?}" , fn_sig. abi) ) ;
670
+ fx. tcx . sess . span_fatal (
671
+ span,
672
+ & format ! ( "Variadic call for non-C abi {:?}" , fn_sig. abi) ,
673
+ ) ;
641
674
}
642
675
let sig_ref = fx. bcx . func . dfg . call_signature ( call_inst) . unwrap ( ) ;
643
676
let abi_params = call_args
@@ -646,7 +679,9 @@ pub(crate) fn codegen_terminator_call<'tcx>(
646
679
let ty = fx. bcx . func . dfg . value_type ( arg) ;
647
680
if !ty. is_int ( ) {
648
681
// FIXME set %al to upperbound on float args once floats are supported
649
- fx. tcx . sess . span_fatal ( span, & format ! ( "Non int ty {:?} for variadic call" , ty) ) ;
682
+ fx. tcx
683
+ . sess
684
+ . span_fatal ( span, & format ! ( "Non int ty {:?} for variadic call" , ty) ) ;
650
685
}
651
686
AbiParam :: new ( ty)
652
687
} )
@@ -700,13 +735,16 @@ pub(crate) fn codegen_drop<'tcx>(
700
735
_ => {
701
736
assert ! ( !matches!( drop_fn. def, InstanceDef :: Virtual ( _, _) ) ) ;
702
737
703
- let arg_value = drop_place. place_ref ( fx, fx. layout_of ( fx. tcx . mk_ref (
704
- & ty:: RegionKind :: ReErased ,
705
- TypeAndMut {
706
- ty,
707
- mutbl : crate :: rustc_hir:: Mutability :: Mut ,
708
- } ,
709
- ) ) ) ;
738
+ let arg_value = drop_place. place_ref (
739
+ fx,
740
+ fx. layout_of ( fx. tcx . mk_ref (
741
+ & ty:: RegionKind :: ReErased ,
742
+ TypeAndMut {
743
+ ty,
744
+ mutbl : crate :: rustc_hir:: Mutability :: Mut ,
745
+ } ,
746
+ ) ) ,
747
+ ) ;
710
748
let arg_value = adjust_arg_for_abi ( fx, arg_value) ;
711
749
712
750
let mut call_args: Vec < Value > = arg_value. into_iter ( ) . collect :: < Vec < _ > > ( ) ;
0 commit comments