Skip to content

Commit ee1768c

Browse files
authored
Rollup merge of #141383 - RalfJung:miri-sync, r=RalfJung
Miri subtree update r? `@ghost`
2 parents 225ed8b + 3f0c39d commit ee1768c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+736
-201
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3116,9 +3116,9 @@ dependencies = [
31163116

31173117
[[package]]
31183118
name = "rustc-build-sysroot"
3119-
version = "0.5.5"
3119+
version = "0.5.7"
31203120
source = "registry+https://github.com/rust-lang/crates.io-index"
3121-
checksum = "fb332121f7845c6bd016f9655cf22f03c2999df936694b624a88669a78667d98"
3121+
checksum = "10edc2e4393515193bd766e2f6c050b0536a68e56f2b6d56c07ababfdc114ff0"
31223122
dependencies = [
31233123
"anyhow",
31243124
"rustc_version",

src/tools/miri/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ degree documented below):
218218
make no promises and we don't run tests for such targets.
219219
- We have unofficial support (not maintained by the Miri team itself) for some further operating systems.
220220
- `solaris` / `illumos`: maintained by @devnexen. Supports the entire test suite.
221-
- `freebsd`: maintained by @YohDeadfall. Supports `std::env` and parts of `std::{thread, fs}`, but not `std::sync`.
221+
- `freebsd`: maintained by @YohDeadfall and @LorrensP-2158466. Supports the entire test suite.
222222
- `android`: **maintainer wanted**. Support very incomplete, but a basic "hello world" works.
223223
- `wasi`: **maintainer wanted**. Support very incomplete, not even standard output works, but an empty `main` function works.
224224
- For targets on other operating systems, Miri might fail before even reaching the `main` function.

src/tools/miri/cargo-miri/Cargo.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,9 @@ dependencies = [
208208

209209
[[package]]
210210
name = "rustc-build-sysroot"
211-
version = "0.5.4"
211+
version = "0.5.7"
212212
source = "registry+https://github.com/rust-lang/crates.io-index"
213-
checksum = "d6d984a9db43148467059309bd1e5ad577085162f695d9fe2cf3543aeb25cd38"
213+
checksum = "10edc2e4393515193bd766e2f6c050b0536a68e56f2b6d56c07ababfdc114ff0"
214214
dependencies = [
215215
"anyhow",
216216
"rustc_version",

src/tools/miri/cargo-miri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ directories = "6"
1818
rustc_version = "0.4"
1919
serde_json = "1.0.40"
2020
cargo_metadata = "0.19"
21-
rustc-build-sysroot = "0.5.4"
21+
rustc-build-sysroot = "0.5.7"
2222

2323
# Enable some feature flags that dev-dependencies need but dependencies
2424
# do not. This makes `./miri install` after `./miri build` faster.

src/tools/miri/ci/ci.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,17 @@ case $HOST_TARGET in
156156
MANY_SEEDS=64 TEST_TARGET=i686-pc-windows-gnu run_tests
157157
MANY_SEEDS=64 TEST_TARGET=x86_64-pc-windows-msvc CARGO_MIRI_ENV=1 run_tests
158158
# Extra tier 2
159-
TEST_TARGET=arm-unknown-linux-gnueabi run_tests
160-
TEST_TARGET=s390x-unknown-linux-gnu run_tests # big-endian architecture of choice
159+
MANY_SEEDS=16 TEST_TARGET=arm-unknown-linux-gnueabi run_tests
160+
MANY_SEEDS=16 TEST_TARGET=s390x-unknown-linux-gnu run_tests # big-endian architecture of choice
161161
# Not officially supported tier 2
162-
TEST_TARGET=x86_64-unknown-illumos run_tests
163-
TEST_TARGET=x86_64-pc-solaris run_tests
162+
MANY_SEEDS=16 TEST_TARGET=mips-unknown-linux-gnu run_tests # a 32bit big-endian target, and also a target without 64bit atomics
163+
MANY_SEEDS=16 TEST_TARGET=x86_64-unknown-illumos run_tests
164+
MANY_SEEDS=16 TEST_TARGET=x86_64-pc-solaris run_tests
165+
MANY_SEEDS=16 TEST_TARGET=x86_64-unknown-freebsd run_tests
166+
MANY_SEEDS=16 TEST_TARGET=i686-unknown-freebsd run_tests
164167
# Partially supported targets (tier 2)
165168
BASIC="empty_main integer heap_alloc libc-mem vec string btreemap" # ensures we have the basics: pre-main code, system allocator
166169
UNIX="hello panic/panic panic/unwind concurrency/simple atomic libc-mem libc-misc libc-random env num_cpus" # the things that are very similar across all Unixes, and hence easily supported there
167-
TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal $BASIC $UNIX time hashmap random thread sync concurrency fs libc-pipe
168-
TEST_TARGET=i686-unknown-freebsd run_tests_minimal $BASIC $UNIX time hashmap random thread sync concurrency fs libc-pipe
169170
TEST_TARGET=aarch64-linux-android run_tests_minimal $BASIC $UNIX time hashmap random thread sync concurrency epoll eventfd
170171
TEST_TARGET=wasm32-wasip2 run_tests_minimal $BASIC wasm
171172
TEST_TARGET=wasm32-unknown-unknown run_tests_minimal no_std empty_main wasm # this target doesn't really have std

src/tools/miri/rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ac17c3486c6fdfbb0c3c18b99f3d8dfbff625d29
1+
2b96ddca1272960623e41829439df8dae82d20af

src/tools/miri/src/alloc_addresses/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
168168
AllocKind::Dead => unreachable!(),
169169
};
170170
// We don't have to expose this pointer yet, we do that in `prepare_for_native_call`.
171-
return interp_ok(base_ptr.addr().try_into().unwrap());
171+
return interp_ok(base_ptr.addr().to_u64());
172172
}
173173
// We are not in native lib mode, so we control the addresses ourselves.
174174
if let Some((reuse_addr, clock)) = global_state.reuse.take_addr(

src/tools/miri/src/alloc_addresses/reuse_pool.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use rand::Rng;
44
use rustc_abi::{Align, Size};
55

66
use crate::concurrency::VClock;
7+
use crate::helpers::ToUsize as _;
78
use crate::{MemoryKind, MiriConfig, ThreadId};
89

910
const MAX_POOL_SIZE: usize = 64;
@@ -46,7 +47,7 @@ impl ReusePool {
4647
}
4748

4849
fn subpool(&mut self, align: Align) -> &mut Vec<(u64, Size, ThreadId, VClock)> {
49-
let pool_idx: usize = align.bytes().trailing_zeros().try_into().unwrap();
50+
let pool_idx: usize = align.bytes().trailing_zeros().to_usize();
5051
if self.pool.len() <= pool_idx {
5152
self.pool.resize(pool_idx + 1, Vec::new());
5253
}

src/tools/miri/src/alloc_bytes.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use std::{alloc, slice};
55
use rustc_abi::{Align, Size};
66
use rustc_middle::mir::interpret::AllocBytes;
77

8+
use crate::helpers::ToU64 as _;
9+
810
/// Allocation bytes that explicitly handle the layout of the data they're storing.
911
/// This is necessary to interface with native code that accesses the program store in Miri.
1012
#[derive(Debug)]
@@ -21,7 +23,7 @@ pub struct MiriAllocBytes {
2123
impl Clone for MiriAllocBytes {
2224
fn clone(&self) -> Self {
2325
let bytes: Cow<'_, [u8]> = Cow::Borrowed(self);
24-
let align = Align::from_bytes(self.layout.align().try_into().unwrap()).unwrap();
26+
let align = Align::from_bytes(self.layout.align().to_u64()).unwrap();
2527
MiriAllocBytes::from_bytes(bytes, align)
2628
}
2729
}
@@ -90,7 +92,7 @@ impl AllocBytes for MiriAllocBytes {
9092
let align = align.bytes();
9193
// SAFETY: `alloc_fn` will only be used with `size != 0`.
9294
let alloc_fn = |layout| unsafe { alloc::alloc(layout) };
93-
let alloc_bytes = MiriAllocBytes::alloc_with(size.try_into().unwrap(), align, alloc_fn)
95+
let alloc_bytes = MiriAllocBytes::alloc_with(size.to_u64(), align, alloc_fn)
9496
.unwrap_or_else(|()| {
9597
panic!("Miri ran out of memory: cannot create allocation of {size} bytes")
9698
});

src/tools/miri/src/borrow_tracker/tree_borrows/unimap.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ use std::mem;
1717

1818
use rustc_data_structures::fx::FxHashMap;
1919

20+
use crate::helpers::ToUsize;
21+
2022
/// Intermediate key between a UniKeyMap and a UniValMap.
2123
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
2224
pub struct UniIndex {
@@ -158,7 +160,7 @@ where
158160
impl<V> UniValMap<V> {
159161
/// Whether this index has an associated value.
160162
pub fn contains_idx(&self, idx: UniIndex) -> bool {
161-
self.data.get(idx.idx as usize).and_then(Option::as_ref).is_some()
163+
self.data.get(idx.idx.to_usize()).and_then(Option::as_ref).is_some()
162164
}
163165

164166
/// Reserve enough space to insert the value at the right index.
@@ -174,29 +176,29 @@ impl<V> UniValMap<V> {
174176

175177
/// Assign a value to the index. Permanently overwrites any previous value.
176178
pub fn insert(&mut self, idx: UniIndex, val: V) {
177-
self.extend_to_length(idx.idx as usize + 1);
178-
self.data[idx.idx as usize] = Some(val)
179+
self.extend_to_length(idx.idx.to_usize() + 1);
180+
self.data[idx.idx.to_usize()] = Some(val)
179181
}
180182

181183
/// Get the value at this index, if it exists.
182184
pub fn get(&self, idx: UniIndex) -> Option<&V> {
183-
self.data.get(idx.idx as usize).and_then(Option::as_ref)
185+
self.data.get(idx.idx.to_usize()).and_then(Option::as_ref)
184186
}
185187

186188
/// Get the value at this index mutably, if it exists.
187189
pub fn get_mut(&mut self, idx: UniIndex) -> Option<&mut V> {
188-
self.data.get_mut(idx.idx as usize).and_then(Option::as_mut)
190+
self.data.get_mut(idx.idx.to_usize()).and_then(Option::as_mut)
189191
}
190192

191193
/// Delete any value associated with this index.
192194
/// Returns None if the value was not present, otherwise
193195
/// returns the previously stored value.
194196
pub fn remove(&mut self, idx: UniIndex) -> Option<V> {
195-
if idx.idx as usize >= self.data.len() {
197+
if idx.idx.to_usize() >= self.data.len() {
196198
return None;
197199
}
198200
let mut res = None;
199-
mem::swap(&mut res, &mut self.data[idx.idx as usize]);
201+
mem::swap(&mut res, &mut self.data[idx.idx.to_usize()]);
200202
res
201203
}
202204
}
@@ -209,8 +211,8 @@ pub struct UniEntry<'a, V> {
209211
impl<'a, V> UniValMap<V> {
210212
/// Get a wrapper around a mutable access to the value corresponding to `idx`.
211213
pub fn entry(&'a mut self, idx: UniIndex) -> UniEntry<'a, V> {
212-
self.extend_to_length(idx.idx as usize + 1);
213-
UniEntry { inner: &mut self.data[idx.idx as usize] }
214+
self.extend_to_length(idx.idx.to_usize() + 1);
215+
UniEntry { inner: &mut self.data[idx.idx.to_usize()] }
214216
}
215217
}
216218

src/tools/miri/src/concurrency/cpu_affinity.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl CpuAffinityMask {
2525
let mut this = Self([0; Self::CPU_MASK_BYTES]);
2626

2727
// the default affinity mask includes only the available CPUs
28-
for i in 0..cpu_count as usize {
28+
for i in 0..cpu_count.to_usize() {
2929
this.set(cx, i);
3030
}
3131

src/tools/miri/src/concurrency/vector_clock.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc_span::{DUMMY_SP, Span, SpanData};
77
use smallvec::SmallVec;
88

99
use super::data_race::NaReadType;
10+
use crate::helpers::ToUsize;
1011

1112
/// A vector clock index, this is associated with a thread id
1213
/// but in some cases one vector index may be shared with
@@ -157,7 +158,7 @@ impl VClock {
157158

158159
#[inline]
159160
pub(super) fn index_mut(&mut self, index: VectorIdx) -> &mut VTimestamp {
160-
self.0.as_mut_slice().get_mut(index.to_u32() as usize).unwrap()
161+
self.0.as_mut_slice().get_mut(index.to_u32().to_usize()).unwrap()
161162
}
162163

163164
/// Get a mutable slice to the internal vector with minimum `min_len`
@@ -420,7 +421,7 @@ impl Index<VectorIdx> for VClock {
420421

421422
#[inline]
422423
fn index(&self, index: VectorIdx) -> &VTimestamp {
423-
self.as_slice().get(index.to_u32() as usize).unwrap_or(&VTimestamp::ZERO)
424+
self.as_slice().get(index.to_u32().to_usize()).unwrap_or(&VTimestamp::ZERO)
424425
}
425426
}
426427

src/tools/miri/src/helpers.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,3 +1412,26 @@ pub(crate) fn windows_check_buffer_size((success, len): (bool, u64)) -> u32 {
14121412
u32::try_from(len).unwrap()
14131413
}
14141414
}
1415+
1416+
/// We don't support 16-bit systems, so let's have ergonomic conversion from `u32` to `usize`.
1417+
pub trait ToUsize {
1418+
fn to_usize(self) -> usize;
1419+
}
1420+
1421+
impl ToUsize for u32 {
1422+
fn to_usize(self) -> usize {
1423+
self.try_into().unwrap()
1424+
}
1425+
}
1426+
1427+
/// Similarly, a maximum address size of `u64` is assumed widely here, so let's have ergonomic
1428+
/// converion from `usize` to `u64`.
1429+
pub trait ToU64 {
1430+
fn to_u64(self) -> u64;
1431+
}
1432+
1433+
impl ToU64 for usize {
1434+
fn to_u64(self) -> u64 {
1435+
self.try_into().unwrap()
1436+
}
1437+
}

src/tools/miri/src/intrinsics/simd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
634634
let index_len = index.len();
635635

636636
assert_eq!(left_len, right_len);
637-
assert_eq!(index_len as u64, dest_len);
637+
assert_eq!(u64::try_from(index_len).unwrap(), dest_len);
638638

639639
for i in 0..dest_len {
640640
let src_index: u64 =

src/tools/miri/src/lib.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,7 @@
4141
rustc::potential_query_instability,
4242
rustc::untranslatable_diagnostic,
4343
)]
44-
#![warn(
45-
rust_2018_idioms,
46-
unqualified_local_imports,
47-
clippy::cast_possible_wrap, // unsigned -> signed
48-
clippy::cast_sign_loss, // signed -> unsigned
49-
clippy::cast_lossless,
50-
clippy::cast_possible_truncation,
51-
)]
44+
#![warn(rust_2018_idioms, unqualified_local_imports, clippy::as_conversions)]
5245
// Needed for rustdoc from bootstrap (with `-Znormalize-docs`).
5346
#![recursion_limit = "256"]
5447

@@ -140,7 +133,7 @@ pub use crate::eval::{
140133
AlignmentCheck, BacktraceStyle, IsolatedOp, MiriConfig, MiriEntryFnType, RejectOpWith,
141134
ValidationMode, create_ecx, eval_entry,
142135
};
143-
pub use crate::helpers::{AccessKind, EvalContextExt as _};
136+
pub use crate::helpers::{AccessKind, EvalContextExt as _, ToU64 as _, ToUsize as _};
144137
pub use crate::intrinsics::EvalContextExt as _;
145138
pub use crate::machine::{
146139
AllocExtra, DynMachineCallback, FrameExtra, MachineCallback, MemoryKind, MiriInterpCx,

src/tools/miri/src/machine.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -544,9 +544,6 @@ pub struct MiriMachine<'tcx> {
544544
/// Failure rate of compare_exchange_weak, between 0.0 and 1.0
545545
pub(crate) cmpxchg_weak_failure_rate: f64,
546546

547-
/// Corresponds to -Zmiri-mute-stdout-stderr and doesn't write the output but acts as if it succeeded.
548-
pub(crate) mute_stdout_stderr: bool,
549-
550547
/// The probability of the active thread being preempted at the end of each basic block.
551548
pub(crate) preemption_rate: f64,
552549

@@ -722,7 +719,6 @@ impl<'tcx> MiriMachine<'tcx> {
722719
track_alloc_accesses: config.track_alloc_accesses,
723720
check_alignment: config.check_alignment,
724721
cmpxchg_weak_failure_rate: config.cmpxchg_weak_failure_rate,
725-
mute_stdout_stderr: config.mute_stdout_stderr,
726722
preemption_rate: config.preemption_rate,
727723
report_progress: config.report_progress,
728724
basic_block_count: 0,
@@ -925,7 +921,6 @@ impl VisitProvenance for MiriMachine<'_> {
925921
track_alloc_accesses: _,
926922
check_alignment: _,
927923
cmpxchg_weak_failure_rate: _,
928-
mute_stdout_stderr: _,
929924
preemption_rate: _,
930925
report_progress: _,
931926
basic_block_count: _,

src/tools/miri/src/shims/backtrace.rs

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

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

28-
this.write_scalar(Scalar::from_target_usize(frame_count.try_into().unwrap(), this), dest)
28+
this.write_scalar(Scalar::from_target_usize(frame_count.to_u64(), this), dest)
2929
}
3030

3131
fn handle_miri_get_backtrace(
@@ -70,7 +70,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
7070
}
7171
1 =>
7272
for (i, ptr) in ptrs.into_iter().enumerate() {
73-
let offset = ptr_layout.size.checked_mul(i.try_into().unwrap(), this).unwrap();
73+
let offset = ptr_layout.size.checked_mul(i.to_u64(), this).unwrap();
7474

7575
let op_place = buf_place.offset(offset, ptr_layout, this)?;
7676

@@ -158,11 +158,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
158158
}
159159
1 => {
160160
this.write_scalar(
161-
Scalar::from_target_usize(name.len().try_into().unwrap(), this),
161+
Scalar::from_target_usize(name.len().to_u64(), this),
162162
&this.project_field(dest, 0)?,
163163
)?;
164164
this.write_scalar(
165-
Scalar::from_target_usize(filename.len().try_into().unwrap(), this),
165+
Scalar::from_target_usize(filename.len().to_u64(), this),
166166
&this.project_field(dest, 1)?,
167167
)?;
168168
}

src/tools/miri/src/shims/files.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,10 @@ pub trait FileDescription: std::fmt::Debug + FileDescriptionExt {
135135

136136
/// Reads as much as possible into the given buffer `ptr`.
137137
/// `len` indicates how many bytes we should try to read.
138-
/// `dest` is where the return value should be stored: number of bytes read, or `-1` in case of error.
138+
///
139+
/// When the read is done, `finish` will be called. Note that `read` itself may return before
140+
/// that happens! Everything that should happen "after" the `read` needs to happen inside
141+
/// `finish`.
139142
fn read<'tcx>(
140143
self: FileDescriptionRef<Self>,
141144
_communicate_allowed: bool,
@@ -149,7 +152,10 @@ pub trait FileDescription: std::fmt::Debug + FileDescriptionExt {
149152

150153
/// Writes as much as possible from the given buffer `ptr`.
151154
/// `len` indicates how many bytes we should try to write.
152-
/// `dest` is where the return value should be stored: number of bytes written, or `-1` in case of error.
155+
///
156+
/// When the write is done, `finish` will be called. Note that `write` itself may return before
157+
/// that happens! Everything that should happen "after" the `write` needs to happen inside
158+
/// `finish`.
153159
fn write<'tcx>(
154160
self: FileDescriptionRef<Self>,
155161
_communicate_allowed: bool,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
639639
let val = this.read_scalar(val)?.to_i32()?;
640640
let num = this.read_target_usize(num)?;
641641
// The docs say val is "interpreted as unsigned char".
642-
#[expect(clippy::cast_sign_loss, clippy::cast_possible_truncation)]
642+
#[expect(clippy::as_conversions)]
643643
let val = val as u8;
644644

645645
// C requires that this must always be a valid pointer (C18 §7.1.4).
@@ -665,7 +665,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
665665
let val = this.read_scalar(val)?.to_i32()?;
666666
let num = this.read_target_usize(num)?;
667667
// The docs say val is "interpreted as unsigned char".
668-
#[expect(clippy::cast_sign_loss, clippy::cast_possible_truncation)]
668+
#[expect(clippy::as_conversions)]
669669
let val = val as u8;
670670

671671
// C requires that this must always be a valid pointer (C18 §7.1.4).
@@ -676,7 +676,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
676676
.iter()
677677
.position(|&c| c == val);
678678
if let Some(idx) = idx {
679-
let new_ptr = ptr.wrapping_offset(Size::from_bytes(idx as u64), this);
679+
let new_ptr = ptr.wrapping_offset(Size::from_bytes(idx), this);
680680
this.write_pointer(new_ptr, dest)?;
681681
} else {
682682
this.write_null(dest)?;

0 commit comments

Comments
 (0)