11//! Argument passing
22
3- use cranelift_codegen:: ir:: { ArgumentExtension , ArgumentPurpose } ;
3+ use cranelift_codegen:: ir:: ArgumentPurpose ;
44use rustc_abi:: { Reg , RegKind } ;
55use rustc_target:: callconv:: {
66 ArgAbi , ArgAttributes , ArgExtension as RustcArgExtension , CastTarget , PassMode ,
@@ -32,13 +32,12 @@ fn reg_to_abi_param(reg: Reg) -> AbiParam {
3232 AbiParam :: new ( clif_ty)
3333}
3434
35- fn apply_arg_attrs_to_abi_param ( mut param : AbiParam , arg_attrs : ArgAttributes ) -> AbiParam {
35+ fn apply_attrs_to_abi_param ( param : AbiParam , arg_attrs : ArgAttributes ) -> AbiParam {
3636 match arg_attrs. arg_ext {
37- RustcArgExtension :: None => { }
38- RustcArgExtension :: Zext => param. extension = ArgumentExtension :: Uext ,
39- RustcArgExtension :: Sext => param. extension = ArgumentExtension :: Sext ,
37+ RustcArgExtension :: None => param ,
38+ RustcArgExtension :: Zext => param. uext ( ) ,
39+ RustcArgExtension :: Sext => param. sext ( ) ,
4040 }
41- param
4241}
4342
4443fn cast_target_to_abi_params ( cast : & CastTarget ) -> SmallVec < [ AbiParam ; 2 ] > {
@@ -82,7 +81,7 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
8281 match self . mode {
8382 PassMode :: Ignore => smallvec ! [ ] ,
8483 PassMode :: Direct ( attrs) => match self . layout . backend_repr {
85- BackendRepr :: Scalar ( scalar) => smallvec ! [ apply_arg_attrs_to_abi_param (
84+ BackendRepr :: Scalar ( scalar) => smallvec ! [ apply_attrs_to_abi_param (
8685 AbiParam :: new( scalar_to_clif_type( tcx, scalar) ) ,
8786 attrs
8887 ) ] ,
@@ -97,8 +96,8 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
9796 let a = scalar_to_clif_type ( tcx, a) ;
9897 let b = scalar_to_clif_type ( tcx, b) ;
9998 smallvec ! [
100- apply_arg_attrs_to_abi_param ( AbiParam :: new( a) , attrs_a) ,
101- apply_arg_attrs_to_abi_param ( AbiParam :: new( b) , attrs_b) ,
99+ apply_attrs_to_abi_param ( AbiParam :: new( a) , attrs_a) ,
100+ apply_attrs_to_abi_param ( AbiParam :: new( b) , attrs_b) ,
102101 ]
103102 }
104103 _ => unreachable ! ( "{:?}" , self . layout. backend_repr) ,
@@ -112,19 +111,19 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
112111 // Abi requires aligning struct size to pointer size
113112 let size = self . layout . size . align_to ( tcx. data_layout . pointer_align . abi ) ;
114113 let size = u32:: try_from ( size. bytes ( ) ) . unwrap ( ) ;
115- smallvec ! [ apply_arg_attrs_to_abi_param (
114+ smallvec ! [ apply_attrs_to_abi_param (
116115 AbiParam :: special( pointer_ty( tcx) , ArgumentPurpose :: StructArgument ( size) , ) ,
117116 attrs
118117 ) ]
119118 } else {
120- smallvec ! [ apply_arg_attrs_to_abi_param ( AbiParam :: new( pointer_ty( tcx) ) , attrs) ]
119+ smallvec ! [ apply_attrs_to_abi_param ( AbiParam :: new( pointer_ty( tcx) ) , attrs) ]
121120 }
122121 }
123122 PassMode :: Indirect { attrs, meta_attrs : Some ( meta_attrs) , on_stack } => {
124123 assert ! ( !on_stack) ;
125124 smallvec ! [
126- apply_arg_attrs_to_abi_param ( AbiParam :: new( pointer_ty( tcx) ) , attrs) ,
127- apply_arg_attrs_to_abi_param ( AbiParam :: new( pointer_ty( tcx) ) , meta_attrs) ,
125+ apply_attrs_to_abi_param ( AbiParam :: new( pointer_ty( tcx) ) , attrs) ,
126+ apply_attrs_to_abi_param ( AbiParam :: new( pointer_ty( tcx) ) , meta_attrs) ,
128127 ]
129128 }
130129 }
@@ -133,30 +132,46 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
133132 fn get_abi_return ( & self , tcx : TyCtxt < ' tcx > ) -> ( Option < AbiParam > , Vec < AbiParam > ) {
134133 match self . mode {
135134 PassMode :: Ignore => ( None , vec ! [ ] ) ,
136- PassMode :: Direct ( _) => match self . layout . backend_repr {
137- BackendRepr :: Scalar ( scalar) => {
138- ( None , vec ! [ AbiParam :: new( scalar_to_clif_type( tcx, scalar) ) ] )
139- }
135+ PassMode :: Direct ( attrs) => match self . layout . backend_repr {
136+ BackendRepr :: Scalar ( scalar) => (
137+ None ,
138+ vec ! [ apply_attrs_to_abi_param(
139+ AbiParam :: new( scalar_to_clif_type( tcx, scalar) ) ,
140+ attrs,
141+ ) ] ,
142+ ) ,
140143 BackendRepr :: SimdVector { .. } => {
141144 let vector_ty = crate :: intrinsics:: clif_vector_type ( tcx, self . layout ) ;
142- ( None , vec ! [ AbiParam :: new( vector_ty) ] )
145+ ( None , vec ! [ apply_attrs_to_abi_param ( AbiParam :: new( vector_ty) , attrs ) ] )
143146 }
144147 _ => unreachable ! ( "{:?}" , self . layout. backend_repr) ,
145148 } ,
146- PassMode :: Pair ( _ , _ ) => match self . layout . backend_repr {
149+ PassMode :: Pair ( attrs_a , attrs_b ) => match self . layout . backend_repr {
147150 BackendRepr :: ScalarPair ( a, b) => {
148151 let a = scalar_to_clif_type ( tcx, a) ;
149152 let b = scalar_to_clif_type ( tcx, b) ;
150- ( None , vec ! [ AbiParam :: new( a) , AbiParam :: new( b) ] )
153+ (
154+ None ,
155+ vec ! [
156+ apply_attrs_to_abi_param( AbiParam :: new( a) , attrs_a) ,
157+ apply_attrs_to_abi_param( AbiParam :: new( b) , attrs_b) ,
158+ ] ,
159+ )
151160 }
152161 _ => unreachable ! ( "{:?}" , self . layout. backend_repr) ,
153162 } ,
154163 PassMode :: Cast { ref cast, .. } => {
155164 ( None , cast_target_to_abi_params ( cast) . into_iter ( ) . collect ( ) )
156165 }
157- PassMode :: Indirect { attrs : _ , meta_attrs : None , on_stack } => {
166+ PassMode :: Indirect { attrs, meta_attrs : None , on_stack } => {
158167 assert ! ( !on_stack) ;
159- ( Some ( AbiParam :: special ( pointer_ty ( tcx) , ArgumentPurpose :: StructReturn ) ) , vec ! [ ] )
168+ (
169+ Some ( apply_attrs_to_abi_param (
170+ AbiParam :: special ( pointer_ty ( tcx) , ArgumentPurpose :: StructReturn ) ,
171+ attrs,
172+ ) ) ,
173+ vec ! [ ] ,
174+ )
160175 }
161176 PassMode :: Indirect { attrs : _, meta_attrs : Some ( _) , on_stack : _ } => {
162177 unreachable ! ( "unsized return value" )
0 commit comments