@@ -522,6 +522,37 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
522522 this. write_scalar ( res, dest) ?;
523523 }
524524
525+ "uninit" => {
526+ // Check fast path: we don't want to force an allocation in case the destination is a simple value,
527+ // but we also do not want to create a new allocation with 0s and then copy that over.
528+ // FIXME: We do not properly validate in case of ZSTs and when doing it in memory!
529+ // However, this only affects direct calls of the intrinsic; calls to the stable
530+ // functions wrapping them do get their validation.
531+ // FIXME: should we check alignment for ZSTs?
532+ use crate :: ScalarMaybeUndef ;
533+ if !dest. layout . is_zst ( ) {
534+ match dest. layout . abi {
535+ layout:: Abi :: Scalar ( ..) => {
536+ let x = ScalarMaybeUndef :: Undef ;
537+ this. write_immediate ( Immediate :: Scalar ( x) , dest) ?;
538+ }
539+ layout:: Abi :: ScalarPair ( ..) => {
540+ let x = ScalarMaybeUndef :: Undef ;
541+ this. write_immediate ( Immediate :: ScalarPair ( x, x) , dest) ?;
542+ }
543+ _ => {
544+ // Do it in memory
545+ let mplace = this. force_allocation ( dest) ?;
546+ assert ! ( mplace. meta. is_none( ) ) ;
547+ let ptr = mplace. ptr . to_ptr ( ) ?;
548+ this. memory_mut ( )
549+ . get_mut ( ptr. alloc_id ) ?
550+ . mark_definedness ( ptr, dest. layout . size , false ) ;
551+ }
552+ }
553+ }
554+ }
555+
525556 "write_bytes" => {
526557 let ty = substs. type_at ( 0 ) ;
527558 let ty_layout = this. layout_of ( ty) ?;
0 commit comments