@@ -31,9 +31,9 @@ use crate::base::codegen_unwind_terminate;
3131use crate :: debuginfo:: EXCEPTION_HANDLER_CLEANUP ;
3232use crate :: prelude:: * ;
3333
34- pub ( super ) struct ArgValue < ' tcx > {
35- pub ( super ) value : Option < CValue < ' tcx > > ,
36- pub ( super ) is_underaligned_pointee : bool ,
34+ struct ArgValue < ' tcx > {
35+ value : CValue < ' tcx > ,
36+ is_underaligned_pointee : bool ,
3737}
3838
3939fn clif_sig_from_fn_abi < ' tcx > (
@@ -248,9 +248,10 @@ pub(crate) fn codegen_fn_prelude<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, start_
248248 self :: returning:: codegen_return_param ( fx, & ssa_analyzed, & mut block_params_iter) ;
249249 assert_eq ! ( fx. local_map. push( ret_place) , RETURN_PLACE ) ;
250250
251+ // None means pass_mode == NoPass
251252 enum ArgKind < ' tcx > {
252- Normal ( ArgValue < ' tcx > ) ,
253- Spread ( Vec < ArgValue < ' tcx > > ) ,
253+ Normal ( Option < ArgValue < ' tcx > > ) ,
254+ Spread ( Vec < Option < ArgValue < ' tcx > > > ) ,
254255 }
255256
256257 // FIXME implement variadics in cranelift
@@ -284,20 +285,17 @@ pub(crate) fn codegen_fn_prelude<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, start_
284285 let mut params = Vec :: new ( ) ;
285286 for ( i, _arg_ty) in tupled_arg_tys. iter ( ) . enumerate ( ) {
286287 let arg_abi = arg_abis_iter. next ( ) . unwrap ( ) ;
287- params. push ( cvalue_for_param (
288- fx,
289- Some ( local) ,
290- Some ( i) ,
291- arg_abi,
292- & mut block_params_iter,
293- ) ) ;
288+ let param =
289+ cvalue_for_param ( fx, Some ( local) , Some ( i) , arg_abi, & mut block_params_iter) ;
290+ params. push ( param) ;
294291 }
295292
296293 ( local, ArgKind :: Spread ( params) , arg_ty)
297294 } else {
298295 let arg_abi = arg_abis_iter. next ( ) . unwrap ( ) ;
299- let arg = cvalue_for_param ( fx, Some ( local) , None , arg_abi, & mut block_params_iter) ;
300- ( local, ArgKind :: Normal ( arg) , arg_ty)
296+ let param =
297+ cvalue_for_param ( fx, Some ( local) , None , arg_abi, & mut block_params_iter) ;
298+ ( local, ArgKind :: Normal ( param) , arg_ty)
301299 }
302300 } )
303301 . collect :: < Vec < ( Local , ArgKind < ' tcx > , Ty < ' tcx > ) > > ( ) ;
@@ -306,12 +304,12 @@ pub(crate) fn codegen_fn_prelude<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, start_
306304 if fx. instance . def . requires_caller_location ( fx. tcx ) {
307305 // Store caller location for `#[track_caller]`.
308306 let arg_abi = arg_abis_iter. next ( ) . unwrap ( ) ;
309- let arg = cvalue_for_param ( fx, None , None , arg_abi, & mut block_params_iter) ;
307+ let param = cvalue_for_param ( fx, None , None , arg_abi, & mut block_params_iter) . unwrap ( ) ;
310308 assert ! (
311- !arg . is_underaligned_pointee,
309+ !param . is_underaligned_pointee,
312310 "caller location argument should not be underaligned" ,
313311 ) ;
314- fx. caller_location = Some ( arg . value . unwrap ( ) ) ;
312+ fx. caller_location = Some ( param . value ) ;
315313 }
316314
317315 assert_eq ! ( arg_abis_iter. next( ) , None , "ArgAbi left behind for {:?}" , fx. fn_abi) ;
@@ -322,7 +320,7 @@ pub(crate) fn codegen_fn_prelude<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, start_
322320 for ( local, arg_kind, ty) in func_params {
323321 // While this is normally an optimization to prevent an unnecessary copy when an argument is
324322 // not mutated by the current function, this is necessary to support unsized arguments.
325- if let ArgKind :: Normal ( ArgValue { value : Some ( val) , is_underaligned_pointee : false } ) =
323+ if let ArgKind :: Normal ( Some ( ArgValue { value : val, is_underaligned_pointee : false } ) ) =
326324 arg_kind
327325 {
328326 if let Some ( ( addr, meta) ) = val. try_to_ptr ( ) {
@@ -349,24 +347,23 @@ pub(crate) fn codegen_fn_prelude<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, start_
349347 assert_eq ! ( fx. local_map. push( place) , local) ;
350348
351349 match arg_kind {
352- ArgKind :: Normal ( ArgValue { value : Some ( param) , is_underaligned_pointee } ) => {
353- if is_underaligned_pointee {
354- place. write_cvalue_transmute ( fx, param) ;
355- } else {
356- place. write_cvalue ( fx, param) ;
350+ ArgKind :: Normal ( param) => {
351+ if let Some ( param) = param {
352+ if param. is_underaligned_pointee {
353+ place. write_cvalue_transmute ( fx, param. value ) ;
354+ } else {
355+ place. write_cvalue ( fx, param. value ) ;
356+ }
357357 }
358358 }
359- ArgKind :: Normal ( ArgValue { value : None , is_underaligned_pointee : _ } ) => { }
360359 ArgKind :: Spread ( params) => {
361- for ( i, ArgValue { value : param, is_underaligned_pointee } ) in
362- params. into_iter ( ) . enumerate ( )
363- {
360+ for ( i, param) in params. into_iter ( ) . enumerate ( ) {
364361 if let Some ( param) = param {
365362 let field_place = place. place_field ( fx, FieldIdx :: new ( i) ) ;
366- if is_underaligned_pointee {
367- field_place. write_cvalue_transmute ( fx, param) ;
363+ if param . is_underaligned_pointee {
364+ field_place. write_cvalue_transmute ( fx, param. value ) ;
368365 } else {
369- field_place. write_cvalue ( fx, param) ;
366+ field_place. write_cvalue ( fx, param. value ) ;
370367 }
371368 }
372369 }
0 commit comments