Skip to content

Commit c27779f

Browse files
authored
Rollup merge of #75226 - pnadon:miri-undef-uninit, r=RalfJung
Miri: Renamed "undef" to "uninit" Renamed remaining references to "undef" to "uninit" when referring to Miri. Impacted directories are: - `src/librustc_codegen_llvm/consts.rs` - `src/librustc_middle/mir/interpret/` - `src/librustc_middle/ty/print/pretty.rs` - `src/librustc_mir/` - `src/tools/clippy/clippy_lints/src/consts.rs` Upon building Miri based on the new changes it was verified that no changes needed to be made with the Miri project. Related issue #71193
2 parents f26f201 + 0c6e8b6 commit c27779f

File tree

11 files changed

+37
-37
lines changed

11 files changed

+37
-37
lines changed

src/librustc_codegen_llvm/consts.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ pub fn const_alloc_to_llvm(cx: &CodegenCx<'ll, '_>, alloc: &Allocation) -> &'ll
4141
// some arbitrary byte value.
4242
//
4343
// FIXME: relay undef bytes to codegen as undef const bytes
44-
let bytes = alloc.inspect_with_undef_and_ptr_outside_interpreter(next_offset..offset);
44+
let bytes = alloc.inspect_with_uninit_and_ptr_outside_interpreter(next_offset..offset);
4545
llvals.push(cx.const_bytes(bytes));
4646
}
4747
let ptr_offset = read_target_uint(
4848
dl.endian,
4949
// This `inspect` is okay since it is within the bounds of the allocation, it doesn't
5050
// affect interpreter execution (we inspect the result after interpreter execution),
5151
// and we properly interpret the relocation as a relocation pointer offset.
52-
alloc.inspect_with_undef_and_ptr_outside_interpreter(offset..(offset + pointer_size)),
52+
alloc.inspect_with_uninit_and_ptr_outside_interpreter(offset..(offset + pointer_size)),
5353
)
5454
.expect("const_alloc_to_llvm: could not read relocation pointer")
5555
as u64;
@@ -74,7 +74,7 @@ pub fn const_alloc_to_llvm(cx: &CodegenCx<'ll, '_>, alloc: &Allocation) -> &'ll
7474
// arbitrary byte value.
7575
//
7676
// FIXME: relay undef bytes to codegen as undef const bytes
77-
let bytes = alloc.inspect_with_undef_and_ptr_outside_interpreter(range);
77+
let bytes = alloc.inspect_with_uninit_and_ptr_outside_interpreter(range);
7878
llvals.push(cx.const_bytes(bytes));
7979
}
8080

@@ -452,7 +452,7 @@ impl StaticMethods for CodegenCx<'ll, 'tcx> {
452452
// BSS.
453453
let all_bytes_are_zero = alloc.relocations().is_empty()
454454
&& alloc
455-
.inspect_with_undef_and_ptr_outside_interpreter(0..alloc.len())
455+
.inspect_with_uninit_and_ptr_outside_interpreter(0..alloc.len())
456456
.iter()
457457
.all(|&byte| byte == 0);
458458

@@ -480,7 +480,7 @@ impl StaticMethods for CodegenCx<'ll, 'tcx> {
480480
// because we are doing this access to inspect the final interpreter state (not
481481
// as part of the interpreter execution).
482482
let bytes =
483-
alloc.inspect_with_undef_and_ptr_outside_interpreter(0..alloc.len());
483+
alloc.inspect_with_uninit_and_ptr_outside_interpreter(0..alloc.len());
484484
let alloc = llvm::LLVMMDStringInContext(
485485
self.llcx,
486486
bytes.as_ptr().cast(),

src/librustc_middle/mir/interpret/allocation.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,10 @@ impl<Tag, Extra> Allocation<Tag, Extra> {
154154
}
155155

156156
/// Looks at a slice which may describe uninitialized bytes or describe a relocation. This differs
157-
/// from `get_bytes_with_undef_and_ptr` in that it does no relocation checks (even on the
157+
/// from `get_bytes_with_uninit_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.
160-
pub fn inspect_with_undef_and_ptr_outside_interpreter(&self, range: Range<usize>) -> &[u8] {
160+
pub fn inspect_with_uninit_and_ptr_outside_interpreter(&self, range: Range<usize>) -> &[u8] {
161161
&self.bytes[range]
162162
}
163163

@@ -194,7 +194,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
194194

195195
/// 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
197-
/// `get_bytes_with_undef_and_ptr` instead,
197+
/// `get_bytes_with_uninit_and_ptr` instead,
198198
///
199199
/// This function also guarantees that the resulting pointer will remain stable
200200
/// even when new allocations are pushed to the `HashMap`. `copy_repeatedly` relies
@@ -244,7 +244,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
244244
///
245245
/// It is the caller's responsibility to check bounds and alignment beforehand.
246246
#[inline]
247-
pub fn get_bytes_with_undef_and_ptr(
247+
pub fn get_bytes_with_uninit_and_ptr(
248248
&self,
249249
cx: &impl HasDataLayout,
250250
ptr: Pointer<Tag>,
@@ -302,19 +302,19 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
302302
}
303303

304304
/// Validates that `ptr.offset` and `ptr.offset + size` do not point to the middle of a
305-
/// relocation. If `allow_ptr_and_undef` is `false`, also enforces that the memory in the
305+
/// relocation. If `allow_uninit_and_ptr` is `false`, also enforces that the memory in the
306306
/// given range contains neither relocations nor uninitialized bytes.
307307
pub fn check_bytes(
308308
&self,
309309
cx: &impl HasDataLayout,
310310
ptr: Pointer<Tag>,
311311
size: Size,
312-
allow_ptr_and_undef: bool,
312+
allow_uninit_and_ptr: bool,
313313
) -> InterpResult<'tcx> {
314314
// Check bounds and relocations on the edges.
315-
self.get_bytes_with_undef_and_ptr(cx, ptr, size)?;
315+
self.get_bytes_with_uninit_and_ptr(cx, ptr, size)?;
316316
// Check uninit and ptr.
317-
if !allow_ptr_and_undef {
317+
if !allow_uninit_and_ptr {
318318
self.check_init(ptr, size)?;
319319
self.check_relocations(cx, ptr, size)?;
320320
}
@@ -361,7 +361,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
361361
size: Size,
362362
) -> InterpResult<'tcx, ScalarMaybeUninit<Tag>> {
363363
// `get_bytes_unchecked` tests relocation edges.
364-
let bytes = self.get_bytes_with_undef_and_ptr(cx, ptr, size)?;
364+
let bytes = self.get_bytes_with_uninit_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!
367367
if self.is_init(ptr, size).is_err() {
@@ -594,7 +594,7 @@ impl InitMaskCompressed {
594594
/// Transferring the initialization mask to other allocations.
595595
impl<Tag, Extra> Allocation<Tag, Extra> {
596596
/// Creates a run-length encoding of the initialization mask.
597-
pub fn compress_undef_range(&self, src: Pointer<Tag>, size: Size) -> InitMaskCompressed {
597+
pub fn compress_uninit_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`),
599599
// 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,
@@ -636,8 +636,8 @@ impl<Tag, Extra> Allocation<Tag, Extra> {
636636
size: Size,
637637
repeat: u64,
638638
) {
639-
// An optimization where we can just overwrite an entire range of definedness bits if
640-
// they are going to be uniformly `1` or `0`.
639+
// An optimization where we can just overwrite an entire range of initialization
640+
// bits if they are going to be uniformly `1` or `0`.
641641
if defined.ranges.len() <= 1 {
642642
self.init_mask.set_range_inbounds(
643643
dest.offset,

src/librustc_middle/mir/interpret/value.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl<'tcx> ConstValue<'tcx> {
5858

5959
pub fn try_to_str_slice(&self) -> Option<&'tcx str> {
6060
if let ConstValue::Slice { data, start, end } = *self {
61-
::std::str::from_utf8(data.inspect_with_undef_and_ptr_outside_interpreter(start..end))
61+
::std::str::from_utf8(data.inspect_with_uninit_and_ptr_outside_interpreter(start..end))
6262
.ok()
6363
} else {
6464
None

src/librustc_middle/ty/print/pretty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,7 @@ pub trait PrettyPrinter<'tcx>:
11071107
// The `inspect` here is okay since we checked the bounds, and there are
11081108
// no relocations (we have an active slice reference here). We don't use
11091109
// this result to affect interpreter execution.
1110-
let byte_str = data.inspect_with_undef_and_ptr_outside_interpreter(start..end);
1110+
let byte_str = data.inspect_with_uninit_and_ptr_outside_interpreter(start..end);
11111111
self.pretty_print_byte_str(byte_str)
11121112
}
11131113
(
@@ -1117,7 +1117,7 @@ pub trait PrettyPrinter<'tcx>:
11171117
// The `inspect` here is okay since we checked the bounds, and there are no
11181118
// relocations (we have an active `str` reference here). We don't use this
11191119
// result to affect interpreter execution.
1120-
let slice = data.inspect_with_undef_and_ptr_outside_interpreter(start..end);
1120+
let slice = data.inspect_with_uninit_and_ptr_outside_interpreter(start..end);
11211121
let s = ::std::str::from_utf8(slice).expect("non utf8 str from miri");
11221122
p!(write("{:?}", s));
11231123
Ok(self)

src/librustc_mir/interpret/memory.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
926926
// first copy the relocations to a temporary buffer, because
927927
// `get_bytes_mut` will clear the relocations, which is correct,
928928
// since we don't want to keep any relocations at the target.
929-
// (`get_bytes_with_undef_and_ptr` below checks that there are no
929+
// (`get_bytes_with_uninit_and_ptr` below checks that there are no
930930
// relocations overlapping the edges; those would not be handled correctly).
931931
let relocations =
932932
self.get_raw(src.alloc_id)?.prepare_relocation_copy(self, src, size, dest, length);
@@ -935,7 +935,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
935935

936936
// This checks relocation edges on the src.
937937
let src_bytes =
938-
self.get_raw(src.alloc_id)?.get_bytes_with_undef_and_ptr(&tcx, src, size)?.as_ptr();
938+
self.get_raw(src.alloc_id)?.get_bytes_with_uninit_and_ptr(&tcx, src, size)?.as_ptr();
939939
let dest_bytes =
940940
self.get_raw_mut(dest.alloc_id)?.get_bytes_mut(&tcx, dest, size * length)?; // `Size` multiplication
941941

@@ -948,7 +948,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
948948
let dest_bytes = dest_bytes.as_mut_ptr();
949949

950950
// Prepare a copy of the initialization mask.
951-
let compressed = self.get_raw(src.alloc_id)?.compress_undef_range(src, size);
951+
let compressed = self.get_raw(src.alloc_id)?.compress_uninit_range(src, size);
952952

953953
if compressed.no_bytes_init() {
954954
// Fast path: If all bytes are `uninit` then there is nothing to copy. The target range

src/librustc_mir/interpret/operand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl<Tag: Copy> std::fmt::Display for ImmTy<'tcx, Tag> {
106106
}
107107
ScalarMaybeUninit::Uninit => cx.typed_value(
108108
|mut this| {
109-
this.write_str("{undef ")?;
109+
this.write_str("{uninit ")?;
110110
Ok(this)
111111
},
112112
|this| this.print_type(ty),

src/librustc_mir/interpret/place.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl<Tag> MemPlaceMeta<Tag> {
6161
pub struct MemPlace<Tag = ()> {
6262
/// A place may have an integral pointer for ZSTs, and since it might
6363
/// be turned back into a reference before ever being dereferenced.
64-
/// However, it may never be undef.
64+
/// However, it may never be uninit.
6565
pub ptr: Scalar<Tag>,
6666
pub align: Align,
6767
/// Metadata for unsized places. Interpretation is up to the type.
@@ -729,7 +729,7 @@ where
729729
"Size mismatch when writing bits"
730730
)
731731
}
732-
Immediate::Scalar(ScalarMaybeUninit::Uninit) => {} // undef can have any size
732+
Immediate::Scalar(ScalarMaybeUninit::Uninit) => {} // uninit can have any size
733733
Immediate::ScalarPair(_, _) => {
734734
// FIXME: Can we check anything here?
735735
}

src/librustc_mir/interpret/validity.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -508,12 +508,12 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
508508
}
509509
} else {
510510
// At run-time, for now, we accept *anything* for these types, including
511-
// undef. We should fix that, but let's start low.
511+
// uninit. We should fix that, but let's start low.
512512
}
513513
Ok(true)
514514
}
515515
ty::RawPtr(..) => {
516-
// We are conservative with undef for integers, but try to
516+
// We are conservative with uninit for integers, but try to
517517
// actually enforce the strict rules for raw pointers (mostly because
518518
// that lets us re-use `ref_to_mplace`).
519519
let place = try_validation!(
@@ -807,12 +807,12 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
807807
// reject it. However, that's good: We don't inherently want
808808
// to reject those pointers, we just do not have the machinery to
809809
// talk about parts of a pointer.
810-
// We also accept undef, for consistency with the slow path.
810+
// We also accept uninit, for consistency with the slow path.
811811
match self.ecx.memory.get_raw(ptr.alloc_id)?.check_bytes(
812812
self.ecx,
813813
ptr,
814814
size,
815-
/*allow_ptr_and_undef*/ self.ref_tracking_for_consts.is_none(),
815+
/*allow_uninit_and_ptr*/ self.ref_tracking_for_consts.is_none(),
816816
) {
817817
// In the happy case, we needn't check anything else.
818818
Ok(()) => {}

src/librustc_mir/transform/const_prop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,7 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
10761076
// ```rust
10771077
// let mut x = 42;
10781078
// x = SOME_MUTABLE_STATIC;
1079-
// // x must now be undefined
1079+
// // x must now be uninit
10801080
// ```
10811081
// FIXME: we overzealously erase the entire local, because that's easier to
10821082
// implement.

src/librustc_mir/util/pretty.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -743,8 +743,8 @@ fn write_allocation_bytes<Tag: Copy + Debug, Extra>(
743743
if let Some(&(tag, target_id)) = alloc.relocations().get(&i) {
744744
// Memory with a relocation must be defined
745745
let j = i.bytes_usize();
746-
let offset =
747-
alloc.inspect_with_undef_and_ptr_outside_interpreter(j..j + ptr_size.bytes_usize());
746+
let offset = alloc
747+
.inspect_with_uninit_and_ptr_outside_interpreter(j..j + ptr_size.bytes_usize());
748748
let offset = read_target_uint(tcx.data_layout.endian, offset).unwrap();
749749
let offset = Size::from_bytes(offset);
750750
let relocation_width = |bytes| bytes * 3;
@@ -803,7 +803,7 @@ fn write_allocation_bytes<Tag: Copy + Debug, Extra>(
803803

804804
// Checked definedness (and thus range) and relocations. This access also doesn't
805805
// influence interpreter execution but is only for debugging.
806-
let c = alloc.inspect_with_undef_and_ptr_outside_interpreter(j..j + 1)[0];
806+
let c = alloc.inspect_with_uninit_and_ptr_outside_interpreter(j..j + 1)[0];
807807
write!(w, "{:02x}", c)?;
808808
if c.is_ascii_control() || c >= 0x80 {
809809
ascii.push('.');

src/tools/clippy/clippy_lints/src/consts.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ pub fn miri_to_const(result: &ty::Const<'_>) -> Option<Constant> {
517517
ty::ConstKind::Value(ConstValue::Slice { data, start, end }) => match result.ty.kind {
518518
ty::Ref(_, tam, _) => match tam.kind {
519519
ty::Str => String::from_utf8(
520-
data.inspect_with_undef_and_ptr_outside_interpreter(start..end)
520+
data.inspect_with_uninit_and_ptr_outside_interpreter(start..end)
521521
.to_owned(),
522522
)
523523
.ok()
@@ -530,7 +530,7 @@ pub fn miri_to_const(result: &ty::Const<'_>) -> Option<Constant> {
530530
ty::Array(sub_type, len) => match sub_type.kind {
531531
ty::Float(FloatTy::F32) => match miri_to_const(len) {
532532
Some(Constant::Int(len)) => alloc
533-
.inspect_with_undef_and_ptr_outside_interpreter(0..(4 * len as usize))
533+
.inspect_with_uninit_and_ptr_outside_interpreter(0..(4 * len as usize))
534534
.to_owned()
535535
.chunks(4)
536536
.map(|chunk| {
@@ -544,7 +544,7 @@ pub fn miri_to_const(result: &ty::Const<'_>) -> Option<Constant> {
544544
},
545545
ty::Float(FloatTy::F64) => match miri_to_const(len) {
546546
Some(Constant::Int(len)) => alloc
547-
.inspect_with_undef_and_ptr_outside_interpreter(0..(8 * len as usize))
547+
.inspect_with_uninit_and_ptr_outside_interpreter(0..(8 * len as usize))
548548
.to_owned()
549549
.chunks(8)
550550
.map(|chunk| {

0 commit comments

Comments
 (0)