Skip to content

Commit 432635a

Browse files
committed
Create ret_dest as late as possible in all code paths
1 parent 55200e7 commit 432635a

File tree

1 file changed

+19
-13
lines changed
  • compiler/rustc_codegen_ssa/src/mir

1 file changed

+19
-13
lines changed

compiler/rustc_codegen_ssa/src/mir/block.rs

+19-13
Original file line numberDiff line numberDiff line change
@@ -817,23 +817,16 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
817817

818818
// The arguments we'll be passing. Plus one to account for outptr, if used.
819819
let arg_count = fn_abi.args.len() + fn_abi.ret.is_indirect() as usize;
820-
let mut llargs = Vec::with_capacity(arg_count);
821-
822-
// Prepare the return value destination
823-
let ret_dest = self.make_return_dest(
824-
bx,
825-
destination,
826-
&fn_abi.ret,
827-
&mut llargs,
828-
intrinsic.is_some(),
829-
target.is_some(),
830-
);
831820

832821
if intrinsic == Some(sym::caller_location) {
833822
return if let Some(target) = target {
834823
let location =
835824
self.get_caller_location(bx, mir::SourceInfo { span: fn_span, ..source_info });
836825

826+
let mut llargs = Vec::with_capacity(arg_count);
827+
let ret_dest =
828+
self.make_return_dest(bx, destination, &fn_abi.ret, &mut llargs, true, true);
829+
assert_eq!(llargs, []);
837830
if let ReturnDest::IndirectOperand(tmp, _) = ret_dest {
838831
location.val.store(bx, tmp);
839832
}
@@ -847,6 +840,15 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
847840
match intrinsic {
848841
None | Some(sym::drop_in_place) => {}
849842
Some(intrinsic) => {
843+
let mut llargs = Vec::with_capacity(1);
844+
let ret_dest = self.make_return_dest(
845+
bx,
846+
destination,
847+
&fn_abi.ret,
848+
&mut llargs,
849+
true,
850+
target.is_some(),
851+
);
850852
let dest = match ret_dest {
851853
_ if fn_abi.ret.is_indirect() => llargs[0],
852854
ReturnDest::Nothing => bx.const_undef(bx.type_ptr()),
@@ -902,6 +904,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
902904
}
903905
}
904906

907+
let mut llargs = Vec::with_capacity(arg_count);
908+
let destination = target.as_ref().map(|&target| {
909+
(self.make_return_dest(bx, destination, &fn_abi.ret, &mut llargs, false, true), target)
910+
});
911+
905912
// Split the rust-call tupled arguments off.
906913
let (first_args, untuple) = if abi == Abi::RustCall && !args.is_empty() {
907914
let (tup, args) = args.split_last().unwrap();
@@ -1042,14 +1049,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
10421049
(_, Some(llfn)) => llfn,
10431050
_ => span_bug!(span, "no instance or llfn for call"),
10441051
};
1045-
10461052
helper.do_call(
10471053
self,
10481054
bx,
10491055
fn_abi,
10501056
fn_ptr,
10511057
&llargs,
1052-
target.as_ref().map(|&target| (ret_dest, target)),
1058+
destination,
10531059
unwind,
10541060
&copied_constant_arguments,
10551061
mergeable_succ,

0 commit comments

Comments
 (0)