Skip to content

Commit 13f9aa1

Browse files
committedJul 26, 2020
Auto merge of #74664 - pnadon:Miri-rename-undef-uninit, r=RalfJung
Miri rename undef uninit Renamed parts of code within the `librustc_middle/mir/interpret/` directory. Related issue [#71193](#71193)
2 parents 461707c + ef9c4f5 commit 13f9aa1

File tree

12 files changed

+94
-94
lines changed

12 files changed

+94
-94
lines changed
 

‎src/librustc_codegen_ssa/mir/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
883883
let ptr = Pointer::new(AllocId(0), offset);
884884
alloc
885885
.read_scalar(&bx, ptr, size)
886-
.and_then(|s| s.not_undef())
886+
.and_then(|s| s.check_init())
887887
.unwrap_or_else(|e| {
888888
bx.tcx().sess.span_err(
889889
span,

‎src/librustc_middle/mir/interpret/allocation.rs

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl<Tag> Allocation<Tag> {
105105
Allocation::from_bytes(slice, Align::from_bytes(1).unwrap())
106106
}
107107

108-
pub fn undef(size: Size, align: Align) -> Self {
108+
pub fn uninit(size: Size, align: Align) -> Self {
109109
Allocation {
110110
bytes: vec![0; size.bytes_usize()],
111111
relocations: Relocations::new(),
@@ -153,7 +153,7 @@ impl<Tag, Extra> Allocation<Tag, Extra> {
153153
self.size.bytes_usize()
154154
}
155155

156-
/// Looks at a slice which may describe undefined bytes or describe a relocation. This differs
156+
/// Looks at a slice which may describe uninitialized bytes or describe a relocation. This differs
157157
/// from `get_bytes_with_undef_and_ptr` in that it does no relocation checks (even on the
158158
/// edges) at all. It further ignores `AllocationExtra` callbacks.
159159
/// This must not be used for reads affecting the interpreter execution.
@@ -192,7 +192,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
192192
offset.bytes_usize()..end
193193
}
194194

195-
/// The last argument controls whether we error out when there are undefined
195+
/// The last argument controls whether we error out when there are uninitialized
196196
/// or pointer bytes. You should never call this, call `get_bytes` or
197197
/// `get_bytes_with_undef_and_ptr` instead,
198198
///
@@ -206,12 +206,12 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
206206
cx: &impl HasDataLayout,
207207
ptr: Pointer<Tag>,
208208
size: Size,
209-
check_defined_and_ptr: bool,
209+
check_init_and_ptr: bool,
210210
) -> InterpResult<'tcx, &[u8]> {
211211
let range = self.check_bounds(ptr.offset, size);
212212

213-
if check_defined_and_ptr {
214-
self.check_defined(ptr, size)?;
213+
if check_init_and_ptr {
214+
self.check_init(ptr, size)?;
215215
self.check_relocations(cx, ptr, size)?;
216216
} else {
217217
// We still don't want relocations on the *edges*.
@@ -239,7 +239,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
239239
self.get_bytes_internal(cx, ptr, size, true)
240240
}
241241

242-
/// It is the caller's responsibility to handle undefined and pointer bytes.
242+
/// It is the caller's responsibility to handle uninitialized and pointer bytes.
243243
/// However, this still checks that there are no relocations on the *edges*.
244244
///
245245
/// It is the caller's responsibility to check bounds and alignment beforehand.
@@ -267,7 +267,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
267267
) -> InterpResult<'tcx, &mut [u8]> {
268268
let range = self.check_bounds(ptr.offset, size);
269269

270-
self.mark_definedness(ptr, size, true);
270+
self.mark_init(ptr, size, true);
271271
self.clear_relocations(cx, ptr, size)?;
272272

273273
AllocationExtra::memory_written(self, ptr, size)?;
@@ -303,7 +303,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
303303

304304
/// Validates that `ptr.offset` and `ptr.offset + size` do not point to the middle of a
305305
/// relocation. If `allow_ptr_and_undef` is `false`, also enforces that the memory in the
306-
/// given range contains neither relocations nor undef bytes.
306+
/// given range contains neither relocations nor uninitialized bytes.
307307
pub fn check_bytes(
308308
&self,
309309
cx: &impl HasDataLayout,
@@ -313,9 +313,9 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
313313
) -> InterpResult<'tcx> {
314314
// Check bounds and relocations on the edges.
315315
self.get_bytes_with_undef_and_ptr(cx, ptr, size)?;
316-
// Check undef and ptr.
316+
// Check uninit and ptr.
317317
if !allow_ptr_and_undef {
318-
self.check_defined(ptr, size)?;
318+
self.check_init(ptr, size)?;
319319
self.check_relocations(cx, ptr, size)?;
320320
}
321321
Ok(())
@@ -364,7 +364,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
364364
let bytes = self.get_bytes_with_undef_and_ptr(cx, ptr, size)?;
365365
// Uninit check happens *after* we established that the alignment is correct.
366366
// We must not return `Ok()` for unaligned pointers!
367-
if self.is_defined(ptr, size).is_err() {
367+
if self.is_init(ptr, size).is_err() {
368368
// This inflates uninitialized bytes to the entire scalar, even if only a few
369369
// bytes are uninitialized.
370370
return Ok(ScalarMaybeUninit::Uninit);
@@ -416,7 +416,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
416416
let val = match val {
417417
ScalarMaybeUninit::Scalar(scalar) => scalar,
418418
ScalarMaybeUninit::Uninit => {
419-
self.mark_definedness(ptr, type_size, false);
419+
self.mark_init(ptr, type_size, false);
420420
return Ok(());
421421
}
422422
};
@@ -512,7 +512,7 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
512512
let start = ptr.offset;
513513
let end = start + size; // `Size` addition
514514

515-
// Mark parts of the outermost relocations as undefined if they partially fall outside the
515+
// Mark parts of the outermost relocations as uninitialized if they partially fall outside the
516516
// given range.
517517
if first < start {
518518
self.init_mask.set_range(first, start, false);
@@ -542,20 +542,20 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
542542
}
543543
}
544544

545-
/// Undefined bytes.
545+
/// Uninitialized bytes.
546546
impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
547-
/// Checks whether the given range is entirely defined.
547+
/// Checks whether the given range is entirely initialized.
548548
///
549-
/// Returns `Ok(())` if it's defined. Otherwise returns the range of byte
550-
/// indexes of the first contiguous undefined access.
551-
fn is_defined(&self, ptr: Pointer<Tag>, size: Size) -> Result<(), Range<Size>> {
549+
/// Returns `Ok(())` if it's initialized. Otherwise returns the range of byte
550+
/// indexes of the first contiguous uninitialized access.
551+
fn is_init(&self, ptr: Pointer<Tag>, size: Size) -> Result<(), Range<Size>> {
552552
self.init_mask.is_range_initialized(ptr.offset, ptr.offset + size) // `Size` addition
553553
}
554554

555-
/// Checks that a range of bytes is defined. If not, returns the `InvalidUndefBytes`
556-
/// error which will report the first range of bytes which is undefined.
557-
fn check_defined(&self, ptr: Pointer<Tag>, size: Size) -> InterpResult<'tcx> {
558-
self.is_defined(ptr, size).or_else(|idx_range| {
555+
/// Checks that a range of bytes is initialized. If not, returns the `InvalidUninitBytes`
556+
/// error which will report the first range of bytes which is uninitialized.
557+
fn check_init(&self, ptr: Pointer<Tag>, size: Size) -> InterpResult<'tcx> {
558+
self.is_init(ptr, size).or_else(|idx_range| {
559559
throw_ub!(InvalidUninitBytes(Some(Box::new(UninitBytesAccess {
560560
access_ptr: ptr.erase_tag(),
561561
access_size: size,
@@ -565,44 +565,44 @@ impl<'tcx, Tag: Copy, Extra> Allocation<Tag, Extra> {
565565
})
566566
}
567567

568-
pub fn mark_definedness(&mut self, ptr: Pointer<Tag>, size: Size, new_state: bool) {
568+
pub fn mark_init(&mut self, ptr: Pointer<Tag>, size: Size, is_init: bool) {
569569
if size.bytes() == 0 {
570570
return;
571571
}
572-
self.init_mask.set_range(ptr.offset, ptr.offset + size, new_state);
572+
self.init_mask.set_range(ptr.offset, ptr.offset + size, is_init);
573573
}
574574
}
575575

576-
/// Run-length encoding of the undef mask.
576+
/// Run-length encoding of the uninit mask.
577577
/// Used to copy parts of a mask multiple times to another allocation.
578-
pub struct AllocationDefinedness {
579-
/// The definedness of the first range.
578+
pub struct InitMaskCompressed {
579+
/// Whether the first range is initialized.
580580
initial: bool,
581581
/// The lengths of ranges that are run-length encoded.
582-
/// The definedness of the ranges alternate starting with `initial`.
582+
/// The initialization state of the ranges alternate starting with `initial`.
583583
ranges: smallvec::SmallVec<[u64; 1]>,
584584
}
585585

586-
impl AllocationDefinedness {
587-
pub fn all_bytes_undef(&self) -> bool {
588-
// The `ranges` are run-length encoded and of alternating definedness.
589-
// So if `ranges.len() > 1` then the second block is a range of defined.
586+
impl InitMaskCompressed {
587+
pub fn no_bytes_init(&self) -> bool {
588+
// The `ranges` are run-length encoded and of alternating initialization state.
589+
// So if `ranges.len() > 1` then the second block is an initialized range.
590590
!self.initial && self.ranges.len() == 1
591591
}
592592
}
593593

594-
/// Transferring the definedness mask to other allocations.
594+
/// Transferring the initialization mask to other allocations.
595595
impl<Tag, Extra> Allocation<Tag, Extra> {
596-
/// Creates a run-length encoding of the undef mask.
597-
pub fn compress_undef_range(&self, src: Pointer<Tag>, size: Size) -> AllocationDefinedness {
596+
/// Creates a run-length encoding of the initialization mask.
597+
pub fn compress_undef_range(&self, src: Pointer<Tag>, size: Size) -> InitMaskCompressed {
598598
// Since we are copying `size` bytes from `src` to `dest + i * size` (`for i in 0..repeat`),
599-
// a naive undef mask copying algorithm would repeatedly have to read the undef mask from
599+
// a naive initialization mask copying algorithm would repeatedly have to read the initialization mask from
600600
// the source and write it to the destination. Even if we optimized the memory accesses,
601601
// we'd be doing all of this `repeat` times.
602-
// Therefore we precompute a compressed version of the undef mask of the source value and
602+
// Therefore we precompute a compressed version of the initialization mask of the source value and
603603
// then write it back `repeat` times without computing any more information from the source.
604604

605-
// A precomputed cache for ranges of defined/undefined bits
605+
// A precomputed cache for ranges of initialized / uninitialized bits
606606
// 0000010010001110 will become
607607
// `[5, 1, 2, 1, 3, 3, 1]`,
608608
// where each element toggles the state.
@@ -613,7 +613,7 @@ impl<Tag, Extra> Allocation<Tag, Extra> {
613613
let mut cur = initial;
614614

615615
for i in 1..size.bytes() {
616-
// FIXME: optimize to bitshift the current undef block's bits and read the top bit.
616+
// FIXME: optimize to bitshift the current uninitialized block's bits and read the top bit.
617617
if self.init_mask.get(src.offset + Size::from_bytes(i)) == cur {
618618
cur_len += 1;
619619
} else {
@@ -625,13 +625,13 @@ impl<Tag, Extra> Allocation<Tag, Extra> {
625625

626626
ranges.push(cur_len);
627627

628-
AllocationDefinedness { ranges, initial }
628+
InitMaskCompressed { ranges, initial }
629629
}
630630

631-
/// Applies multiple instances of the run-length encoding to the undef mask.
632-
pub fn mark_compressed_undef_range(
631+
/// Applies multiple instances of the run-length encoding to the initialization mask.
632+
pub fn mark_compressed_init_range(
633633
&mut self,
634-
defined: &AllocationDefinedness,
634+
defined: &InitMaskCompressed,
635635
dest: Pointer<Tag>,
636636
size: Size,
637637
repeat: u64,
@@ -740,7 +740,7 @@ impl<Tag: Copy, Extra> Allocation<Tag, Extra> {
740740
}
741741

742742
////////////////////////////////////////////////////////////////////////////////
743-
// Undefined byte tracking
743+
// Uninitialized byte tracking
744744
////////////////////////////////////////////////////////////////////////////////
745745

746746
type Block = u64;
@@ -778,11 +778,11 @@ impl InitMask {
778778

779779
match idx {
780780
Some(idx) => {
781-
let undef_end = (idx.bytes()..end.bytes())
781+
let uninit_end = (idx.bytes()..end.bytes())
782782
.map(Size::from_bytes)
783783
.find(|&i| self.get(i))
784784
.unwrap_or(end);
785-
Err(idx..undef_end)
785+
Err(idx..uninit_end)
786786
}
787787
None => Ok(()),
788788
}

‎src/librustc_middle/mir/interpret/value.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ impl<'tcx, Tag> ScalarMaybeUninit<Tag> {
606606
}
607607

608608
#[inline]
609-
pub fn not_undef(self) -> InterpResult<'static, Scalar<Tag>> {
609+
pub fn check_init(self) -> InterpResult<'static, Scalar<Tag>> {
610610
match self {
611611
ScalarMaybeUninit::Scalar(scalar) => Ok(scalar),
612612
ScalarMaybeUninit::Uninit => throw_ub!(InvalidUninitBytes(None)),
@@ -615,72 +615,72 @@ impl<'tcx, Tag> ScalarMaybeUninit<Tag> {
615615

616616
#[inline(always)]
617617
pub fn to_bool(self) -> InterpResult<'tcx, bool> {
618-
self.not_undef()?.to_bool()
618+
self.check_init()?.to_bool()
619619
}
620620

621621
#[inline(always)]
622622
pub fn to_char(self) -> InterpResult<'tcx, char> {
623-
self.not_undef()?.to_char()
623+
self.check_init()?.to_char()
624624
}
625625

626626
#[inline(always)]
627627
pub fn to_f32(self) -> InterpResult<'tcx, Single> {
628-
self.not_undef()?.to_f32()
628+
self.check_init()?.to_f32()
629629
}
630630

631631
#[inline(always)]
632632
pub fn to_f64(self) -> InterpResult<'tcx, Double> {
633-
self.not_undef()?.to_f64()
633+
self.check_init()?.to_f64()
634634
}
635635

636636
#[inline(always)]
637637
pub fn to_u8(self) -> InterpResult<'tcx, u8> {
638-
self.not_undef()?.to_u8()
638+
self.check_init()?.to_u8()
639639
}
640640

641641
#[inline(always)]
642642
pub fn to_u16(self) -> InterpResult<'tcx, u16> {
643-
self.not_undef()?.to_u16()
643+
self.check_init()?.to_u16()
644644
}
645645

646646
#[inline(always)]
647647
pub fn to_u32(self) -> InterpResult<'tcx, u32> {
648-
self.not_undef()?.to_u32()
648+
self.check_init()?.to_u32()
649649
}
650650

651651
#[inline(always)]
652652
pub fn to_u64(self) -> InterpResult<'tcx, u64> {
653-
self.not_undef()?.to_u64()
653+
self.check_init()?.to_u64()
654654
}
655655

656656
#[inline(always)]
657657
pub fn to_machine_usize(self, cx: &impl HasDataLayout) -> InterpResult<'tcx, u64> {
658-
self.not_undef()?.to_machine_usize(cx)
658+
self.check_init()?.to_machine_usize(cx)
659659
}
660660

661661
#[inline(always)]
662662
pub fn to_i8(self) -> InterpResult<'tcx, i8> {
663-
self.not_undef()?.to_i8()
663+
self.check_init()?.to_i8()
664664
}
665665

666666
#[inline(always)]
667667
pub fn to_i16(self) -> InterpResult<'tcx, i16> {
668-
self.not_undef()?.to_i16()
668+
self.check_init()?.to_i16()
669669
}
670670

671671
#[inline(always)]
672672
pub fn to_i32(self) -> InterpResult<'tcx, i32> {
673-
self.not_undef()?.to_i32()
673+
self.check_init()?.to_i32()
674674
}
675675

676676
#[inline(always)]
677677
pub fn to_i64(self) -> InterpResult<'tcx, i64> {
678-
self.not_undef()?.to_i64()
678+
self.check_init()?.to_i64()
679679
}
680680

681681
#[inline(always)]
682682
pub fn to_machine_isize(self, cx: &impl HasDataLayout) -> InterpResult<'tcx, i64> {
683-
self.not_undef()?.to_machine_isize(cx)
683+
self.check_init()?.to_machine_isize(cx)
684684
}
685685
}
686686

‎src/librustc_mir/const_eval/eval_queries.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ pub(super) fn op_to_const<'tcx>(
154154
ScalarMaybeUninit::Uninit => to_const_value(op.assert_mem_place(ecx)),
155155
},
156156
Immediate::ScalarPair(a, b) => {
157-
let (data, start) = match a.not_undef().unwrap() {
157+
let (data, start) = match a.check_init().unwrap() {
158158
Scalar::Ptr(ptr) => {
159159
(ecx.tcx.global_alloc(ptr.alloc_id).unwrap_memory(), ptr.offset.bytes())
160160
}

‎src/librustc_mir/interpret/intrinsics.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
150150
| sym::bitreverse => {
151151
let ty = substs.type_at(0);
152152
let layout_of = self.layout_of(ty)?;
153-
let val = self.read_scalar(args[0])?.not_undef()?;
153+
let val = self.read_scalar(args[0])?.check_init()?;
154154
let bits = self.force_bits(val, layout_of.size)?;
155155
let kind = match layout_of.abi {
156156
Abi::Scalar(ref scalar) => scalar.value,
@@ -281,9 +281,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
281281
// rotate_left: (X << (S % BW)) | (X >> ((BW - S) % BW))
282282
// rotate_right: (X << ((BW - S) % BW)) | (X >> (S % BW))
283283
let layout = self.layout_of(substs.type_at(0))?;
284-
let val = self.read_scalar(args[0])?.not_undef()?;
284+
let val = self.read_scalar(args[0])?.check_init()?;
285285
let val_bits = self.force_bits(val, layout.size)?;
286-
let raw_shift = self.read_scalar(args[1])?.not_undef()?;
286+
let raw_shift = self.read_scalar(args[1])?.check_init()?;
287287
let raw_shift_bits = self.force_bits(raw_shift, layout.size)?;
288288
let width_bits = u128::from(layout.size.bits());
289289
let shift_bits = raw_shift_bits % width_bits;
@@ -298,15 +298,15 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
298298
self.write_scalar(result, dest)?;
299299
}
300300
sym::offset => {
301-
let ptr = self.read_scalar(args[0])?.not_undef()?;
301+
let ptr = self.read_scalar(args[0])?.check_init()?;
302302
let offset_count = self.read_scalar(args[1])?.to_machine_isize(self)?;
303303
let pointee_ty = substs.type_at(0);
304304

305305
let offset_ptr = self.ptr_offset_inbounds(ptr, pointee_ty, offset_count)?;
306306
self.write_scalar(offset_ptr, dest)?;
307307
}
308308
sym::arith_offset => {
309-
let ptr = self.read_scalar(args[0])?.not_undef()?;
309+
let ptr = self.read_scalar(args[0])?.check_init()?;
310310
let offset_count = self.read_scalar(args[1])?.to_machine_isize(self)?;
311311
let pointee_ty = substs.type_at(0);
312312

‎src/librustc_mir/interpret/memory.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
171171
align: Align,
172172
kind: MemoryKind<M::MemoryKind>,
173173
) -> Pointer<M::PointerTag> {
174-
let alloc = Allocation::undef(size, align);
174+
let alloc = Allocation::uninit(size, align);
175175
self.allocate_with(alloc, kind)
176176
}
177177

@@ -907,18 +907,18 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
907907

908908
let dest_bytes = dest_bytes.as_mut_ptr();
909909

910-
// Prepare a copy of the undef mask.
910+
// Prepare a copy of the initialization mask.
911911
let compressed = self.get_raw(src.alloc_id)?.compress_undef_range(src, size);
912912

913-
if compressed.all_bytes_undef() {
914-
// Fast path: If all bytes are `undef` then there is nothing to copy. The target range
915-
// is marked as undef but we otherwise omit changing the byte representation which may
916-
// be arbitrary for undef bytes.
913+
if compressed.no_bytes_init() {
914+
// Fast path: If all bytes are `uninit` then there is nothing to copy. The target range
915+
// is marked as unititialized but we otherwise omit changing the byte representation which may
916+
// be arbitrary for uninitialized bytes.
917917
// This also avoids writing to the target bytes so that the backing allocation is never
918-
// touched if the bytes stay undef for the whole interpreter execution. On contemporary
918+
// touched if the bytes stay uninitialized for the whole interpreter execution. On contemporary
919919
// operating system this can avoid physically allocating the page.
920920
let dest_alloc = self.get_raw_mut(dest.alloc_id)?;
921-
dest_alloc.mark_definedness(dest, size * length, false); // `Size` multiplication
921+
dest_alloc.mark_init(dest, size * length, false); // `Size` multiplication
922922
dest_alloc.mark_relocation_range(relocations);
923923
return Ok(());
924924
}
@@ -958,7 +958,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
958958
}
959959

960960
// now fill in all the data
961-
self.get_raw_mut(dest.alloc_id)?.mark_compressed_undef_range(
961+
self.get_raw_mut(dest.alloc_id)?.mark_compressed_init_range(
962962
&compressed,
963963
dest,
964964
size,

‎src/librustc_mir/interpret/operand.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl<'tcx, Tag> Immediate<Tag> {
6363
}
6464

6565
#[inline]
66-
pub fn to_scalar_or_undef(self) -> ScalarMaybeUninit<Tag> {
66+
pub fn to_scalar_or_uninit(self) -> ScalarMaybeUninit<Tag> {
6767
match self {
6868
Immediate::Scalar(val) => val,
6969
Immediate::ScalarPair(..) => bug!("Got a wide pointer where a scalar was expected"),
@@ -72,14 +72,14 @@ impl<'tcx, Tag> Immediate<Tag> {
7272

7373
#[inline]
7474
pub fn to_scalar(self) -> InterpResult<'tcx, Scalar<Tag>> {
75-
self.to_scalar_or_undef().not_undef()
75+
self.to_scalar_or_uninit().check_init()
7676
}
7777

7878
#[inline]
7979
pub fn to_scalar_pair(self) -> InterpResult<'tcx, (Scalar<Tag>, Scalar<Tag>)> {
8080
match self {
8181
Immediate::Scalar(..) => bug!("Got a thin pointer where a scalar pair was expected"),
82-
Immediate::ScalarPair(a, b) => Ok((a.not_undef()?, b.not_undef()?)),
82+
Immediate::ScalarPair(a, b) => Ok((a.check_init()?, b.check_init()?)),
8383
}
8484
}
8585
}
@@ -333,7 +333,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
333333
&self,
334334
op: OpTy<'tcx, M::PointerTag>,
335335
) -> InterpResult<'tcx, ScalarMaybeUninit<M::PointerTag>> {
336-
Ok(self.read_immediate(op)?.to_scalar_or_undef())
336+
Ok(self.read_immediate(op)?.to_scalar_or_uninit())
337337
}
338338

339339
// Turn the wide MPlace into a string (must already be dereferenced!)

‎src/librustc_mir/interpret/place.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,9 @@ where
292292
val.layout.ty.builtin_deref(true).expect("`ref_to_mplace` called on non-ptr type").ty;
293293
let layout = self.layout_of(pointee_type)?;
294294
let (ptr, meta) = match *val {
295-
Immediate::Scalar(ptr) => (ptr.not_undef()?, MemPlaceMeta::None),
295+
Immediate::Scalar(ptr) => (ptr.check_init()?, MemPlaceMeta::None),
296296
Immediate::ScalarPair(ptr, meta) => {
297-
(ptr.not_undef()?, MemPlaceMeta::Meta(meta.not_undef()?))
297+
(ptr.check_init()?, MemPlaceMeta::Meta(meta.check_init()?))
298298
}
299299
};
300300

@@ -541,7 +541,7 @@ where
541541
let n = self.access_local(self.frame(), local, Some(layout))?;
542542
let n = self.read_scalar(n)?;
543543
let n = u64::try_from(
544-
self.force_bits(n.not_undef()?, self.tcx.data_layout.pointer_size)?,
544+
self.force_bits(n.check_init()?, self.tcx.data_layout.pointer_size)?,
545545
)
546546
.unwrap();
547547
self.mplace_index(base, n)?

‎src/librustc_mir/interpret/terminator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
5858
let (fn_val, abi) = match func.layout.ty.kind {
5959
ty::FnPtr(sig) => {
6060
let caller_abi = sig.abi();
61-
let fn_ptr = self.read_scalar(func)?.not_undef()?;
61+
let fn_ptr = self.read_scalar(func)?.check_init()?;
6262
let fn_val = self.memory.get_fn(fn_ptr)?;
6363
(fn_val, caller_abi)
6464
}

‎src/librustc_mir/interpret/traits.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
118118
.memory
119119
.get_raw(vtable_slot.alloc_id)?
120120
.read_ptr_sized(self, vtable_slot)?
121-
.not_undef()?;
121+
.check_init()?;
122122
Ok(self.memory.get_fn(fn_ptr)?)
123123
}
124124

@@ -137,7 +137,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
137137
)?
138138
.expect("cannot be a ZST");
139139
let drop_fn =
140-
self.memory.get_raw(vtable.alloc_id)?.read_ptr_sized(self, vtable)?.not_undef()?;
140+
self.memory.get_raw(vtable.alloc_id)?.read_ptr_sized(self, vtable)?.check_init()?;
141141
// We *need* an instance here, no other kind of function value, to be able
142142
// to determine the type.
143143
let drop_instance = self.memory.get_fn(drop_fn)?.as_instance()?;
@@ -165,10 +165,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
165165
.check_ptr_access(vtable, 3 * pointer_size, self.tcx.data_layout.pointer_align.abi)?
166166
.expect("cannot be a ZST");
167167
let alloc = self.memory.get_raw(vtable.alloc_id)?;
168-
let size = alloc.read_ptr_sized(self, vtable.offset(pointer_size, self)?)?.not_undef()?;
168+
let size = alloc.read_ptr_sized(self, vtable.offset(pointer_size, self)?)?.check_init()?;
169169
let size = u64::try_from(self.force_bits(size, pointer_size)?).unwrap();
170170
let align =
171-
alloc.read_ptr_sized(self, vtable.offset(pointer_size * 2, self)?)?.not_undef()?;
171+
alloc.read_ptr_sized(self, vtable.offset(pointer_size * 2, self)?)?.check_init()?;
172172
let align = u64::try_from(self.force_bits(align, pointer_size)?).unwrap();
173173

174174
if size >= self.tcx.data_layout.obj_size_bound() {

‎src/librustc_mir/interpret/validity.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
500500
// types below!
501501
if self.ref_tracking_for_consts.is_some() {
502502
// Integers/floats in CTFE: Must be scalar bits, pointers are dangerous
503-
let is_bits = value.not_undef().map_or(false, |v| v.is_bits());
503+
let is_bits = value.check_init().map_or(false, |v| v.is_bits());
504504
if !is_bits {
505505
throw_validation_failure!(self.path,
506506
{ "{}", value } expected { "initialized plain (non-pointer) bytes" }
@@ -537,7 +537,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
537537
ty::FnPtr(_sig) => {
538538
let value = self.ecx.read_scalar(value)?;
539539
let _fn = try_validation!(
540-
value.not_undef().and_then(|ptr| self.ecx.memory.get_fn(ptr)),
540+
value.check_init().and_then(|ptr| self.ecx.memory.get_fn(ptr)),
541541
self.path,
542542
err_ub!(DanglingIntPointer(..)) |
543543
err_ub!(InvalidFunctionPointer(..)) |
@@ -596,7 +596,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
596596
}
597597
// At least one value is excluded. Get the bits.
598598
let value = try_validation!(
599-
value.not_undef(),
599+
value.check_init(),
600600
self.path,
601601
err_ub!(InvalidUninitBytes(None)) => { "{}", value }
602602
expected { "something {}", wrapping_range_format(valid_range, max_hi) },

‎src/librustc_mir_build/hair/pattern/_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2614,7 +2614,7 @@ fn specialize_one_pattern<'p, 'tcx>(
26142614
let pats = cx.pattern_arena.alloc_from_iter((0..n).filter_map(|i| {
26152615
let ptr = ptr.offset(layout.size * i, &cx.tcx).ok()?;
26162616
let scalar = alloc.read_scalar(&cx.tcx, ptr, layout.size).ok()?;
2617-
let scalar = scalar.not_undef().ok()?;
2617+
let scalar = scalar.check_init().ok()?;
26182618
let value = ty::Const::from_scalar(cx.tcx, scalar, ty);
26192619
let pattern = Pat { ty, span: pat.span, kind: box PatKind::Constant { value } };
26202620
Some(pattern)

0 commit comments

Comments
 (0)
Please sign in to comment.