Skip to content

Commit 560bf1f

Browse files
committed
Auto merge of #108096 - matthiaskrgr:rollup-ncexzf6, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - #107034 (Migrating rustc_infer to session diagnostics (part 4)) - #107972 (Fix unintentional UB in ui tests) - #108010 (Make `InferCtxt::can_eq` and `InferCtxt::can_sub` return booleans) - #108021 (make x look for x.py if shell script does not exist) - #108047 (Use `target` instead of `machine` for mir interpreter integer handling.) - #108049 (Don't suggest `#[doc(hidden)]` trait methods with matching return type) - #108066 (Better names for illegal impl trait positions) - #108076 (rustdoc: Use more let chain) - #108088 (clarify correctness of `black_box`) - #108094 (Demonstrate I/O in File examples) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7f80d26 + 54c3c49 commit 560bf1f

25 files changed

+107
-107
lines changed

src/borrow_tracker/stacked_borrows/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ trait EvalContextPrivExt<'mir: 'ecx, 'tcx: 'mir, 'ecx>: crate::MiriInterpCxExt<'
718718
throw_ub!(PointerOutOfBounds {
719719
alloc_id,
720720
alloc_size,
721-
ptr_offset: this.machine_usize_to_isize(base_offset.bytes()),
721+
ptr_offset: this.target_usize_to_isize(base_offset.bytes()),
722722
ptr_size: size,
723723
msg: CheckInAllocMsg::InboundsTest
724724
});

src/eval.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ impl MainThreadState {
236236
this.machine.main_fn_ret_place.unwrap().ptr,
237237
this.machine.layouts.isize,
238238
);
239-
let exit_code = this.read_machine_isize(&ret_place.into())?;
239+
let exit_code = this.read_target_isize(&ret_place.into())?;
240240
// Need to call this ourselves since we are not going to return to the scheduler
241241
// loop, and we want the main thread TLS to not show up as memory leaks.
242242
this.terminate_active_thread()?;
@@ -287,7 +287,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
287287
// First argument is constructed later, because it's skipped if the entry function uses #[start].
288288

289289
// Second argument (argc): length of `config.args`.
290-
let argc = Scalar::from_machine_usize(u64::try_from(config.args.len()).unwrap(), &ecx);
290+
let argc = Scalar::from_target_usize(u64::try_from(config.args.len()).unwrap(), &ecx);
291291
// Third argument (`argv`): created from `config.args`.
292292
let argv = {
293293
// Put each argument in memory, collect pointers.

src/helpers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,10 +758,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
758758
let this = self.eval_context_mut();
759759
let seconds_place = this.mplace_field(tp, 0)?;
760760
let seconds_scalar = this.read_scalar(&seconds_place.into())?;
761-
let seconds = seconds_scalar.to_machine_isize(this)?;
761+
let seconds = seconds_scalar.to_target_isize(this)?;
762762
let nanoseconds_place = this.mplace_field(tp, 1)?;
763763
let nanoseconds_scalar = this.read_scalar(&nanoseconds_place.into())?;
764-
let nanoseconds = nanoseconds_scalar.to_machine_isize(this)?;
764+
let nanoseconds = nanoseconds_scalar.to_target_isize(this)?;
765765

766766
Ok(try {
767767
// tv_sec must be non-negative.

src/intptrcast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl<'mir, 'tcx> GlobalStateInner {
207207
.checked_add(max(size.bytes(), 1))
208208
.ok_or_else(|| err_exhaust!(AddressSpaceFull))?;
209209
// Even if `Size` didn't overflow, we might still have filled up the address space.
210-
if global_state.next_base_addr > ecx.machine_usize_max() {
210+
if global_state.next_base_addr > ecx.target_usize_max() {
211211
throw_exhaust!(AddressSpaceFull);
212212
}
213213
// Given that `next_base_addr` increases in each allocation, pushing the

src/operator.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl<'mir, 'tcx> EvalContextExt<'tcx> for super::MiriInterpCx<'mir, 'tcx> {
5656
Offset => {
5757
assert!(left.layout.ty.is_unsafe_ptr());
5858
let ptr = left.to_scalar().to_pointer(self)?;
59-
let offset = right.to_scalar().to_machine_isize(self)?;
59+
let offset = right.to_scalar().to_target_isize(self)?;
6060

6161
let pointee_ty =
6262
left.layout.ty.builtin_deref(true).expect("Offset called on non-ptr type").ty;
@@ -73,14 +73,14 @@ impl<'mir, 'tcx> EvalContextExt<'tcx> for super::MiriInterpCx<'mir, 'tcx> {
7373
// We do the actual operation with usize-typed scalars.
7474
let left = ImmTy::from_uint(ptr.addr().bytes(), self.machine.layouts.usize);
7575
let right = ImmTy::from_uint(
76-
right.to_scalar().to_machine_usize(self)?,
76+
right.to_scalar().to_target_usize(self)?,
7777
self.machine.layouts.usize,
7878
);
7979
let (result, overflowing, _ty) =
8080
self.overflowing_binary_op(bin_op, &left, &right)?;
8181
// Construct a new pointer with the provenance of `ptr` (the LHS).
8282
let result_ptr =
83-
Pointer::new(ptr.provenance, Size::from_bytes(result.to_machine_usize(self)?));
83+
Pointer::new(ptr.provenance, Size::from_bytes(result.to_target_usize(self)?));
8484
(Scalar::from_maybe_pointer(result_ptr, self), overflowing, left.layout.ty)
8585
}
8686

src/shims/backtrace.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
2424

2525
let frame_count = this.active_thread_stack().len();
2626

27-
this.write_scalar(Scalar::from_machine_usize(frame_count.try_into().unwrap(), this), dest)
27+
this.write_scalar(Scalar::from_target_usize(frame_count.try_into().unwrap(), this), dest)
2828
}
2929

3030
fn handle_miri_get_backtrace(
@@ -205,11 +205,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
205205
}
206206
1 => {
207207
this.write_scalar(
208-
Scalar::from_machine_usize(name.len().try_into().unwrap(), this),
208+
Scalar::from_target_usize(name.len().try_into().unwrap(), this),
209209
&this.mplace_field(&dest, 0)?.into(),
210210
)?;
211211
this.write_scalar(
212-
Scalar::from_machine_usize(filename.len().try_into().unwrap(), this),
212+
Scalar::from_target_usize(filename.len().try_into().unwrap(), this),
213213
&this.mplace_field(&dest, 1)?.into(),
214214
)?;
215215
}

src/shims/env.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
323323
this.assert_target_os_is_unix("getcwd");
324324

325325
let buf = this.read_pointer(buf_op)?;
326-
let size = this.read_machine_usize(size_op)?;
326+
let size = this.read_target_usize(size_op)?;
327327

328328
if let IsolatedOp::Reject(reject_with) = this.machine.isolated_op {
329329
this.reject_in_isolation("`getcwd`", reject_with)?;

src/shims/ffi_support.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
3636
ty::Int(IntTy::Isize) => {
3737
// This will fail if host != target, but then the entire FFI thing probably won't work well
3838
// in that situation.
39-
return Ok(CArg::ISize(k.to_machine_isize(cx)?.try_into().unwrap()));
39+
return Ok(CArg::ISize(k.to_target_isize(cx)?.try_into().unwrap()));
4040
}
4141
// the uints
4242
ty::Uint(UintTy::U8) => {
@@ -54,7 +54,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
5454
ty::Uint(UintTy::Usize) => {
5555
// This will fail if host != target, but then the entire FFI thing probably won't work well
5656
// in that situation.
57-
return Ok(CArg::USize(k.to_machine_usize(cx)?.try_into().unwrap()));
57+
return Ok(CArg::USize(k.to_target_usize(cx)?.try_into().unwrap()));
5858
}
5959
_ => {}
6060
}

src/shims/foreign_items.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
449449
let [ptr, out, out_size] = this.check_shim(abi, Abi::Rust, link_name, args)?;
450450
let ptr = this.read_pointer(ptr)?;
451451
let out = this.read_pointer(out)?;
452-
let out_size = this.read_scalar(out_size)?.to_machine_usize(this)?;
452+
let out_size = this.read_scalar(out_size)?.to_target_usize(this)?;
453453

454454
// The host affects program behavior here, so this requires isolation to be disabled.
455455
this.check_no_isolation("`miri_host_to_target_path`")?;
@@ -490,7 +490,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
490490
let [bytes] = this.check_shim(abi, Abi::Rust, link_name, args)?;
491491
let (ptr, len) = this.read_immediate(bytes)?.to_scalar_pair();
492492
let ptr = ptr.to_pointer(this)?;
493-
let len = len.to_machine_usize(this)?;
493+
let len = len.to_target_usize(this)?;
494494
let msg = this.read_bytes_ptr_strip_provenance(ptr, Size::from_bytes(len))?;
495495

496496
// Note: we're ignoring errors writing to host stdout/stderr.
@@ -504,15 +504,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
504504
// Standard C allocation
505505
"malloc" => {
506506
let [size] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
507-
let size = this.read_machine_usize(size)?;
507+
let size = this.read_target_usize(size)?;
508508
let res = this.malloc(size, /*zero_init:*/ false, MiriMemoryKind::C)?;
509509
this.write_pointer(res, dest)?;
510510
}
511511
"calloc" => {
512512
let [items, len] =
513513
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
514-
let items = this.read_machine_usize(items)?;
515-
let len = this.read_machine_usize(len)?;
514+
let items = this.read_target_usize(items)?;
515+
let len = this.read_target_usize(len)?;
516516
let size = items
517517
.checked_mul(len)
518518
.ok_or_else(|| err_ub_format!("overflow during calloc size computation"))?;
@@ -528,16 +528,16 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
528528
let [old_ptr, new_size] =
529529
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
530530
let old_ptr = this.read_pointer(old_ptr)?;
531-
let new_size = this.read_machine_usize(new_size)?;
531+
let new_size = this.read_target_usize(new_size)?;
532532
let res = this.realloc(old_ptr, new_size, MiriMemoryKind::C)?;
533533
this.write_pointer(res, dest)?;
534534
}
535535

536536
// Rust allocation
537537
"__rust_alloc" | "miri_alloc" => {
538538
let [size, align] = this.check_shim(abi, Abi::Rust, link_name, args)?;
539-
let size = this.read_machine_usize(size)?;
540-
let align = this.read_machine_usize(align)?;
539+
let size = this.read_target_usize(size)?;
540+
let align = this.read_target_usize(align)?;
541541

542542
let default = |this: &mut MiriInterpCx<'mir, 'tcx>| {
543543
Self::check_alloc_request(size, align)?;
@@ -569,8 +569,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
569569
}
570570
"__rust_alloc_zeroed" => {
571571
let [size, align] = this.check_shim(abi, Abi::Rust, link_name, args)?;
572-
let size = this.read_machine_usize(size)?;
573-
let align = this.read_machine_usize(align)?;
572+
let size = this.read_target_usize(size)?;
573+
let align = this.read_target_usize(align)?;
574574

575575
return this.emulate_allocator(Symbol::intern("__rg_alloc_zeroed"), |this| {
576576
Self::check_alloc_request(size, align)?;
@@ -593,8 +593,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
593593
"__rust_dealloc" | "miri_dealloc" => {
594594
let [ptr, old_size, align] = this.check_shim(abi, Abi::Rust, link_name, args)?;
595595
let ptr = this.read_pointer(ptr)?;
596-
let old_size = this.read_machine_usize(old_size)?;
597-
let align = this.read_machine_usize(align)?;
596+
let old_size = this.read_target_usize(old_size)?;
597+
let align = this.read_target_usize(align)?;
598598

599599
let default = |this: &mut MiriInterpCx<'mir, 'tcx>| {
600600
let memory_kind = match link_name.as_str() {
@@ -625,9 +625,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
625625
let [ptr, old_size, align, new_size] =
626626
this.check_shim(abi, Abi::Rust, link_name, args)?;
627627
let ptr = this.read_pointer(ptr)?;
628-
let old_size = this.read_machine_usize(old_size)?;
629-
let align = this.read_machine_usize(align)?;
630-
let new_size = this.read_machine_usize(new_size)?;
628+
let old_size = this.read_target_usize(old_size)?;
629+
let align = this.read_target_usize(align)?;
630+
let new_size = this.read_target_usize(new_size)?;
631631
// No need to check old_size; we anyway check that they match the allocation.
632632

633633
return this.emulate_allocator(Symbol::intern("__rg_realloc"), |this| {
@@ -651,7 +651,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
651651
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
652652
let left = this.read_pointer(left)?;
653653
let right = this.read_pointer(right)?;
654-
let n = Size::from_bytes(this.read_machine_usize(n)?);
654+
let n = Size::from_bytes(this.read_target_usize(n)?);
655655

656656
let result = {
657657
let left_bytes = this.read_bytes_ptr_strip_provenance(left, n)?;
@@ -672,7 +672,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
672672
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
673673
let ptr = this.read_pointer(ptr)?;
674674
let val = this.read_scalar(val)?.to_i32()?;
675-
let num = this.read_machine_usize(num)?;
675+
let num = this.read_target_usize(num)?;
676676
// The docs say val is "interpreted as unsigned char".
677677
#[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)]
678678
let val = val as u8;
@@ -696,7 +696,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
696696
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
697697
let ptr = this.read_pointer(ptr)?;
698698
let val = this.read_scalar(val)?.to_i32()?;
699-
let num = this.read_machine_usize(num)?;
699+
let num = this.read_target_usize(num)?;
700700
// The docs say val is "interpreted as unsigned char".
701701
#[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)]
702702
let val = val as u8;
@@ -717,7 +717,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
717717
let ptr = this.read_pointer(ptr)?;
718718
let n = this.read_c_str(ptr)?.len();
719719
this.write_scalar(
720-
Scalar::from_machine_usize(u64::try_from(n).unwrap(), this),
720+
Scalar::from_target_usize(u64::try_from(n).unwrap(), this),
721721
dest,
722722
)?;
723723
}

src/shims/intrinsics/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
111111
let ty_layout = this.layout_of(ty)?;
112112
let val_byte = this.read_scalar(val_byte)?.to_u8()?;
113113
let ptr = this.read_pointer(ptr)?;
114-
let count = this.read_machine_usize(count)?;
115-
// `checked_mul` enforces a too small bound (the correct one would probably be machine_isize_max),
114+
let count = this.read_target_usize(count)?;
115+
// `checked_mul` enforces a too small bound (the correct one would probably be target_isize_max),
116116
// but no actual allocation can be big enough for the difference to be noticeable.
117117
let byte_count = ty_layout.size.checked_mul(count, this).ok_or_else(|| {
118118
err_ub_format!("overflow computing total size of `{intrinsic_name}`")
@@ -124,7 +124,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
124124
let [ptr, mask] = check_arg_count(args)?;
125125

126126
let ptr = this.read_pointer(ptr)?;
127-
let mask = this.read_machine_usize(mask)?;
127+
let mask = this.read_target_usize(mask)?;
128128

129129
let masked_addr = Size::from_bytes(ptr.addr().bytes() & mask);
130130

src/shims/intrinsics/simd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
202202
}
203203
Op::WrappingOffset => {
204204
let ptr = left.to_scalar().to_pointer(this)?;
205-
let offset_count = right.to_scalar().to_machine_isize(this)?;
205+
let offset_count = right.to_scalar().to_target_isize(this)?;
206206
let pointee_ty = left.layout.ty.builtin_deref(true).unwrap().ty;
207207

208208
let pointee_size = i64::try_from(this.layout_of(pointee_ty)?.size.bytes()).unwrap();

src/shims/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
8080
return Ok(false);
8181
}
8282

83-
let req_align = this.read_machine_usize(align_op)?;
83+
let req_align = this.read_target_usize(align_op)?;
8484

8585
// Stop if the alignment is not a power of two.
8686
if !req_align.is_power_of_two() {
@@ -106,7 +106,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
106106
}
107107

108108
// Return error result (usize::MAX), and jump to caller.
109-
this.write_scalar(Scalar::from_machine_usize(this.machine_usize_max(), this), dest)?;
109+
this.write_scalar(Scalar::from_target_usize(this.target_usize_max(), this), dest)?;
110110
this.go_to_block(ret);
111111
Ok(true)
112112
}

src/shims/tls.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl<'tcx> TlsData<'tcx> {
108108
) -> InterpResult<'tcx> {
109109
match self.keys.get_mut(&key) {
110110
Some(TlsEntry { data, .. }) => {
111-
if new_data.to_machine_usize(cx)? != 0 {
111+
if new_data.to_target_usize(cx)? != 0 {
112112
trace!("TLS key {} for thread {:?} stored: {:?}", key, thread_id, new_data);
113113
data.insert(thread_id, new_data);
114114
} else {
@@ -356,7 +356,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
356356
state.last_key = Some(key);
357357
trace!("Running TLS dtor {:?} on {:?} at {:?}", instance, ptr, active_thread);
358358
assert!(
359-
!ptr.to_machine_usize(this).unwrap() != 0,
359+
!ptr.to_target_usize(this).unwrap() != 0,
360360
"data can't be NULL when dtor is called!"
361361
);
362362

0 commit comments

Comments
 (0)