@@ -288,6 +288,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> LayoutOf for &'a EvalContext<'a, 'm
288288 type Ty = Ty < ' tcx > ;
289289 type TyLayout = EvalResult < ' tcx , TyLayout < ' tcx > > ;
290290
291+ #[ inline]
291292 fn layout_of ( self , ty : Ty < ' tcx > ) -> Self :: TyLayout {
292293 self . tcx . layout_of ( self . param_env . and ( ty) )
293294 . 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
559560 // value we use for things that we know are initially dead.
560561 let dummy =
561562 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 ) ;
563564 // Now mark those locals as dead that we do not want to initialize
564565 match self . tcx . describe_def ( instance. def_id ( ) ) {
565566 // 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
572573 match stmt. kind {
573574 StorageLive ( local) |
574575 StorageDead ( local) => {
575- // Worst case we are overwriting a dummy, no deallocation needed
576- self . storage_dead ( local) ;
576+ locals[ local] = LocalValue :: Dead ;
577577 }
578578 _ => { }
579579 }
@@ -582,11 +582,20 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M
582582 } ,
583583 }
584584 // 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+ }
588595 }
589596 }
597+ // done
598+ self . frame_mut ( ) . locals = locals;
590599 }
591600
592601 if self . stack . len ( ) > self . stack_limit {
0 commit comments