@@ -522,6 +522,36 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
522
522
this. write_scalar ( res, dest) ?;
523
523
}
524
524
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
+ if !dest. layout . is_zst ( ) {
533
+ match dest. layout . abi {
534
+ layout:: Abi :: Scalar ( ..) => {
535
+ let x = ScalarMaybeUndef :: Undef ;
536
+ this. write_immediate ( Immediate :: Scalar ( x) , dest) ?;
537
+ }
538
+ layout:: Abi :: ScalarPair ( ..) => {
539
+ let x = ScalarMaybeUndef :: Undef ;
540
+ this. write_immediate ( Immediate :: ScalarPair ( x, x) , dest) ?;
541
+ }
542
+ _ => {
543
+ // Do it in memory
544
+ let mplace = this. force_allocation ( dest) ?;
545
+ assert ! ( mplace. meta. is_none( ) ) ;
546
+ let ptr = mplace. ptr . to_ptr ( ) ?;
547
+ this. memory_mut ( )
548
+ . get_mut ( ptr. alloc_id ) ?
549
+ . mark_definedness ( ptr, dest. layout . size , false ) ;
550
+ }
551
+ }
552
+ }
553
+ }
554
+
525
555
"write_bytes" => {
526
556
let ty = substs. type_at ( 0 ) ;
527
557
let ty_layout = this. layout_of ( ty) ?;
0 commit comments