@@ -506,7 +506,7 @@ impl Inliner<'tcx> {
506
506
let return_block = destination. 1 ;
507
507
508
508
// Copy the arguments if needed.
509
- let args: Vec < _ > = self . make_call_args ( args, & callsite, caller_body) ;
509
+ let args: Vec < _ > = self . make_call_args ( args, & callsite, caller_body, return_block ) ;
510
510
511
511
let bb_len = caller_body. basic_blocks ( ) . len ( ) ;
512
512
let mut integrator = Integrator {
@@ -553,6 +553,7 @@ impl Inliner<'tcx> {
553
553
args : Vec < Operand < ' tcx > > ,
554
554
callsite : & CallSite < ' tcx > ,
555
555
caller_body : & mut Body < ' tcx > ,
556
+ return_block : BasicBlock ,
556
557
) -> Vec < Local > {
557
558
let tcx = self . tcx ;
558
559
@@ -581,8 +582,18 @@ impl Inliner<'tcx> {
581
582
// and the vector is `[closure_ref, tmp0, tmp1, tmp2]`.
582
583
if tcx. is_closure ( callsite. callee ) {
583
584
let mut args = args. into_iter ( ) ;
584
- let self_ = self . create_temp_if_necessary ( args. next ( ) . unwrap ( ) , callsite, caller_body) ;
585
- let tuple = self . create_temp_if_necessary ( args. next ( ) . unwrap ( ) , callsite, caller_body) ;
585
+ let self_ = self . create_temp_if_necessary (
586
+ args. next ( ) . unwrap ( ) ,
587
+ callsite,
588
+ caller_body,
589
+ return_block,
590
+ ) ;
591
+ let tuple = self . create_temp_if_necessary (
592
+ args. next ( ) . unwrap ( ) ,
593
+ callsite,
594
+ caller_body,
595
+ return_block,
596
+ ) ;
586
597
assert ! ( args. next( ) . is_none( ) ) ;
587
598
588
599
let tuple = Place :: from ( tuple) ;
@@ -602,13 +613,13 @@ impl Inliner<'tcx> {
602
613
Operand :: Move ( tcx. mk_place_field ( tuple, Field :: new ( i) , ty. expect_ty ( ) ) ) ;
603
614
604
615
// Spill to a local to make e.g., `tmp0`.
605
- self . create_temp_if_necessary ( tuple_field, callsite, caller_body)
616
+ self . create_temp_if_necessary ( tuple_field, callsite, caller_body, return_block )
606
617
} ) ;
607
618
608
619
closure_ref_arg. chain ( tuple_tmp_args) . collect ( )
609
620
} else {
610
621
args. into_iter ( )
611
- . map ( |a| self . create_temp_if_necessary ( a, callsite, caller_body) )
622
+ . map ( |a| self . create_temp_if_necessary ( a, callsite, caller_body, return_block ) )
612
623
. collect ( )
613
624
}
614
625
}
@@ -620,6 +631,7 @@ impl Inliner<'tcx> {
620
631
arg : Operand < ' tcx > ,
621
632
callsite : & CallSite < ' tcx > ,
622
633
caller_body : & mut Body < ' tcx > ,
634
+ return_block : BasicBlock ,
623
635
) -> Local {
624
636
// FIXME: Analysis of the usage of the arguments to avoid
625
637
// unnecessary temporaries.
@@ -642,11 +654,19 @@ impl Inliner<'tcx> {
642
654
let arg_tmp = LocalDecl :: new ( ty, callsite. location . span ) ;
643
655
let arg_tmp = caller_body. local_decls . push ( arg_tmp) ;
644
656
645
- let stmt = Statement {
657
+ caller_body[ callsite. bb ] . statements . push ( Statement {
658
+ source_info : callsite. location ,
659
+ kind : StatementKind :: StorageLive ( arg_tmp) ,
660
+ } ) ;
661
+ caller_body[ callsite. bb ] . statements . push ( Statement {
646
662
source_info : callsite. location ,
647
663
kind : StatementKind :: Assign ( box ( Place :: from ( arg_tmp) , arg) ) ,
648
- } ;
649
- caller_body[ callsite. bb ] . statements . push ( stmt) ;
664
+ } ) ;
665
+ caller_body[ return_block] . statements . insert (
666
+ 0 ,
667
+ Statement { source_info : callsite. location , kind : StatementKind :: StorageDead ( arg_tmp) } ,
668
+ ) ;
669
+
650
670
arg_tmp
651
671
}
652
672
}
0 commit comments