@@ -288,6 +288,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> LayoutOf for &'a EvalContext<'a, 'm
288
288
type Ty = Ty < ' tcx > ;
289
289
type TyLayout = EvalResult < ' tcx , TyLayout < ' tcx > > ;
290
290
291
+ #[ inline]
291
292
fn layout_of ( self , ty : Ty < ' tcx > ) -> Self :: TyLayout {
292
293
self . tcx . layout_of ( self . param_env . and ( ty) )
293
294
. map_err ( |layout| EvalErrorKind :: Layout ( layout) . into ( ) )
@@ -559,7 +560,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
559
560
// value we use for things that we know are initially dead.
560
561
let dummy =
561
562
LocalValue :: Live ( Operand :: Immediate ( Value :: Scalar ( ScalarMaybeUndef :: Undef ) ) ) ;
562
- self . frame_mut ( ) . locals = IndexVec :: from_elem ( dummy, & mir. local_decls ) ;
563
+ let mut locals = IndexVec :: from_elem ( dummy, & mir. local_decls ) ;
563
564
// Now mark those locals as dead that we do not want to initialize
564
565
match self . tcx . describe_def ( instance. def_id ( ) ) {
565
566
// statics and constants don't have `Storage*` statements, no need to look for them
@@ -572,8 +573,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
572
573
match stmt. kind {
573
574
StorageLive ( local) |
574
575
StorageDead ( local) => {
575
- // Worst case we are overwriting a dummy, no deallocation needed
576
- self . storage_dead ( local) ;
576
+ locals[ local] = LocalValue :: Dead ;
577
577
}
578
578
_ => { }
579
579
}
@@ -582,11 +582,20 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
582
582
} ,
583
583
}
584
584
// Finally, properly initialize all those that still have the dummy value
585
- for local in mir. local_decls . indices ( ) {
586
- if self . frame ( ) . locals [ local] == dummy {
587
- self . storage_live ( local) ?;
585
+ for ( local, decl) in locals. iter_mut ( ) . zip ( mir. local_decls . iter ( ) ) {
586
+ match * local {
587
+ LocalValue :: Live ( _) => {
588
+ // This needs to be peoperly initialized.
589
+ let layout = self . layout_of ( self . monomorphize ( decl. ty , instance. substs ) ) ?;
590
+ * local = LocalValue :: Live ( self . uninit_operand ( layout) ?) ;
591
+ }
592
+ LocalValue :: Dead => {
593
+ // Nothing to do
594
+ }
588
595
}
589
596
}
597
+ // done
598
+ self . frame_mut ( ) . locals = locals;
590
599
}
591
600
592
601
if self . stack . len ( ) > self . stack_limit {
0 commit comments