Skip to content

Commit be82560

Browse files
committed
Auto merge of rust-lang#2738 - RalfJung:rustup, r=RalfJung
Rustup
2 parents 4ec960f + f93d956 commit be82560

25 files changed

+228
-63
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,7 @@ Definite bugs found:
656656
* [Data race in `thread::scope`](https://github.com/rust-lang/rust/issues/98498)
657657
* [`regex` incorrectly handling unaligned `Vec<u8>` buffers](https://www.reddit.com/r/rust/comments/vq3mmu/comment/ienc7t0?context=3)
658658
* [Incorrect use of `compare_exchange_weak` in `once_cell`](https://github.com/matklad/once_cell/issues/186)
659+
* [Dropping with unaligned pointers in `vec::IntoIter`](https://github.com/rust-lang/rust/pull/106084)
659660

660661
Violations of [Stacked Borrows] found that are likely bugs (but Stacked Borrows is currently just an experiment):
661662

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a803f313fdf8f6eb2d674d7dfb3694a2b437ee1e
1+
4f4d0586ad20c66a16d547581ca379beafece93a

src/eval.rs

Lines changed: 1 addition & 1 deletion
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_scalar(&ret_place.into())?.to_machine_isize(this)?;
239+
let exit_code = this.read_machine_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()?;

src/shims/env.rs

Lines changed: 1 addition & 1 deletion
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/shims/foreign_items.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -500,14 +500,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
500500
// Standard C allocation
501501
"malloc" => {
502502
let [size] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
503-
let size = this.read_scalar(size)?.to_machine_usize(this)?;
503+
let size = this.read_machine_usize(size)?;
504504
let res = this.malloc(size, /*zero_init:*/ false, MiriMemoryKind::C)?;
505505
this.write_pointer(res, dest)?;
506506
}
507507
"calloc" => {
508508
let [items, len] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
509-
let items = this.read_scalar(items)?.to_machine_usize(this)?;
510-
let len = this.read_scalar(len)?.to_machine_usize(this)?;
509+
let items = this.read_machine_usize(items)?;
510+
let len = this.read_machine_usize(len)?;
511511
let size =
512512
items.checked_mul(len).ok_or_else(|| err_ub_format!("overflow during calloc size computation"))?;
513513
let res = this.malloc(size, /*zero_init:*/ true, MiriMemoryKind::C)?;
@@ -521,16 +521,16 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
521521
"realloc" => {
522522
let [old_ptr, new_size] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
523523
let old_ptr = this.read_pointer(old_ptr)?;
524-
let new_size = this.read_scalar(new_size)?.to_machine_usize(this)?;
524+
let new_size = this.read_machine_usize(new_size)?;
525525
let res = this.realloc(old_ptr, new_size, MiriMemoryKind::C)?;
526526
this.write_pointer(res, dest)?;
527527
}
528528

529529
// Rust allocation
530530
"__rust_alloc" | "miri_alloc" => {
531531
let [size, align] = this.check_shim(abi, Abi::Rust, link_name, args)?;
532-
let size = this.read_scalar(size)?.to_machine_usize(this)?;
533-
let align = this.read_scalar(align)?.to_machine_usize(this)?;
532+
let size = this.read_machine_usize(size)?;
533+
let align = this.read_machine_usize(align)?;
534534

535535
let default = |this: &mut MiriInterpCx<'mir, 'tcx>| {
536536
Self::check_alloc_request(size, align)?;
@@ -561,8 +561,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
561561
}
562562
"__rust_alloc_zeroed" => {
563563
let [size, align] = this.check_shim(abi, Abi::Rust, link_name, args)?;
564-
let size = this.read_scalar(size)?.to_machine_usize(this)?;
565-
let align = this.read_scalar(align)?.to_machine_usize(this)?;
564+
let size = this.read_machine_usize(size)?;
565+
let align = this.read_machine_usize(align)?;
566566

567567
return this.emulate_allocator(Symbol::intern("__rg_alloc_zeroed"), |this| {
568568
Self::check_alloc_request(size, align)?;
@@ -581,8 +581,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
581581
"__rust_dealloc" | "miri_dealloc" => {
582582
let [ptr, old_size, align] = this.check_shim(abi, Abi::Rust, link_name, args)?;
583583
let ptr = this.read_pointer(ptr)?;
584-
let old_size = this.read_scalar(old_size)?.to_machine_usize(this)?;
585-
let align = this.read_scalar(align)?.to_machine_usize(this)?;
584+
let old_size = this.read_machine_usize(old_size)?;
585+
let align = this.read_machine_usize(align)?;
586586

587587
let default = |this: &mut MiriInterpCx<'mir, 'tcx>| {
588588
let memory_kind = match link_name.as_str() {
@@ -611,9 +611,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
611611
"__rust_realloc" => {
612612
let [ptr, old_size, align, new_size] = this.check_shim(abi, Abi::Rust, link_name, args)?;
613613
let ptr = this.read_pointer(ptr)?;
614-
let old_size = this.read_scalar(old_size)?.to_machine_usize(this)?;
615-
let align = this.read_scalar(align)?.to_machine_usize(this)?;
616-
let new_size = this.read_scalar(new_size)?.to_machine_usize(this)?;
614+
let old_size = this.read_machine_usize(old_size)?;
615+
let align = this.read_machine_usize(align)?;
616+
let new_size = this.read_machine_usize(new_size)?;
617617
// No need to check old_size; we anyway check that they match the allocation.
618618

619619
return this.emulate_allocator(Symbol::intern("__rg_realloc"), |this| {
@@ -636,7 +636,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
636636
let [left, right, n] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
637637
let left = this.read_pointer(left)?;
638638
let right = this.read_pointer(right)?;
639-
let n = Size::from_bytes(this.read_scalar(n)?.to_machine_usize(this)?);
639+
let n = Size::from_bytes(this.read_machine_usize(n)?);
640640

641641
let result = {
642642
let left_bytes = this.read_bytes_ptr_strip_provenance(left, n)?;
@@ -656,7 +656,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
656656
let [ptr, val, num] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
657657
let ptr = this.read_pointer(ptr)?;
658658
let val = this.read_scalar(val)?.to_i32()?;
659-
let num = this.read_scalar(num)?.to_machine_usize(this)?;
659+
let num = this.read_machine_usize(num)?;
660660
// The docs say val is "interpreted as unsigned char".
661661
#[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)]
662662
let val = val as u8;
@@ -679,7 +679,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
679679
let [ptr, val, num] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
680680
let ptr = this.read_pointer(ptr)?;
681681
let val = this.read_scalar(val)?.to_i32()?;
682-
let num = this.read_scalar(num)?.to_machine_usize(this)?;
682+
let num = this.read_machine_usize(num)?;
683683
// The docs say val is "interpreted as unsigned char".
684684
#[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)]
685685
let val = val as u8;

src/shims/intrinsics/mod.rs

Lines changed: 2 additions & 2 deletions
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/shims/mod.rs

Lines changed: 1 addition & 1 deletion
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/shims/unix/foreign_items.rs

Lines changed: 9 additions & 9 deletions
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/shims/unix/fs.rs

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

13081308
this.assert_target_os("linux", "readdir64");
13091309

1310-
let dirp = this.read_scalar(dirp_op)?.to_machine_usize(this)?;
1310+
let dirp = this.read_machine_usize(dirp_op)?;
13111311

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

14001400
this.assert_target_os("macos", "readdir_r");
14011401

1402-
let dirp = this.read_scalar(dirp_op)?.to_machine_usize(this)?;
1402+
let dirp = this.read_machine_usize(dirp_op)?;
14031403

14041404
// Reject if isolation is enabled.
14051405
if let IsolatedOp::Reject(reject_with) = this.machine.isolated_op {
@@ -1492,7 +1492,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
14921492
fn closedir(&mut self, dirp_op: &OpTy<'tcx, Provenance>) -> InterpResult<'tcx, i32> {
14931493
let this = self.eval_context_mut();
14941494

1495-
let dirp = this.read_scalar(dirp_op)?.to_machine_usize(this)?;
1495+
let dirp = this.read_machine_usize(dirp_op)?;
14961496

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

16571657
let pathname = this.read_path_from_c_str(this.read_pointer(pathname_op)?)?;
16581658
let buf = this.read_pointer(buf_op)?;
1659-
let bufsize = this.read_scalar(bufsize_op)?.to_machine_usize(this)?;
1659+
let bufsize = this.read_machine_usize(bufsize_op)?;
16601660

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

src/shims/unix/linux/foreign_items.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
130130
"incorrect number of arguments for syscall: got 0, expected at least 1"
131131
);
132132
}
133-
match this.read_scalar(&args[0])?.to_machine_usize(this)? {
133+
match this.read_machine_usize(&args[0])? {
134134
// `libc::syscall(NR_GETRANDOM, buf.as_mut_ptr(), buf.len(), GRND_NONBLOCK)`
135135
// is called if a `HashMap` is created the regular way (e.g. HashMap<K, V>).
136136
id if id == sys_getrandom => {
@@ -178,7 +178,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
178178
let [pid, cpusetsize, mask] =
179179
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
180180
this.read_scalar(pid)?.to_i32()?;
181-
this.read_scalar(cpusetsize)?.to_machine_usize(this)?;
181+
this.read_machine_usize(cpusetsize)?;
182182
this.deref_operand(mask)?;
183183
// FIXME: we just return an error; `num_cpus` then falls back to `sysconf`.
184184
let einval = this.eval_libc("EINVAL");
@@ -210,7 +210,7 @@ fn getrandom<'tcx>(
210210
dest: &PlaceTy<'tcx, Provenance>,
211211
) -> InterpResult<'tcx> {
212212
let ptr = this.read_pointer(ptr)?;
213-
let len = this.read_scalar(len)?.to_machine_usize(this)?;
213+
let len = this.read_machine_usize(len)?;
214214

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

src/shims/unix/macos/dlsym.rs

Lines changed: 1 addition & 1 deletion
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/shims/unix/macos/foreign_items.rs

Lines changed: 2 additions & 2 deletions
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(this.machine.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(this.machine.stack_size, this.pointer_size());
172172
this.write_scalar(stack_size, dest)?;
173173
}

src/shims/unix/thread.rs

Lines changed: 2 additions & 2 deletions
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,

0 commit comments

Comments
 (0)