@@ -56,23 +56,22 @@ pub(super) fn codegen_return_param<'tcx>(
56
56
pub ( super ) fn codegen_with_call_return_arg < ' tcx > (
57
57
fx : & mut FunctionCx < ' _ , ' _ , ' tcx > ,
58
58
ret_arg_abi : & ArgAbi < ' tcx , Ty < ' tcx > > ,
59
- ret_place : Option < CPlace < ' tcx > > ,
59
+ ret_place : CPlace < ' tcx > ,
60
60
f : impl FnOnce ( & mut FunctionCx < ' _ , ' _ , ' tcx > , Option < Value > ) -> Inst ,
61
61
) {
62
62
let ( ret_temp_place, return_ptr) = match ret_arg_abi. mode {
63
63
PassMode :: Ignore => ( None , None ) ,
64
- PassMode :: Indirect { attrs : _, extra_attrs : None , on_stack : _ } => match ret_place {
65
- Some ( ret_place ) if matches ! ( ret_place. inner( ) , CPlaceInner :: Addr ( _, None ) ) => {
64
+ PassMode :: Indirect { attrs : _, extra_attrs : None , on_stack : _ } => {
65
+ if matches ! ( ret_place. inner( ) , CPlaceInner :: Addr ( _, None ) ) {
66
66
// This is an optimization to prevent unnecessary copies of the return value when
67
67
// the return place is already a memory place as opposed to a register.
68
68
// This match arm can be safely removed.
69
69
( None , Some ( ret_place. to_ptr ( ) . get_addr ( fx) ) )
70
- }
71
- _ => {
70
+ } else {
72
71
let place = CPlace :: new_stack_slot ( fx, ret_arg_abi. layout ) ;
73
72
( Some ( place) , Some ( place. to_ptr ( ) . get_addr ( fx) ) )
74
73
}
75
- } ,
74
+ }
76
75
PassMode :: Indirect { attrs : _, extra_attrs : Some ( _) , on_stack : _ } => {
77
76
unreachable ! ( "unsized return value" )
78
77
}
@@ -84,39 +83,25 @@ pub(super) fn codegen_with_call_return_arg<'tcx>(
84
83
match ret_arg_abi. mode {
85
84
PassMode :: Ignore => { }
86
85
PassMode :: Direct ( _) => {
87
- if let Some ( ret_place) = ret_place {
88
- let ret_val = fx. bcx . inst_results ( call_inst) [ 0 ] ;
89
- ret_place. write_cvalue ( fx, CValue :: by_val ( ret_val, ret_arg_abi. layout ) ) ;
90
- }
86
+ let ret_val = fx. bcx . inst_results ( call_inst) [ 0 ] ;
87
+ ret_place. write_cvalue ( fx, CValue :: by_val ( ret_val, ret_arg_abi. layout ) ) ;
91
88
}
92
89
PassMode :: Pair ( _, _) => {
93
- if let Some ( ret_place) = ret_place {
94
- let ret_val_a = fx. bcx . inst_results ( call_inst) [ 0 ] ;
95
- let ret_val_b = fx. bcx . inst_results ( call_inst) [ 1 ] ;
96
- ret_place. write_cvalue (
97
- fx,
98
- CValue :: by_val_pair ( ret_val_a, ret_val_b, ret_arg_abi. layout ) ,
99
- ) ;
100
- }
90
+ let ret_val_a = fx. bcx . inst_results ( call_inst) [ 0 ] ;
91
+ let ret_val_b = fx. bcx . inst_results ( call_inst) [ 1 ] ;
92
+ ret_place
93
+ . write_cvalue ( fx, CValue :: by_val_pair ( ret_val_a, ret_val_b, ret_arg_abi. layout ) ) ;
101
94
}
102
95
PassMode :: Cast ( cast) => {
103
- if let Some ( ret_place) = ret_place {
104
- let results = fx
105
- . bcx
106
- . inst_results ( call_inst)
107
- . iter ( )
108
- . copied ( )
109
- . collect :: < SmallVec < [ Value ; 2 ] > > ( ) ;
110
- let result =
111
- super :: pass_mode:: from_casted_value ( fx, & results, ret_place. layout ( ) , cast) ;
112
- ret_place. write_cvalue ( fx, result) ;
113
- }
96
+ let results =
97
+ fx. bcx . inst_results ( call_inst) . iter ( ) . copied ( ) . collect :: < SmallVec < [ Value ; 2 ] > > ( ) ;
98
+ let result =
99
+ super :: pass_mode:: from_casted_value ( fx, & results, ret_place. layout ( ) , cast) ;
100
+ ret_place. write_cvalue ( fx, result) ;
114
101
}
115
102
PassMode :: Indirect { attrs : _, extra_attrs : None , on_stack : _ } => {
116
- if let ( Some ( ret_place) , Some ( ret_temp_place) ) = ( ret_place, ret_temp_place) {
117
- // Both ret_place and ret_temp_place must be Some. If ret_place is None, this is
118
- // a non-returning call. If ret_temp_place is None, it is not necessary to copy the
119
- // return value.
103
+ if let Some ( ret_temp_place) = ret_temp_place {
104
+ // If ret_temp_place is None, it is not necessary to copy the return value.
120
105
let ret_temp_value = ret_temp_place. to_cvalue ( fx) ;
121
106
ret_place. write_cvalue ( fx, ret_temp_value) ;
122
107
}
0 commit comments