@@ -494,7 +494,7 @@ impl Inliner<'tcx> {
494
494
let return_block = destination. 1 ;
495
495
496
496
// Copy the arguments if needed.
497
- let args: Vec < _ > = self . make_call_args ( args, & callsite, caller_body) ;
497
+ let args: Vec < _ > = self . make_call_args ( args, & callsite, caller_body, return_block ) ;
498
498
499
499
let bb_len = caller_body. basic_blocks ( ) . len ( ) ;
500
500
let mut integrator = Integrator {
@@ -541,6 +541,7 @@ impl Inliner<'tcx> {
541
541
args : Vec < Operand < ' tcx > > ,
542
542
callsite : & CallSite < ' tcx > ,
543
543
caller_body : & mut Body < ' tcx > ,
544
+ return_block : BasicBlock ,
544
545
) -> Vec < Local > {
545
546
let tcx = self . tcx ;
546
547
@@ -569,8 +570,18 @@ impl Inliner<'tcx> {
569
570
// and the vector is `[closure_ref, tmp0, tmp1, tmp2]`.
570
571
if tcx. is_closure ( callsite. callee ) {
571
572
let mut args = args. into_iter ( ) ;
572
- let self_ = self . create_temp_if_necessary ( args. next ( ) . unwrap ( ) , callsite, caller_body) ;
573
- let tuple = self . create_temp_if_necessary ( args. next ( ) . unwrap ( ) , callsite, caller_body) ;
573
+ let self_ = self . create_temp_if_necessary (
574
+ args. next ( ) . unwrap ( ) ,
575
+ callsite,
576
+ caller_body,
577
+ return_block,
578
+ ) ;
579
+ let tuple = self . create_temp_if_necessary (
580
+ args. next ( ) . unwrap ( ) ,
581
+ callsite,
582
+ caller_body,
583
+ return_block,
584
+ ) ;
574
585
assert ! ( args. next( ) . is_none( ) ) ;
575
586
576
587
let tuple = Place :: from ( tuple) ;
@@ -590,13 +601,13 @@ impl Inliner<'tcx> {
590
601
Operand :: Move ( tcx. mk_place_field ( tuple, Field :: new ( i) , ty. expect_ty ( ) ) ) ;
591
602
592
603
// Spill to a local to make e.g., `tmp0`.
593
- self . create_temp_if_necessary ( tuple_field, callsite, caller_body)
604
+ self . create_temp_if_necessary ( tuple_field, callsite, caller_body, return_block )
594
605
} ) ;
595
606
596
607
closure_ref_arg. chain ( tuple_tmp_args) . collect ( )
597
608
} else {
598
609
args. into_iter ( )
599
- . map ( |a| self . create_temp_if_necessary ( a, callsite, caller_body) )
610
+ . map ( |a| self . create_temp_if_necessary ( a, callsite, caller_body, return_block ) )
600
611
. collect ( )
601
612
}
602
613
}
@@ -608,6 +619,7 @@ impl Inliner<'tcx> {
608
619
arg : Operand < ' tcx > ,
609
620
callsite : & CallSite < ' tcx > ,
610
621
caller_body : & mut Body < ' tcx > ,
622
+ return_block : BasicBlock ,
611
623
) -> Local {
612
624
// FIXME: Analysis of the usage of the arguments to avoid
613
625
// unnecessary temporaries.
@@ -630,11 +642,19 @@ impl Inliner<'tcx> {
630
642
let arg_tmp = LocalDecl :: new ( ty, callsite. location . span ) ;
631
643
let arg_tmp = caller_body. local_decls . push ( arg_tmp) ;
632
644
633
- let stmt = Statement {
645
+ caller_body[ callsite. bb ] . statements . push ( Statement {
646
+ source_info : callsite. location ,
647
+ kind : StatementKind :: StorageLive ( arg_tmp) ,
648
+ } ) ;
649
+ caller_body[ callsite. bb ] . statements . push ( Statement {
634
650
source_info : callsite. location ,
635
651
kind : StatementKind :: Assign ( box ( Place :: from ( arg_tmp) , arg) ) ,
636
- } ;
637
- caller_body[ callsite. bb ] . statements . push ( stmt) ;
652
+ } ) ;
653
+ caller_body[ return_block] . statements . insert (
654
+ 0 ,
655
+ Statement { source_info : callsite. location , kind : StatementKind :: StorageDead ( arg_tmp) } ,
656
+ ) ;
657
+
638
658
arg_tmp
639
659
}
640
660
}
0 commit comments