Skip to content

Commit b12ebfc

Browse files
committed
Auto merge of #895 - RalfJung:uninit, r=oli-obk
Revert "uninit intrinsic is gone" This reverts commit fa290f1. Uninit is [being reinstated](rust-lang/rust#63343) because it breaks some broken code.
2 parents 9758d8f + 455531c commit b12ebfc

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Diff for: src/shims/intrinsics.rs

+31
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)