From cd4b1233ee22d684b1cd71130d874dcbeebaecbb Mon Sep 17 00:00:00 2001 From: Hanif Bin Ariffin Date: Wed, 22 Apr 2020 03:20:40 -0400 Subject: [PATCH] Renamed "undef" -> "uninit" 1. InvalidUndefBytes -> InvalidUninitBytes 2. ScalarMaybeUndef -> ScalarMaybeUninit 3. UndefMask -> UninitMask Resolves #71193 --- .../mir/interpret/allocation.rs | 40 +++++++++---------- src/librustc_middle/mir/interpret/error.rs | 10 ++--- src/librustc_middle/mir/interpret/mod.rs | 4 +- src/librustc_middle/mir/interpret/value.rs | 34 ++++++++-------- src/librustc_mir/const_eval/eval_queries.rs | 8 ++-- src/librustc_mir/interpret/eval_context.rs | 8 ++-- src/librustc_mir/interpret/operand.rs | 22 +++++----- src/librustc_mir/interpret/place.rs | 10 ++--- src/librustc_mir/interpret/validity.rs | 2 +- src/librustc_mir/transform/const_prop.rs | 20 +++++----- 10 files changed, 79 insertions(+), 79 deletions(-) diff --git a/src/librustc_middle/mir/interpret/allocation.rs b/src/librustc_middle/mir/interpret/allocation.rs index 8b9f09774853a..fcf015d35b3fc 100644 --- a/src/librustc_middle/mir/interpret/allocation.rs +++ b/src/librustc_middle/mir/interpret/allocation.rs @@ -10,7 +10,7 @@ use rustc_data_structures::sorted_map::SortedMap; use rustc_target::abi::{Align, HasDataLayout, Size}; use super::{ - read_target_uint, write_target_uint, AllocId, InterpResult, Pointer, Scalar, ScalarMaybeUndef, + read_target_uint, write_target_uint, AllocId, InterpResult, Pointer, Scalar, ScalarMaybeUninit, }; // NOTE: When adding new fields, make sure to adjust the `Snapshot` impl in @@ -27,7 +27,7 @@ pub struct Allocation { /// at the given offset. relocations: Relocations, /// Denotes which part of this allocation is initialized. - undef_mask: UndefMask, + undef_mask: UninitMask, /// The size of the allocation. Currently, must always equal `bytes.len()`. pub size: Size, /// The alignment of the allocation to detect unaligned reads. @@ -94,7 +94,7 @@ impl Allocation { Self { bytes, relocations: Relocations::new(), - undef_mask: UndefMask::new(size, true), + undef_mask: UninitMask::new(size, true), size, align, mutability: Mutability::Not, @@ -110,7 +110,7 @@ impl Allocation { Allocation { bytes: vec![0; size.bytes_usize()], relocations: Relocations::new(), - undef_mask: UndefMask::new(size, false), + undef_mask: UninitMask::new(size, false), size, align, mutability: Mutability::Mut, @@ -163,7 +163,7 @@ impl Allocation { } /// Returns the undef mask. - pub fn undef_mask(&self) -> &UndefMask { + pub fn undef_mask(&self) -> &UninitMask { &self.undef_mask } @@ -360,7 +360,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra> Allocation { cx: &impl HasDataLayout, ptr: Pointer, size: Size, - ) -> InterpResult<'tcx, ScalarMaybeUndef> { + ) -> InterpResult<'tcx, ScalarMaybeUninit> { // `get_bytes_unchecked` tests relocation edges. let bytes = self.get_bytes_with_undef_and_ptr(cx, ptr, size)?; // Undef check happens *after* we established that the alignment is correct. @@ -368,7 +368,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra> Allocation { if self.is_defined(ptr, size).is_err() { // This inflates undefined bytes to the entire scalar, even if only a few // bytes are undefined. - return Ok(ScalarMaybeUndef::Undef); + return Ok(ScalarMaybeUninit::Undef); } // Now we do the actual reading. let bits = read_target_uint(cx.data_layout().endian, bytes).unwrap(); @@ -379,11 +379,11 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra> Allocation { } else { if let Some(&(tag, alloc_id)) = self.relocations.get(&ptr.offset) { let ptr = Pointer::new_with_tag(alloc_id, Size::from_bytes(bits), tag); - return Ok(ScalarMaybeUndef::Scalar(ptr.into())); + return Ok(ScalarMaybeUninit::Scalar(ptr.into())); } } // We don't. Just return the bits. - Ok(ScalarMaybeUndef::Scalar(Scalar::from_uint(bits, size))) + Ok(ScalarMaybeUninit::Scalar(Scalar::from_uint(bits, size))) } /// Reads a pointer-sized scalar. @@ -394,7 +394,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra> Allocation { &self, cx: &impl HasDataLayout, ptr: Pointer, - ) -> InterpResult<'tcx, ScalarMaybeUndef> { + ) -> InterpResult<'tcx, ScalarMaybeUninit> { self.read_scalar(cx, ptr, cx.data_layout().pointer_size) } @@ -411,12 +411,12 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra> Allocation { &mut self, cx: &impl HasDataLayout, ptr: Pointer, - val: ScalarMaybeUndef, + val: ScalarMaybeUninit, type_size: Size, ) -> InterpResult<'tcx> { let val = match val { - ScalarMaybeUndef::Scalar(scalar) => scalar, - ScalarMaybeUndef::Undef => { + ScalarMaybeUninit::Scalar(scalar) => scalar, + ScalarMaybeUninit::Undef => { self.mark_definedness(ptr, type_size, false); return Ok(()); } @@ -447,7 +447,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra> Allocation { &mut self, cx: &impl HasDataLayout, ptr: Pointer, - val: ScalarMaybeUndef, + val: ScalarMaybeUninit, ) -> InterpResult<'tcx> { let ptr_size = cx.data_layout().pointer_size; self.write_scalar(cx, ptr, val, ptr_size) @@ -557,7 +557,7 @@ impl<'tcx, Tag: Copy, Extra> Allocation { /// error which will report the first byte which is undefined. fn check_defined(&self, ptr: Pointer, size: Size) -> InterpResult<'tcx> { self.is_defined(ptr, size) - .or_else(|idx| throw_ub!(InvalidUndefBytes(Some(Pointer::new(ptr.alloc_id, idx))))) + .or_else(|idx| throw_ub!(InvalidUninitBytes(Some(Pointer::new(ptr.alloc_id, idx))))) } pub fn mark_definedness(&mut self, ptr: Pointer, size: Size, new_state: bool) { @@ -744,16 +744,16 @@ type Block = u64; /// is defined. If it is `false` the byte is undefined. #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)] #[derive(HashStable)] -pub struct UndefMask { +pub struct UninitMask { blocks: Vec, len: Size, } -impl UndefMask { +impl UninitMask { pub const BLOCK_SIZE: u64 = 64; pub fn new(size: Size, state: bool) -> Self { - let mut m = UndefMask { blocks: vec![], len: Size::ZERO }; + let mut m = UninitMask { blocks: vec![], len: Size::ZERO }; m.grow(size, state); m } @@ -872,7 +872,7 @@ impl UndefMask { #[inline] fn bit_index(bits: Size) -> (usize, usize) { let bits = bits.bytes(); - let a = bits / UndefMask::BLOCK_SIZE; - let b = bits % UndefMask::BLOCK_SIZE; + let a = bits / UninitMask::BLOCK_SIZE; + let b = bits % UninitMask::BLOCK_SIZE; (usize::try_from(a).unwrap(), usize::try_from(b).unwrap()) } diff --git a/src/librustc_middle/mir/interpret/error.rs b/src/librustc_middle/mir/interpret/error.rs index c56dc5196c6c2..7e3f895ff8555 100644 --- a/src/librustc_middle/mir/interpret/error.rs +++ b/src/librustc_middle/mir/interpret/error.rs @@ -1,4 +1,4 @@ -use super::{AllocId, CheckInAllocMsg, Pointer, RawConst, ScalarMaybeUndef}; +use super::{AllocId, CheckInAllocMsg, Pointer, RawConst, ScalarMaybeUninit}; use crate::mir::interpret::ConstValue; use crate::ty::layout::LayoutError; @@ -312,7 +312,7 @@ pub enum UndefinedBehaviorInfo { /// Unreachable code was executed. Unreachable, /// An enum discriminant was set to a value which was outside the range of valid values. - InvalidDiscriminant(ScalarMaybeUndef), + InvalidDiscriminant(ScalarMaybeUninit), /// A slice/array index projection went out-of-bounds. BoundsCheckFailed { len: u64, @@ -358,7 +358,7 @@ pub enum UndefinedBehaviorInfo { /// Using a non-character `u32` as character. InvalidChar(u32), /// Using uninitialized data where it is not allowed. - InvalidUndefBytes(Option), + InvalidUninitBytes(Option), /// Working with a local that is not currently live. DeadLocal, /// Trying to read from the return place of a function. @@ -414,12 +414,12 @@ impl fmt::Debug for UndefinedBehaviorInfo { ValidationFailure(ref err) => write!(f, "type validation failed: {}", err), InvalidBool(b) => write!(f, "interpreting an invalid 8-bit value as a bool: {}", b), InvalidChar(c) => write!(f, "interpreting an invalid 32-bit value as a char: {}", c), - InvalidUndefBytes(Some(p)) => write!( + InvalidUninitBytes(Some(p)) => write!( f, "reading uninitialized memory at {:?}, but this operation requires initialized memory", p ), - InvalidUndefBytes(None) => write!( + InvalidUninitBytes(None) => write!( f, "using uninitialized data, but this operation requires initialized memory" ), diff --git a/src/librustc_middle/mir/interpret/mod.rs b/src/librustc_middle/mir/interpret/mod.rs index 96bf694d8fa67..ea1ea5415a2fd 100644 --- a/src/librustc_middle/mir/interpret/mod.rs +++ b/src/librustc_middle/mir/interpret/mod.rs @@ -122,9 +122,9 @@ pub use self::error::{ ResourceExhaustionInfo, UndefinedBehaviorInfo, UnsupportedOpInfo, }; -pub use self::value::{get_slice_bytes, ConstValue, RawConst, Scalar, ScalarMaybeUndef}; +pub use self::value::{get_slice_bytes, ConstValue, RawConst, Scalar, ScalarMaybeUninit}; -pub use self::allocation::{Allocation, AllocationExtra, Relocations, UndefMask}; +pub use self::allocation::{Allocation, AllocationExtra, Relocations, UninitMask}; pub use self::pointer::{CheckInAllocMsg, Pointer, PointerArithmetic}; diff --git a/src/librustc_middle/mir/interpret/value.rs b/src/librustc_middle/mir/interpret/value.rs index f3c1c87dad484..9c6f261c106e5 100644 --- a/src/librustc_middle/mir/interpret/value.rs +++ b/src/librustc_middle/mir/interpret/value.rs @@ -535,60 +535,60 @@ impl From> for Scalar { } #[derive(Clone, Copy, Eq, PartialEq, RustcEncodable, RustcDecodable, HashStable, Hash)] -pub enum ScalarMaybeUndef { +pub enum ScalarMaybeUninit { Scalar(Scalar), Undef, } -impl From> for ScalarMaybeUndef { +impl From> for ScalarMaybeUninit { #[inline(always)] fn from(s: Scalar) -> Self { - ScalarMaybeUndef::Scalar(s) + ScalarMaybeUninit::Scalar(s) } } -impl From> for ScalarMaybeUndef { +impl From> for ScalarMaybeUninit { #[inline(always)] fn from(s: Pointer) -> Self { - ScalarMaybeUndef::Scalar(s.into()) + ScalarMaybeUninit::Scalar(s.into()) } } -impl fmt::Debug for ScalarMaybeUndef { +impl fmt::Debug for ScalarMaybeUninit { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - ScalarMaybeUndef::Undef => write!(f, "Undef"), - ScalarMaybeUndef::Scalar(s) => write!(f, "{:?}", s), + ScalarMaybeUninit::Undef => write!(f, "Undef"), + ScalarMaybeUninit::Scalar(s) => write!(f, "{:?}", s), } } } -impl fmt::Display for ScalarMaybeUndef { +impl fmt::Display for ScalarMaybeUninit { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - ScalarMaybeUndef::Undef => write!(f, "uninitialized bytes"), - ScalarMaybeUndef::Scalar(s) => write!(f, "{}", s), + ScalarMaybeUninit::Undef => write!(f, "uninitialized bytes"), + ScalarMaybeUninit::Scalar(s) => write!(f, "{}", s), } } } -impl<'tcx, Tag> ScalarMaybeUndef { +impl<'tcx, Tag> ScalarMaybeUninit { /// Erase the tag from the scalar, if any. /// /// Used by error reporting code to avoid having the error type depend on `Tag`. #[inline] - pub fn erase_tag(self) -> ScalarMaybeUndef { + pub fn erase_tag(self) -> ScalarMaybeUninit { match self { - ScalarMaybeUndef::Scalar(s) => ScalarMaybeUndef::Scalar(s.erase_tag()), - ScalarMaybeUndef::Undef => ScalarMaybeUndef::Undef, + ScalarMaybeUninit::Scalar(s) => ScalarMaybeUninit::Scalar(s.erase_tag()), + ScalarMaybeUninit::Undef => ScalarMaybeUninit::Undef, } } #[inline] pub fn not_undef(self) -> InterpResult<'static, Scalar> { match self { - ScalarMaybeUndef::Scalar(scalar) => Ok(scalar), - ScalarMaybeUndef::Undef => throw_ub!(InvalidUndefBytes(None)), + ScalarMaybeUninit::Scalar(scalar) => Ok(scalar), + ScalarMaybeUninit::Undef => throw_ub!(InvalidUninitBytes(None)), } } diff --git a/src/librustc_mir/const_eval/eval_queries.rs b/src/librustc_mir/const_eval/eval_queries.rs index 1592207e4d291..27b6c3b1d0cc0 100644 --- a/src/librustc_mir/const_eval/eval_queries.rs +++ b/src/librustc_mir/const_eval/eval_queries.rs @@ -3,7 +3,7 @@ use crate::interpret::eval_nullary_intrinsic; use crate::interpret::{ intern_const_alloc_recursive, Allocation, ConstValue, GlobalId, Immediate, InternKind, InterpCx, InterpResult, MPlaceTy, MemoryKind, OpTy, RawConst, RefTracking, Scalar, - ScalarMaybeUndef, StackPopCleanup, + ScalarMaybeUninit, StackPopCleanup, }; use rustc_hir::def::DefKind; use rustc_middle::mir; @@ -102,7 +102,7 @@ pub(super) fn op_to_const<'tcx>( // Only scalars and slices, since they are very common. // Note that further down we turn scalars of undefined bits back to `ByRef`. These can result // from scalar unions that are initialized with one of their zero sized variants. We could - // instead allow `ConstValue::Scalar` to store `ScalarMaybeUndef`, but that would affect all + // instead allow `ConstValue::Scalar` to store `ScalarMaybeUninit`, but that would affect all // the usual cases of extracting e.g. a `usize`, without there being a real use case for the // `Undef` situation. let try_as_immediate = match op.layout.abi { @@ -149,8 +149,8 @@ pub(super) fn op_to_const<'tcx>( // see comment on `let try_as_immediate` above Err(imm) => match *imm { Immediate::Scalar(x) => match x { - ScalarMaybeUndef::Scalar(s) => ConstValue::Scalar(s), - ScalarMaybeUndef::Undef => to_const_value(op.assert_mem_place(ecx)), + ScalarMaybeUninit::Scalar(s) => ConstValue::Scalar(s), + ScalarMaybeUninit::Undef => to_const_value(op.assert_mem_place(ecx)), }, Immediate::ScalarPair(a, b) => { let (data, start) = match a.not_undef().unwrap() { diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index b2a041874d09d..9ef3d7b515296 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -22,7 +22,7 @@ use rustc_target::abi::{Align, HasDataLayout, LayoutOf, Size, TargetDataLayout}; use super::{ Immediate, MPlaceTy, Machine, MemPlace, MemPlaceMeta, Memory, OpTy, Operand, Place, PlaceTy, - ScalarMaybeUndef, StackPopJump, + ScalarMaybeUninit, StackPopJump, }; use crate::util::storage::AlwaysLiveLocals; @@ -928,16 +928,16 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { }, LocalValue::Live(Operand::Immediate(Immediate::Scalar(val))) => { write!(msg, " {:?}", val).unwrap(); - if let ScalarMaybeUndef::Scalar(Scalar::Ptr(ptr)) = val { + if let ScalarMaybeUninit::Scalar(Scalar::Ptr(ptr)) = val { allocs.push(ptr.alloc_id); } } LocalValue::Live(Operand::Immediate(Immediate::ScalarPair(val1, val2))) => { write!(msg, " ({:?}, {:?})", val1, val2).unwrap(); - if let ScalarMaybeUndef::Scalar(Scalar::Ptr(ptr)) = val1 { + if let ScalarMaybeUninit::Scalar(Scalar::Ptr(ptr)) = val1 { allocs.push(ptr.alloc_id); } - if let ScalarMaybeUndef::Scalar(Scalar::Ptr(ptr)) = val2 { + if let ScalarMaybeUninit::Scalar(Scalar::Ptr(ptr)) = val2 { allocs.push(ptr.alloc_id); } } diff --git a/src/librustc_mir/interpret/operand.rs b/src/librustc_mir/interpret/operand.rs index 31e6fbdceee4a..7c266dcda329e 100644 --- a/src/librustc_mir/interpret/operand.rs +++ b/src/librustc_mir/interpret/operand.rs @@ -16,7 +16,7 @@ use rustc_target::abi::{VariantIdx, Variants}; use super::{ from_known_layout, sign_extend, truncate, AllocId, ConstValue, GlobalId, InterpCx, - InterpResult, MPlaceTy, Machine, MemPlace, Place, PlaceTy, Pointer, Scalar, ScalarMaybeUndef, + InterpResult, MPlaceTy, Machine, MemPlace, Place, PlaceTy, Pointer, Scalar, ScalarMaybeUninit, }; /// An `Immediate` represents a single immediate self-contained Rust value. @@ -28,13 +28,13 @@ use super::{ /// defined on `Immediate`, and do not have to work with a `Place`. #[derive(Copy, Clone, Debug, PartialEq, Eq, HashStable, Hash)] pub enum Immediate { - Scalar(ScalarMaybeUndef), - ScalarPair(ScalarMaybeUndef, ScalarMaybeUndef), + Scalar(ScalarMaybeUninit), + ScalarPair(ScalarMaybeUninit, ScalarMaybeUninit), } -impl From> for Immediate { +impl From> for Immediate { #[inline(always)] - fn from(val: ScalarMaybeUndef) -> Self { + fn from(val: ScalarMaybeUninit) -> Self { Immediate::Scalar(val) } } @@ -63,7 +63,7 @@ impl<'tcx, Tag> Immediate { } #[inline] - pub fn to_scalar_or_undef(self) -> ScalarMaybeUndef { + pub fn to_scalar_or_undef(self) -> ScalarMaybeUninit { match self { Immediate::Scalar(val) => val, Immediate::ScalarPair(..) => bug!("Got a wide pointer where a scalar was expected"), @@ -97,14 +97,14 @@ impl std::fmt::Display for ImmTy<'tcx, Tag> { /// Helper function for printing a scalar to a FmtPrinter fn p<'a, 'tcx, F: std::fmt::Write, Tag>( cx: FmtPrinter<'a, 'tcx, F>, - s: ScalarMaybeUndef, + s: ScalarMaybeUninit, ty: Ty<'tcx>, ) -> Result, std::fmt::Error> { match s { - ScalarMaybeUndef::Scalar(s) => { + ScalarMaybeUninit::Scalar(s) => { cx.pretty_print_const_scalar(s.erase_tag(), ty, true) } - ScalarMaybeUndef::Undef => cx.typed_value( + ScalarMaybeUninit::Undef => cx.typed_value( |mut this| { this.write_str("{undef ")?; Ok(this) @@ -314,7 +314,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { pub fn read_scalar( &self, op: OpTy<'tcx, M::PointerTag>, - ) -> InterpResult<'tcx, ScalarMaybeUndef> { + ) -> InterpResult<'tcx, ScalarMaybeUninit> { Ok(self.read_immediate(op)?.to_scalar_or_undef()) } @@ -646,7 +646,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let variants_end = niche_variants.end().as_u32(); let raw_discr = raw_discr .not_undef() - .map_err(|_| err_ub!(InvalidDiscriminant(ScalarMaybeUndef::Undef)))?; + .map_err(|_| err_ub!(InvalidDiscriminant(ScalarMaybeUninit::Undef)))?; match raw_discr.to_bits_or_ptr(discr_val.layout.size, self) { Err(ptr) => { // The niche must be just 0 (which an inbounds pointer value never is) diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs index af3a9da2f6ca6..8629b8e6627ed 100644 --- a/src/librustc_mir/interpret/place.rs +++ b/src/librustc_mir/interpret/place.rs @@ -15,7 +15,7 @@ use rustc_target::abi::{HasDataLayout, LayoutOf, Size, VariantIdx, Variants}; use super::{ mir_assign_valid_types, truncate, AllocId, AllocMap, Allocation, AllocationExtra, ImmTy, Immediate, InterpCx, InterpResult, LocalValue, Machine, MemoryKind, OpTy, Operand, Pointer, - PointerArithmetic, RawConst, Scalar, ScalarMaybeUndef, + PointerArithmetic, RawConst, Scalar, ScalarMaybeUninit, }; #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HashStable)] @@ -679,7 +679,7 @@ where #[inline(always)] pub fn write_scalar( &mut self, - val: impl Into>, + val: impl Into>, dest: PlaceTy<'tcx, M::PointerTag>, ) -> InterpResult<'tcx> { self.write_immediate(Immediate::Scalar(val.into()), dest) @@ -731,19 +731,19 @@ where // This is a very common path, avoid some checks in release mode assert!(!dest.layout.is_unsized(), "Cannot write unsized data"); match src { - Immediate::Scalar(ScalarMaybeUndef::Scalar(Scalar::Ptr(_))) => assert_eq!( + Immediate::Scalar(ScalarMaybeUninit::Scalar(Scalar::Ptr(_))) => assert_eq!( self.pointer_size(), dest.layout.size, "Size mismatch when writing pointer" ), - Immediate::Scalar(ScalarMaybeUndef::Scalar(Scalar::Raw { size, .. })) => { + Immediate::Scalar(ScalarMaybeUninit::Scalar(Scalar::Raw { size, .. })) => { assert_eq!( Size::from_bytes(size), dest.layout.size, "Size mismatch when writing bits" ) } - Immediate::Scalar(ScalarMaybeUndef::Undef) => {} // undef can have any size + Immediate::Scalar(ScalarMaybeUninit::Undef) => {} // undef can have any size Immediate::ScalarPair(_, _) => { // FIXME: Can we check anything here? } diff --git a/src/librustc_mir/interpret/validity.rs b/src/librustc_mir/interpret/validity.rs index e97a39f8c6fec..8f12774a78bd6 100644 --- a/src/librustc_mir/interpret/validity.rs +++ b/src/librustc_mir/interpret/validity.rs @@ -782,7 +782,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M> Err(err) => { // For some errors we might be able to provide extra information match err.kind { - err_ub!(InvalidUndefBytes(Some(ptr))) => { + err_ub!(InvalidUninitBytes(Some(ptr))) => { // Some byte was uninitialized, determine which // element that byte belongs to so we can // provide an index. diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 79dba2c5db8fb..03112472177c8 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -31,7 +31,7 @@ use crate::const_eval::error_to_const_error; use crate::interpret::{ self, intern_const_alloc_recursive, AllocId, Allocation, Frame, ImmTy, Immediate, InternKind, InterpCx, LocalState, LocalValue, Memory, MemoryKind, OpTy, Operand as InterpOperand, PlaceTy, - Pointer, ScalarMaybeUndef, StackPopCleanup, + Pointer, ScalarMaybeUninit, StackPopCleanup, }; use crate::transform::{MirPass, MirSource}; @@ -687,7 +687,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { if let Some(Ok(imm)) = imm { match *imm { - interpret::Immediate::Scalar(ScalarMaybeUndef::Scalar(scalar)) => { + interpret::Immediate::Scalar(ScalarMaybeUninit::Scalar(scalar)) => { *rval = Rvalue::Use(self.operand_from_scalar( scalar, value.layout.ty, @@ -695,8 +695,8 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { )); } Immediate::ScalarPair( - ScalarMaybeUndef::Scalar(one), - ScalarMaybeUndef::Scalar(two), + ScalarMaybeUninit::Scalar(one), + ScalarMaybeUninit::Scalar(two), ) => { // Found a value represented as a pair. For now only do cont-prop if type of // Rvalue is also a pair with two scalars. The more general case is more @@ -745,12 +745,12 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { } match *op { - interpret::Operand::Immediate(Immediate::Scalar(ScalarMaybeUndef::Scalar(s))) => { + interpret::Operand::Immediate(Immediate::Scalar(ScalarMaybeUninit::Scalar(s))) => { s.is_bits() } interpret::Operand::Immediate(Immediate::ScalarPair( - ScalarMaybeUndef::Scalar(l), - ScalarMaybeUndef::Scalar(r), + ScalarMaybeUninit::Scalar(l), + ScalarMaybeUninit::Scalar(r), )) => l.is_bits() && r.is_bits(), interpret::Operand::Indirect(_) if mir_opt_level >= 2 => { let mplace = op.assert_mem_place(&self.ecx); @@ -907,7 +907,7 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> { TerminatorKind::Assert { expected, ref msg, ref mut cond, .. } => { if let Some(value) = self.eval_operand(&cond, source_info) { trace!("assertion on {:?} should be {:?}", value, expected); - let expected = ScalarMaybeUndef::from(Scalar::from_bool(*expected)); + let expected = ScalarMaybeUninit::from(Scalar::from_bool(*expected)); let value_const = self.ecx.read_scalar(value).unwrap(); if expected != value_const { // poison all places this operand references so that further code @@ -954,7 +954,7 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> { ); } else { if self.should_const_prop(value) { - if let ScalarMaybeUndef::Scalar(scalar) = value_const { + if let ScalarMaybeUninit::Scalar(scalar) = value_const { *cond = self.operand_from_scalar( scalar, self.tcx.types.bool, @@ -968,7 +968,7 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> { TerminatorKind::SwitchInt { ref mut discr, switch_ty, .. } => { if let Some(value) = self.eval_operand(&discr, source_info) { if self.should_const_prop(value) { - if let ScalarMaybeUndef::Scalar(scalar) = + if let ScalarMaybeUninit::Scalar(scalar) = self.ecx.read_scalar(value).unwrap() { *discr = self.operand_from_scalar(scalar, switch_ty, source_info.span);