From: Ralf Jung Date: Wed, 7 Aug 2019 08:24:27 +0000 (+0200) Subject: Revert "uninit intrinsic is gone" X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=455531c564b7c849eb505876a9810f98e2f9fca2;p=rust.git Revert "uninit intrinsic is gone" This reverts commit fa290f1a481b0f98ed1de06206e643af8e04acd5. Uninit is being reinstated because it breaks some broken code. --- diff --git a/src/shims/intrinsics.rs b/src/shims/intrinsics.rs index c96869c80ce..4e957f792b7 100644 --- a/src/shims/intrinsics.rs +++ b/src/shims/intrinsics.rs @@ -522,6 +522,37 @@ fn call_intrinsic( this.write_scalar(res, dest)?; } + "uninit" => { + // Check fast path: we don't want to force an allocation in case the destination is a simple value, + // but we also do not want to create a new allocation with 0s and then copy that over. + // FIXME: We do not properly validate in case of ZSTs and when doing it in memory! + // However, this only affects direct calls of the intrinsic; calls to the stable + // functions wrapping them do get their validation. + // FIXME: should we check alignment for ZSTs? + use crate::ScalarMaybeUndef; + if !dest.layout.is_zst() { + match dest.layout.abi { + layout::Abi::Scalar(..) => { + let x = ScalarMaybeUndef::Undef; + this.write_immediate(Immediate::Scalar(x), dest)?; + } + layout::Abi::ScalarPair(..) => { + let x = ScalarMaybeUndef::Undef; + this.write_immediate(Immediate::ScalarPair(x, x), dest)?; + } + _ => { + // Do it in memory + let mplace = this.force_allocation(dest)?; + assert!(mplace.meta.is_none()); + let ptr = mplace.ptr.to_ptr()?; + this.memory_mut() + .get_mut(ptr.alloc_id)? + .mark_definedness(ptr, dest.layout.size, false); + } + } + } + } + "write_bytes" => { let ty = substs.type_at(0); let ty_layout = this.layout_of(ty)?;