Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6d12349

Browse files
authoredDec 21, 2022
Rollup merge of rust-lang#105602 - RalfJung:read-convenience, r=oli-obk
interpret: add read_machine_[ui]size convenience methods We have `read_pointer`, so it felt inconsistent to not also have these. r? `@oli-obk`
2 parents 7ce7169 + 1588944 commit 6d12349

File tree

18 files changed

+71
-60
lines changed

18 files changed

+71
-60
lines changed
 

‎compiler/rustc_const_eval/src/interpret/intrinsics.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -303,15 +303,15 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
303303
}
304304
sym::offset => {
305305
let ptr = self.read_pointer(&args[0])?;
306-
let offset_count = self.read_scalar(&args[1])?.to_machine_isize(self)?;
306+
let offset_count = self.read_machine_isize(&args[1])?;
307307
let pointee_ty = substs.type_at(0);
308308

309309
let offset_ptr = self.ptr_offset_inbounds(ptr, pointee_ty, offset_count)?;
310310
self.write_pointer(offset_ptr, dest)?;
311311
}
312312
sym::arith_offset => {
313313
let ptr = self.read_pointer(&args[0])?;
314-
let offset_count = self.read_scalar(&args[1])?.to_machine_isize(self)?;
314+
let offset_count = self.read_machine_isize(&args[1])?;
315315
let pointee_ty = substs.type_at(0);
316316

317317
let pointee_size = i64::try_from(self.layout_of(pointee_ty)?.size.bytes()).unwrap();
@@ -668,7 +668,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
668668
count: &OpTy<'tcx, <M as Machine<'mir, 'tcx>>::Provenance>,
669669
nonoverlapping: bool,
670670
) -> InterpResult<'tcx> {
671-
let count = self.read_scalar(&count)?.to_machine_usize(self)?;
671+
let count = self.read_machine_usize(&count)?;
672672
let layout = self.layout_of(src.layout.ty.builtin_deref(true).unwrap().ty)?;
673673
let (size, align) = (layout.size, layout.align.abi);
674674
// `checked_mul` enforces a too small bound (the correct one would probably be machine_isize_max),
@@ -696,7 +696,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
696696

697697
let dst = self.read_pointer(&dst)?;
698698
let byte = self.read_scalar(&byte)?.to_u8()?;
699-
let count = self.read_scalar(&count)?.to_machine_usize(self)?;
699+
let count = self.read_machine_usize(&count)?;
700700

701701
// `checked_mul` enforces a too small bound (the correct one would probably be machine_isize_max),
702702
// but no actual allocation can be big enough for the difference to be noticeable.

‎compiler/rustc_const_eval/src/interpret/operand.rs

+11
Original file line numberDiff line numberDiff line change
@@ -404,13 +404,24 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
404404
Ok(self.read_immediate(op)?.to_scalar())
405405
}
406406

407+
// Pointer-sized reads are fairly common and need target layout access, so we wrap them in
408+
// convenience functions.
409+
407410
/// Read a pointer from a place.
408411
pub fn read_pointer(
409412
&self,
410413
op: &OpTy<'tcx, M::Provenance>,
411414
) -> InterpResult<'tcx, Pointer<Option<M::Provenance>>> {
412415
self.read_scalar(op)?.to_pointer(self)
413416
}
417+
/// Read a pointer-sized unsigned integer from a place.
418+
pub fn read_machine_usize(&self, op: &OpTy<'tcx, M::Provenance>) -> InterpResult<'tcx, u64> {
419+
self.read_scalar(op)?.to_machine_usize(self)
420+
}
421+
/// Read a pointer-sized signed integer from a place.
422+
pub fn read_machine_isize(&self, op: &OpTy<'tcx, M::Provenance>) -> InterpResult<'tcx, i64> {
423+
self.read_scalar(op)?.to_machine_isize(self)
424+
}
414425

415426
/// Turn the wide MPlace into a string (must already be dereferenced!)
416427
pub fn read_str(&self, mplace: &MPlaceTy<'tcx, M::Provenance>) -> InterpResult<'tcx, &str> {

‎compiler/rustc_const_eval/src/interpret/projection.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ where
363363
Index(local) => {
364364
let layout = self.layout_of(self.tcx.types.usize)?;
365365
let n = self.local_to_op(self.frame(), local, Some(layout))?;
366-
let n = self.read_scalar(&n)?.to_machine_usize(self)?;
366+
let n = self.read_machine_usize(&n)?;
367367
self.place_index(base, n)?
368368
}
369369
ConstantIndex { offset, min_length, from_end } => {
@@ -392,7 +392,7 @@ where
392392
Index(local) => {
393393
let layout = self.layout_of(self.tcx.types.usize)?;
394394
let n = self.local_to_op(self.frame(), local, Some(layout))?;
395-
let n = self.read_scalar(&n)?.to_machine_usize(self)?;
395+
let n = self.read_machine_usize(&n)?;
396396
self.operand_index(base, n)?
397397
}
398398
ConstantIndex { offset, min_length, from_end } => {

‎src/tools/miri/src/eval.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ impl MainThreadState {
233233
this.machine.main_fn_ret_place.unwrap().ptr,
234234
this.machine.layouts.isize,
235235
);
236-
let exit_code = this.read_scalar(&ret_place.into())?.to_machine_isize(this)?;
236+
let exit_code = this.read_machine_isize(&ret_place.into())?;
237237
// Need to call this ourselves since we are not going to return to the scheduler
238238
// loop, and we want the main thread TLS to not show up as memory leaks.
239239
this.terminate_active_thread()?;

‎src/tools/miri/src/shims/env.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
321321
this.assert_target_os_is_unix("getcwd");
322322

323323
let buf = this.read_pointer(buf_op)?;
324-
let size = this.read_scalar(size_op)?.to_machine_usize(&*this.tcx)?;
324+
let size = this.read_machine_usize(size_op)?;
325325

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

‎src/tools/miri/src/shims/foreign_items.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -485,14 +485,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
485485
// Standard C allocation
486486
"malloc" => {
487487
let [size] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
488-
let size = this.read_scalar(size)?.to_machine_usize(this)?;
488+
let size = this.read_machine_usize(size)?;
489489
let res = this.malloc(size, /*zero_init:*/ false, MiriMemoryKind::C)?;
490490
this.write_pointer(res, dest)?;
491491
}
492492
"calloc" => {
493493
let [items, len] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
494-
let items = this.read_scalar(items)?.to_machine_usize(this)?;
495-
let len = this.read_scalar(len)?.to_machine_usize(this)?;
494+
let items = this.read_machine_usize(items)?;
495+
let len = this.read_machine_usize(len)?;
496496
let size =
497497
items.checked_mul(len).ok_or_else(|| err_ub_format!("overflow during calloc size computation"))?;
498498
let res = this.malloc(size, /*zero_init:*/ true, MiriMemoryKind::C)?;
@@ -506,16 +506,16 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
506506
"realloc" => {
507507
let [old_ptr, new_size] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
508508
let old_ptr = this.read_pointer(old_ptr)?;
509-
let new_size = this.read_scalar(new_size)?.to_machine_usize(this)?;
509+
let new_size = this.read_machine_usize(new_size)?;
510510
let res = this.realloc(old_ptr, new_size, MiriMemoryKind::C)?;
511511
this.write_pointer(res, dest)?;
512512
}
513513

514514
// Rust allocation
515515
"__rust_alloc" | "miri_alloc" => {
516516
let [size, align] = this.check_shim(abi, Abi::Rust, link_name, args)?;
517-
let size = this.read_scalar(size)?.to_machine_usize(this)?;
518-
let align = this.read_scalar(align)?.to_machine_usize(this)?;
517+
let size = this.read_machine_usize(size)?;
518+
let align = this.read_machine_usize(align)?;
519519

520520
let default = |this: &mut MiriInterpCx<'mir, 'tcx>| {
521521
Self::check_alloc_request(size, align)?;
@@ -546,8 +546,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
546546
}
547547
"__rust_alloc_zeroed" => {
548548
let [size, align] = this.check_shim(abi, Abi::Rust, link_name, args)?;
549-
let size = this.read_scalar(size)?.to_machine_usize(this)?;
550-
let align = this.read_scalar(align)?.to_machine_usize(this)?;
549+
let size = this.read_machine_usize(size)?;
550+
let align = this.read_machine_usize(align)?;
551551

552552
return this.emulate_allocator(Symbol::intern("__rg_alloc_zeroed"), |this| {
553553
Self::check_alloc_request(size, align)?;
@@ -566,8 +566,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
566566
"__rust_dealloc" | "miri_dealloc" => {
567567
let [ptr, old_size, align] = this.check_shim(abi, Abi::Rust, link_name, args)?;
568568
let ptr = this.read_pointer(ptr)?;
569-
let old_size = this.read_scalar(old_size)?.to_machine_usize(this)?;
570-
let align = this.read_scalar(align)?.to_machine_usize(this)?;
569+
let old_size = this.read_machine_usize(old_size)?;
570+
let align = this.read_machine_usize(align)?;
571571

572572
let default = |this: &mut MiriInterpCx<'mir, 'tcx>| {
573573
let memory_kind = match link_name.as_str() {
@@ -596,9 +596,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
596596
"__rust_realloc" => {
597597
let [ptr, old_size, align, new_size] = this.check_shim(abi, Abi::Rust, link_name, args)?;
598598
let ptr = this.read_pointer(ptr)?;
599-
let old_size = this.read_scalar(old_size)?.to_machine_usize(this)?;
600-
let align = this.read_scalar(align)?.to_machine_usize(this)?;
601-
let new_size = this.read_scalar(new_size)?.to_machine_usize(this)?;
599+
let old_size = this.read_machine_usize(old_size)?;
600+
let align = this.read_machine_usize(align)?;
601+
let new_size = this.read_machine_usize(new_size)?;
602602
// No need to check old_size; we anyway check that they match the allocation.
603603

604604
return this.emulate_allocator(Symbol::intern("__rg_realloc"), |this| {
@@ -621,7 +621,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
621621
let [left, right, n] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
622622
let left = this.read_pointer(left)?;
623623
let right = this.read_pointer(right)?;
624-
let n = Size::from_bytes(this.read_scalar(n)?.to_machine_usize(this)?);
624+
let n = Size::from_bytes(this.read_machine_usize(n)?);
625625

626626
let result = {
627627
let left_bytes = this.read_bytes_ptr_strip_provenance(left, n)?;
@@ -641,7 +641,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
641641
let [ptr, val, num] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
642642
let ptr = this.read_pointer(ptr)?;
643643
let val = this.read_scalar(val)?.to_i32()?;
644-
let num = this.read_scalar(num)?.to_machine_usize(this)?;
644+
let num = this.read_machine_usize(num)?;
645645
// The docs say val is "interpreted as unsigned char".
646646
#[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)]
647647
let val = val as u8;
@@ -664,7 +664,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
664664
let [ptr, val, num] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
665665
let ptr = this.read_pointer(ptr)?;
666666
let val = this.read_scalar(val)?.to_i32()?;
667-
let num = this.read_scalar(num)?.to_machine_usize(this)?;
667+
let num = this.read_machine_usize(num)?;
668668
// The docs say val is "interpreted as unsigned char".
669669
#[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)]
670670
let val = val as u8;

‎src/tools/miri/src/shims/intrinsics/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ 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_scalar(count)?.to_machine_usize(this)?;
114+
let count = this.read_machine_usize(count)?;
115115
// `checked_mul` enforces a too small bound (the correct one would probably be machine_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(|| {
@@ -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_scalar(mask)?.to_machine_usize(this)?;
127+
let mask = this.read_machine_usize(mask)?;
128128

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

‎src/tools/miri/src/shims/mod.rs

+1-1
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_scalar(align_op)?.to_machine_usize(this)?;
83+
let req_align = this.read_machine_usize(align_op)?;
8484

8585
// Stop if the alignment is not a power of two.
8686
if !req_align.is_power_of_two() {

‎src/tools/miri/src/shims/unix/foreign_items.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
7878
let [fd, buf, count] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
7979
let fd = this.read_scalar(fd)?.to_i32()?;
8080
let buf = this.read_pointer(buf)?;
81-
let count = this.read_scalar(count)?.to_machine_usize(this)?;
81+
let count = this.read_machine_usize(count)?;
8282
let result = this.read(fd, buf, count)?;
8383
this.write_scalar(Scalar::from_machine_isize(result, this), dest)?;
8484
}
8585
"write" => {
8686
let [fd, buf, n] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
8787
let fd = this.read_scalar(fd)?.to_i32()?;
8888
let buf = this.read_pointer(buf)?;
89-
let count = this.read_scalar(n)?.to_machine_usize(this)?;
89+
let count = this.read_machine_usize(n)?;
9090
trace!("Called write({:?}, {:?}, {:?})", fd, buf, count);
9191
let result = this.write(fd, buf, count)?;
9292
// Now, `result` is the value we return back to the program.
@@ -157,8 +157,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
157157
let [fd, offset, len, advice] =
158158
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
159159
this.read_scalar(fd)?.to_i32()?;
160-
this.read_scalar(offset)?.to_machine_isize(this)?;
161-
this.read_scalar(len)?.to_machine_isize(this)?;
160+
this.read_machine_isize(offset)?;
161+
this.read_machine_isize(len)?;
162162
this.read_scalar(advice)?.to_i32()?;
163163
// fadvise is only informational, we can ignore it.
164164
this.write_null(dest)?;
@@ -191,8 +191,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
191191
"posix_memalign" => {
192192
let [ret, align, size] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
193193
let ret = this.deref_operand(ret)?;
194-
let align = this.read_scalar(align)?.to_machine_usize(this)?;
195-
let size = this.read_scalar(size)?.to_machine_usize(this)?;
194+
let align = this.read_machine_usize(align)?;
195+
let size = this.read_machine_usize(size)?;
196196
// Align must be power of 2, and also at least ptr-sized (POSIX rules).
197197
// But failure to adhere to this is not UB, it's an error condition.
198198
if !align.is_power_of_two() || align < this.pointer_size().bytes() {
@@ -216,7 +216,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
216216
// Dynamic symbol loading
217217
"dlsym" => {
218218
let [handle, symbol] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
219-
this.read_scalar(handle)?.to_machine_usize(this)?;
219+
this.read_machine_usize(handle)?;
220220
let symbol = this.read_pointer(symbol)?;
221221
let symbol_name = this.read_c_str(symbol)?;
222222
if let Some(dlsym) = Dlsym::from_str(symbol_name, &this.tcx.sess.target.os)? {
@@ -472,7 +472,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
472472
let [errnum, buf, buflen] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
473473
let errnum = this.read_scalar(errnum)?;
474474
let buf = this.read_pointer(buf)?;
475-
let buflen = this.read_scalar(buflen)?.to_machine_usize(this)?;
475+
let buflen = this.read_machine_usize(buflen)?;
476476

477477
let error = this.try_errnum_to_io_error(errnum)?;
478478
let formatted = match error {
@@ -565,7 +565,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
565565
let uid = this.read_scalar(uid)?.to_u32()?;
566566
let pwd = this.deref_operand(pwd)?;
567567
let buf = this.read_pointer(buf)?;
568-
let buflen = this.read_scalar(buflen)?.to_machine_usize(this)?;
568+
let buflen = this.read_machine_usize(buflen)?;
569569
let result = this.deref_operand(result)?;
570570

571571
// Must be for "us".

‎src/tools/miri/src/shims/unix/fs.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1293,7 +1293,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
12931293

12941294
this.assert_target_os("linux", "readdir64");
12951295

1296-
let dirp = this.read_scalar(dirp_op)?.to_machine_usize(this)?;
1296+
let dirp = this.read_machine_usize(dirp_op)?;
12971297

12981298
// Reject if isolation is enabled.
12991299
if let IsolatedOp::Reject(reject_with) = this.machine.isolated_op {
@@ -1385,7 +1385,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
13851385

13861386
this.assert_target_os("macos", "readdir_r");
13871387

1388-
let dirp = this.read_scalar(dirp_op)?.to_machine_usize(this)?;
1388+
let dirp = this.read_machine_usize(dirp_op)?;
13891389

13901390
// Reject if isolation is enabled.
13911391
if let IsolatedOp::Reject(reject_with) = this.machine.isolated_op {
@@ -1478,7 +1478,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
14781478
fn closedir(&mut self, dirp_op: &OpTy<'tcx, Provenance>) -> InterpResult<'tcx, i32> {
14791479
let this = self.eval_context_mut();
14801480

1481-
let dirp = this.read_scalar(dirp_op)?.to_machine_usize(this)?;
1481+
let dirp = this.read_machine_usize(dirp_op)?;
14821482

14831483
// Reject if isolation is enabled.
14841484
if let IsolatedOp::Reject(reject_with) = this.machine.isolated_op {
@@ -1642,7 +1642,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
16421642

16431643
let pathname = this.read_path_from_c_str(this.read_pointer(pathname_op)?)?;
16441644
let buf = this.read_pointer(buf_op)?;
1645-
let bufsize = this.read_scalar(bufsize_op)?.to_machine_usize(this)?;
1645+
let bufsize = this.read_machine_usize(bufsize_op)?;
16461646

16471647
// Reject if isolation is enabled.
16481648
if let IsolatedOp::Reject(reject_with) = this.machine.isolated_op {

‎src/tools/miri/src/shims/unix/linux/foreign_items.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
9999
"incorrect number of arguments for syscall: got 0, expected at least 1"
100100
);
101101
}
102-
match this.read_scalar(&args[0])?.to_machine_usize(this)? {
102+
match this.read_machine_usize(&args[0])? {
103103
// `libc::syscall(NR_GETRANDOM, buf.as_mut_ptr(), buf.len(), GRND_NONBLOCK)`
104104
// is called if a `HashMap` is created the regular way (e.g. HashMap<K, V>).
105105
id if id == sys_getrandom => {
@@ -147,7 +147,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
147147
let [pid, cpusetsize, mask] =
148148
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
149149
this.read_scalar(pid)?.to_i32()?;
150-
this.read_scalar(cpusetsize)?.to_machine_usize(this)?;
150+
this.read_machine_usize(cpusetsize)?;
151151
this.deref_operand(mask)?;
152152
// FIXME: we just return an error; `num_cpus` then falls back to `sysconf`.
153153
let einval = this.eval_libc("EINVAL")?;
@@ -179,7 +179,7 @@ fn getrandom<'tcx>(
179179
dest: &PlaceTy<'tcx, Provenance>,
180180
) -> InterpResult<'tcx> {
181181
let ptr = this.read_pointer(ptr)?;
182-
let len = this.read_scalar(len)?.to_machine_usize(this)?;
182+
let len = this.read_machine_usize(len)?;
183183

184184
// The only supported flags are GRND_RANDOM and GRND_NONBLOCK,
185185
// neither of which have any effect on our current PRNG.

‎src/tools/miri/src/shims/unix/macos/dlsym.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
3939
Dlsym::getentropy => {
4040
let [ptr, len] = check_arg_count(args)?;
4141
let ptr = this.read_pointer(ptr)?;
42-
let len = this.read_scalar(len)?.to_machine_usize(this)?;
42+
let len = this.read_machine_usize(len)?;
4343
this.gen_random(ptr, len)?;
4444
this.write_null(dest)?;
4545
}

‎src/tools/miri/src/shims/unix/macos/foreign_items.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
161161
// Querying system information
162162
"pthread_get_stackaddr_np" => {
163163
let [thread] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
164-
this.read_scalar(thread)?.to_machine_usize(this)?;
164+
this.read_machine_usize(thread)?;
165165
let stack_addr = Scalar::from_uint(STACK_ADDR, this.pointer_size());
166166
this.write_scalar(stack_addr, dest)?;
167167
}
168168
"pthread_get_stacksize_np" => {
169169
let [thread] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
170-
this.read_scalar(thread)?.to_machine_usize(this)?;
170+
this.read_machine_usize(thread)?;
171171
let stack_size = Scalar::from_uint(STACK_SIZE, this.pointer_size());
172172
this.write_scalar(stack_size, dest)?;
173173
}

‎src/tools/miri/src/shims/unix/thread.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
4242
throw_unsup_format!("Miri supports pthread_join only with retval==NULL");
4343
}
4444

45-
let thread_id = this.read_scalar(thread)?.to_machine_usize(this)?;
45+
let thread_id = this.read_machine_usize(thread)?;
4646
this.join_thread_exclusive(thread_id.try_into().expect("thread ID should fit in u32"))?;
4747

4848
Ok(0)
@@ -51,7 +51,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
5151
fn pthread_detach(&mut self, thread: &OpTy<'tcx, Provenance>) -> InterpResult<'tcx, i32> {
5252
let this = self.eval_context_mut();
5353

54-
let thread_id = this.read_scalar(thread)?.to_machine_usize(this)?;
54+
let thread_id = this.read_machine_usize(thread)?;
5555
this.detach_thread(
5656
thread_id.try_into().expect("thread ID should fit in u32"),
5757
/*allow_terminated_joined*/ false,

‎src/tools/miri/src/shims/windows/dlsym.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
6767
byte_offset,
6868
_key,
6969
] = check_arg_count(args)?;
70-
let handle = this.read_scalar(handle)?.to_machine_isize(this)?;
70+
let handle = this.read_machine_isize(handle)?;
7171
let buf = this.read_pointer(buf)?;
7272
let n = this.read_scalar(n)?.to_u32()?;
73-
let byte_offset = this.read_scalar(byte_offset)?.to_machine_usize(this)?; // is actually a pointer
73+
let byte_offset = this.read_machine_usize(byte_offset)?; // is actually a pointer
7474
let io_status_block = this.deref_operand(io_status_block)?;
7575

7676
if byte_offset != 0 {

‎src/tools/miri/src/shims/windows/foreign_items.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,17 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
7373
"HeapAlloc" => {
7474
let [handle, flags, size] =
7575
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?;
76-
this.read_scalar(handle)?.to_machine_isize(this)?;
76+
this.read_machine_isize(handle)?;
7777
let flags = this.read_scalar(flags)?.to_u32()?;
78-
let size = this.read_scalar(size)?.to_machine_usize(this)?;
78+
let size = this.read_machine_usize(size)?;
7979
let zero_init = (flags & 0x00000008) != 0; // HEAP_ZERO_MEMORY
8080
let res = this.malloc(size, zero_init, MiriMemoryKind::WinHeap)?;
8181
this.write_pointer(res, dest)?;
8282
}
8383
"HeapFree" => {
8484
let [handle, flags, ptr] =
8585
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?;
86-
this.read_scalar(handle)?.to_machine_isize(this)?;
86+
this.read_machine_isize(handle)?;
8787
this.read_scalar(flags)?.to_u32()?;
8888
let ptr = this.read_pointer(ptr)?;
8989
this.free(ptr, MiriMemoryKind::WinHeap)?;
@@ -92,10 +92,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
9292
"HeapReAlloc" => {
9393
let [handle, flags, ptr, size] =
9494
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?;
95-
this.read_scalar(handle)?.to_machine_isize(this)?;
95+
this.read_machine_isize(handle)?;
9696
this.read_scalar(flags)?.to_u32()?;
9797
let ptr = this.read_pointer(ptr)?;
98-
let size = this.read_scalar(size)?.to_machine_usize(this)?;
98+
let size = this.read_machine_usize(size)?;
9999
let res = this.realloc(ptr, size, MiriMemoryKind::WinHeap)?;
100100
this.write_pointer(res, dest)?;
101101
}
@@ -298,7 +298,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
298298
#[allow(non_snake_case)]
299299
let [hModule, lpProcName] =
300300
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?;
301-
this.read_scalar(hModule)?.to_machine_isize(this)?;
301+
this.read_machine_isize(hModule)?;
302302
let name = this.read_c_str(this.read_pointer(lpProcName)?)?;
303303
if let Some(dlsym) = Dlsym::from_str(name, &this.tcx.sess.target.os)? {
304304
let ptr = this.create_fn_alloc_ptr(FnVal::Other(dlsym));
@@ -356,7 +356,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
356356
// `term` needs this, so we fake it.
357357
let [console, buffer_info] =
358358
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?;
359-
this.read_scalar(console)?.to_machine_isize(this)?;
359+
this.read_machine_isize(console)?;
360360
this.deref_operand(buffer_info)?;
361361
// Indicate an error.
362362
// FIXME: we should set last_error, but to what?
@@ -432,7 +432,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
432432
"GetConsoleMode" if this.frame_in_std() => {
433433
let [console, mode] =
434434
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?;
435-
this.read_scalar(console)?.to_machine_isize(this)?;
435+
this.read_machine_isize(console)?;
436436
this.deref_operand(mode)?;
437437
// Indicate an error.
438438
this.write_null(dest)?;

‎src/tools/miri/src/shims/windows/sync.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
273273

274274
let ptr = this.read_pointer(ptr_op)?;
275275
let compare = this.read_pointer(compare_op)?;
276-
let size = this.read_scalar(size_op)?.to_machine_usize(this)?;
276+
let size = this.read_machine_usize(size_op)?;
277277
let timeout_ms = this.read_scalar(timeout_op)?.to_u32()?;
278278

279279
let thread = this.get_active_thread();

‎src/tools/miri/src/shims/windows/thread.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
2121

2222
let security = this.read_pointer(security_op)?;
2323
// stacksize is ignored, but still needs to be a valid usize
24-
this.read_scalar(stacksize_op)?.to_machine_usize(this)?;
24+
this.read_machine_usize(stacksize_op)?;
2525
let start_routine = this.read_pointer(start_op)?;
2626
let func_arg = this.read_immediate(arg_op)?;
2727
let flags = this.read_scalar(flags_op)?.to_u32()?;

0 commit comments

Comments
 (0)
Please sign in to comment.