Skip to content

Commit 3361e34

Browse files
committed
Don't return anything from codegen_with_call_return_arg
1 parent 83da1e0 commit 3361e34

File tree

2 files changed

+60
-63
lines changed

2 files changed

+60
-63
lines changed

src/abi/mod.rs

Lines changed: 56 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -424,66 +424,65 @@ pub(crate) fn codegen_terminator_call<'tcx>(
424424
};
425425

426426
let ret_place = destination.map(|(place, _)| place);
427-
let (call_inst, call_args) = self::returning::codegen_with_call_return_arg(
428-
fx,
429-
&fn_abi.ret,
430-
ret_place,
431-
|fx, return_ptr| {
432-
let regular_args_count = args.len();
433-
let mut call_args: Vec<Value> = return_ptr
434-
.into_iter()
435-
.chain(first_arg_override.into_iter())
436-
.chain(
437-
args.into_iter()
438-
.enumerate()
439-
.skip(if first_arg_override.is_some() { 1 } else { 0 })
440-
.map(|(i, arg)| adjust_arg_for_abi(fx, arg, &fn_abi.args[i]).into_iter())
441-
.flatten(),
442-
)
443-
.collect::<Vec<_>>();
444-
445-
if instance.map(|inst| inst.def.requires_caller_location(fx.tcx)).unwrap_or(false) {
446-
// Pass the caller location for `#[track_caller]`.
447-
let caller_location = fx.get_caller_location(span);
448-
call_args.extend(
449-
adjust_arg_for_abi(fx, caller_location, &fn_abi.args[regular_args_count])
450-
.into_iter(),
451-
);
452-
assert_eq!(fn_abi.args.len(), regular_args_count + 1);
453-
} else {
454-
assert_eq!(fn_abi.args.len(), regular_args_count);
455-
}
456-
457-
let call_inst = match func_ref {
458-
CallTarget::Direct(func_ref) => fx.bcx.ins().call(func_ref, &call_args),
459-
CallTarget::Indirect(sig, func_ptr) => {
460-
fx.bcx.ins().call_indirect(sig, func_ptr, &call_args)
461-
}
462-
};
427+
self::returning::codegen_with_call_return_arg(fx, &fn_abi.ret, ret_place, |fx, return_ptr| {
428+
let regular_args_count = args.len();
429+
let mut call_args: Vec<Value> = return_ptr
430+
.into_iter()
431+
.chain(first_arg_override.into_iter())
432+
.chain(
433+
args.into_iter()
434+
.enumerate()
435+
.skip(if first_arg_override.is_some() { 1 } else { 0 })
436+
.map(|(i, arg)| adjust_arg_for_abi(fx, arg, &fn_abi.args[i]).into_iter())
437+
.flatten(),
438+
)
439+
.collect::<Vec<_>>();
440+
441+
if instance.map(|inst| inst.def.requires_caller_location(fx.tcx)).unwrap_or(false) {
442+
// Pass the caller location for `#[track_caller]`.
443+
let caller_location = fx.get_caller_location(span);
444+
call_args.extend(
445+
adjust_arg_for_abi(fx, caller_location, &fn_abi.args[regular_args_count])
446+
.into_iter(),
447+
);
448+
assert_eq!(fn_abi.args.len(), regular_args_count + 1);
449+
} else {
450+
assert_eq!(fn_abi.args.len(), regular_args_count);
451+
}
463452

464-
(call_inst, call_args)
465-
},
466-
);
453+
let call_inst = match func_ref {
454+
CallTarget::Direct(func_ref) => fx.bcx.ins().call(func_ref, &call_args),
455+
CallTarget::Indirect(sig, func_ptr) => {
456+
fx.bcx.ins().call_indirect(sig, func_ptr, &call_args)
457+
}
458+
};
467459

468-
// FIXME find a cleaner way to support varargs
469-
if fn_sig.c_variadic {
470-
if !matches!(fn_sig.abi, Abi::C { .. }) {
471-
fx.tcx.sess.span_fatal(span, &format!("Variadic call for non-C abi {:?}", fn_sig.abi));
460+
// FIXME find a cleaner way to support varargs
461+
if fn_sig.c_variadic {
462+
if !matches!(fn_sig.abi, Abi::C { .. }) {
463+
fx.tcx
464+
.sess
465+
.span_fatal(span, &format!("Variadic call for non-C abi {:?}", fn_sig.abi));
466+
}
467+
let sig_ref = fx.bcx.func.dfg.call_signature(call_inst).unwrap();
468+
let abi_params = call_args
469+
.into_iter()
470+
.map(|arg| {
471+
let ty = fx.bcx.func.dfg.value_type(arg);
472+
if !ty.is_int() {
473+
// FIXME set %al to upperbound on float args once floats are supported
474+
fx.tcx
475+
.sess
476+
.span_fatal(span, &format!("Non int ty {:?} for variadic call", ty));
477+
}
478+
AbiParam::new(ty)
479+
})
480+
.collect::<Vec<AbiParam>>();
481+
fx.bcx.func.dfg.signatures[sig_ref].params = abi_params;
472482
}
473-
let sig_ref = fx.bcx.func.dfg.call_signature(call_inst).unwrap();
474-
let abi_params = call_args
475-
.into_iter()
476-
.map(|arg| {
477-
let ty = fx.bcx.func.dfg.value_type(arg);
478-
if !ty.is_int() {
479-
// FIXME set %al to upperbound on float args once floats are supported
480-
fx.tcx.sess.span_fatal(span, &format!("Non int ty {:?} for variadic call", ty));
481-
}
482-
AbiParam::new(ty)
483-
})
484-
.collect::<Vec<AbiParam>>();
485-
fx.bcx.func.dfg.signatures[sig_ref].params = abi_params;
486-
}
483+
484+
call_inst
485+
});
487486

488487
if let Some((_, dest)) = destination {
489488
let ret_block = fx.get_block(dest);

src/abi/returning.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ pub(super) fn codegen_return_param<'tcx>(
9999

100100
/// Invokes the closure with if necessary a value representing the return pointer. When the closure
101101
/// returns the call return value(s) if any are written to the correct place.
102-
pub(super) fn codegen_with_call_return_arg<'tcx, T>(
102+
pub(super) fn codegen_with_call_return_arg<'tcx>(
103103
fx: &mut FunctionCx<'_, '_, 'tcx>,
104104
ret_arg_abi: &ArgAbi<'tcx, Ty<'tcx>>,
105105
ret_place: Option<CPlace<'tcx>>,
106-
f: impl FnOnce(&mut FunctionCx<'_, '_, 'tcx>, Option<Value>) -> (Inst, T),
107-
) -> (Inst, T) {
106+
f: impl FnOnce(&mut FunctionCx<'_, '_, 'tcx>, Option<Value>) -> Inst,
107+
) {
108108
let return_ptr = match ret_arg_abi.mode {
109109
PassMode::Ignore => None,
110110
PassMode::Indirect { attrs: _, extra_attrs: None, on_stack: _ } => match ret_place {
@@ -117,7 +117,7 @@ pub(super) fn codegen_with_call_return_arg<'tcx, T>(
117117
PassMode::Direct(_) | PassMode::Pair(_, _) | PassMode::Cast(_) => None,
118118
};
119119

120-
let (call_inst, meta) = f(fx, return_ptr);
120+
let call_inst = f(fx, return_ptr);
121121

122122
match ret_arg_abi.mode {
123123
PassMode::Ignore => {}
@@ -155,8 +155,6 @@ pub(super) fn codegen_with_call_return_arg<'tcx, T>(
155155
unreachable!("unsized return value")
156156
}
157157
}
158-
159-
(call_inst, meta)
160158
}
161159

162160
/// Codegen a return instruction with the right return value(s) if any.

0 commit comments

Comments
 (0)