Skip to content

Commit cdc509f

Browse files
committed
Auto merge of #125580 - RalfJung:miri-sync, r=RalfJung
Miri subtree update r? `@ghost`
2 parents 529bb25 + 0963353 commit cdc509f

36 files changed

+1138
-1192
lines changed

src/tools/miri/ci/ci.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ case $HOST_TARGET in
148148
UNIX="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
149149
TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal $BASIC $UNIX threadname libc-time fs
150150
TEST_TARGET=i686-unknown-freebsd run_tests_minimal $BASIC $UNIX threadname libc-time fs
151-
TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $BASIC $UNIX pthread-sync
152-
TEST_TARGET=x86_64-pc-solaris run_tests_minimal $BASIC $UNIX pthread-sync
151+
TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $BASIC $UNIX threadname pthread-sync libc-time
152+
TEST_TARGET=x86_64-pc-solaris run_tests_minimal $BASIC $UNIX threadname pthread-sync libc-time
153153
TEST_TARGET=aarch64-linux-android run_tests_minimal $BASIC $UNIX
154154
TEST_TARGET=wasm32-wasip2 run_tests_minimal empty_main wasm heap_alloc libc-mem
155155
TEST_TARGET=wasm32-unknown-unknown run_tests_minimal empty_main wasm

src/tools/miri/miri-script/src/commands.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,13 @@ impl Command {
531531
};
532532
cmd.set_quiet(!verbose);
533533
// Add Miri flags
534-
let cmd = cmd.args(&miri_flags).args(&seed_flag).args(&early_flags).args(&flags);
534+
let mut cmd = cmd.args(&miri_flags).args(&seed_flag).args(&early_flags).args(&flags);
535+
// For `--dep` we also need to set the env var.
536+
if dep {
537+
if let Some(target) = &target {
538+
cmd = cmd.env("MIRI_TEST_TARGET", target);
539+
}
540+
}
535541
// And run the thing.
536542
Ok(cmd.run()?)
537543
};

src/tools/miri/rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6579ed89f0fcc26da71afdd11d30d63f6f812a0a
1+
21e6de7eb64c09102de3f100420a09edc1a2a8d7

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

+5-9
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,10 @@ trait EvalContextExtPriv<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
169169
size,
170170
align,
171171
memory_kind,
172-
ecx.get_active_thread(),
172+
ecx.active_thread(),
173173
) {
174-
if let Some(clock) = clock
175-
&& let Some(data_race) = &ecx.machine.data_race
176-
{
177-
data_race.acquire_clock(&clock, ecx.get_active_thread());
174+
if let Some(clock) = clock {
175+
ecx.acquire_clock(&clock);
178176
}
179177
reuse_addr
180178
} else {
@@ -369,12 +367,10 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
369367
// `alloc_id_from_addr` any more.
370368
global_state.exposed.remove(&dead_id);
371369
// Also remember this address for future reuse.
372-
let thread = self.threads.get_active_thread_id();
370+
let thread = self.threads.active_thread();
373371
global_state.reuse.add_addr(rng, addr, size, align, kind, thread, || {
374372
if let Some(data_race) = &self.data_race {
375-
data_race
376-
.release_clock(thread, self.threads.active_thread_ref().current_span())
377-
.clone()
373+
data_race.release_clock(&self.threads).clone()
378374
} else {
379375
VClock::default()
380376
}

src/tools/miri/src/alloc_bytes.rs

+24-22
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ pub struct MiriAllocBytes {
1414
layout: alloc::Layout,
1515
/// Pointer to the allocation contents.
1616
/// Invariant:
17-
/// * If `self.layout.size() == 0`, then `self.ptr` is some suitably aligned pointer
18-
/// without provenance (and no actual memory was allocated).
17+
/// * If `self.layout.size() == 0`, then `self.ptr` was allocated with the equivalent layout with size 1.
1918
/// * Otherwise, `self.ptr` points to memory allocated with `self.layout`.
2019
ptr: *mut u8,
2120
}
@@ -30,10 +29,15 @@ impl Clone for MiriAllocBytes {
3029

3130
impl Drop for MiriAllocBytes {
3231
fn drop(&mut self) {
33-
if self.layout.size() != 0 {
34-
// SAFETY: Invariant, `self.ptr` points to memory allocated with `self.layout`.
35-
unsafe { alloc::dealloc(self.ptr, self.layout) }
36-
}
32+
// We have to reconstruct the actual layout used for allocation.
33+
// (`Deref` relies on `size` so we can't just always set it to at least 1.)
34+
let alloc_layout = if self.layout.size() == 0 {
35+
Layout::from_size_align(1, self.layout.align()).unwrap()
36+
} else {
37+
self.layout
38+
};
39+
// SAFETY: Invariant, `self.ptr` points to memory allocated with `self.layout`.
40+
unsafe { alloc::dealloc(self.ptr, alloc_layout) }
3741
}
3842
}
3943

@@ -56,27 +60,25 @@ impl std::ops::DerefMut for MiriAllocBytes {
5660
}
5761

5862
impl MiriAllocBytes {
59-
/// This method factors out how a `MiriAllocBytes` object is allocated,
60-
/// specifically given an allocation function `alloc_fn`.
61-
/// `alloc_fn` is only used if `size != 0`.
62-
/// Returns `Err(layout)` if the allocation function returns a `ptr` that is `ptr.is_null()`.
63+
/// This method factors out how a `MiriAllocBytes` object is allocated, given a specific allocation function.
64+
/// If `size == 0` we allocate using a different `alloc_layout` with `size = 1`, to ensure each allocation has a unique address.
65+
/// Returns `Err(alloc_layout)` if the allocation function returns a `ptr` where `ptr.is_null()`.
6366
fn alloc_with(
6467
size: usize,
6568
align: usize,
6669
alloc_fn: impl FnOnce(Layout) -> *mut u8,
6770
) -> Result<MiriAllocBytes, Layout> {
6871
let layout = Layout::from_size_align(size, align).unwrap();
69-
let ptr = if size == 0 {
70-
std::ptr::without_provenance_mut(align)
72+
// When size is 0 we allocate 1 byte anyway, to ensure each allocation has a unique address.
73+
let alloc_layout =
74+
if size == 0 { Layout::from_size_align(1, align).unwrap() } else { layout };
75+
let ptr = alloc_fn(alloc_layout);
76+
if ptr.is_null() {
77+
Err(alloc_layout)
7178
} else {
72-
let ptr = alloc_fn(layout);
73-
if ptr.is_null() {
74-
return Err(layout);
75-
}
76-
ptr
77-
};
78-
// SAFETY: All `MiriAllocBytes` invariants are fulfilled.
79-
Ok(Self { ptr, layout })
79+
// SAFETY: All `MiriAllocBytes` invariants are fulfilled.
80+
Ok(Self { ptr, layout })
81+
}
8082
}
8183
}
8284

@@ -85,7 +87,7 @@ impl AllocBytes for MiriAllocBytes {
8587
let slice = slice.into();
8688
let size = slice.len();
8789
let align = align.bytes_usize();
88-
// SAFETY: `alloc_fn` will only be used if `size != 0`.
90+
// SAFETY: `alloc_fn` will only be used with `size != 0`.
8991
let alloc_fn = |layout| unsafe { alloc::alloc(layout) };
9092
let alloc_bytes = MiriAllocBytes::alloc_with(size, align, alloc_fn)
9193
.unwrap_or_else(|layout| alloc::handle_alloc_error(layout));
@@ -98,7 +100,7 @@ impl AllocBytes for MiriAllocBytes {
98100
fn zeroed(size: Size, align: Align) -> Option<Self> {
99101
let size = size.bytes_usize();
100102
let align = align.bytes_usize();
101-
// SAFETY: `alloc_fn` will only be used if `size != 0`.
103+
// SAFETY: `alloc_fn` will only be used with `size != 0`.
102104
let alloc_fn = |layout| unsafe { alloc::alloc_zeroed(layout) };
103105
MiriAllocBytes::alloc_with(size, align, alloc_fn).ok()
104106
}

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

+7-6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ enum PermissionPriv {
1717
/// is relevant
1818
/// - `conflicted` is set on foreign reads,
1919
/// - `conflicted` must not be set on child writes (there is UB otherwise).
20+
///
2021
/// This is so that the behavior of `Reserved` adheres to the rules of `noalias`:
2122
/// - foreign-read then child-write is UB due to `conflicted`,
2223
/// - child-write then foreign-read is UB since child-write will activate and then
@@ -339,15 +340,15 @@ pub mod diagnostics {
339340
/// This function assumes that its arguments apply to the same location
340341
/// and that they were obtained during a normal execution. It will panic otherwise.
341342
/// - all transitions involved in `self` and `err` should be increasing
342-
/// (Reserved < Active < Frozen < Disabled);
343+
/// (Reserved < Active < Frozen < Disabled);
343344
/// - between `self` and `err` the permission should also be increasing,
344-
/// so all permissions inside `err` should be greater than `self.1`;
345+
/// so all permissions inside `err` should be greater than `self.1`;
345346
/// - `Active` and `Reserved(conflicted=false)` cannot cause an error
346-
/// due to insufficient permissions, so `err` cannot be a `ChildAccessForbidden(_)`
347-
/// of either of them;
347+
/// due to insufficient permissions, so `err` cannot be a `ChildAccessForbidden(_)`
348+
/// of either of them;
348349
/// - `err` should not be `ProtectedDisabled(Disabled)`, because the protected
349-
/// tag should not have been `Disabled` in the first place (if this occurs it means
350-
/// we have unprotected tags that become protected)
350+
/// tag should not have been `Disabled` in the first place (if this occurs it means
351+
/// we have unprotected tags that become protected)
351352
pub(in super::super) fn is_relevant(&self, err: TransitionError) -> bool {
352353
// NOTE: `super::super` is the visibility of `TransitionError`
353354
assert!(self.is_possible());

src/tools/miri/src/borrow_tracker/tree_borrows/tree/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ mod spurious_read {
230230
/// - any access to the same location
231231
/// - end of one of them being protected
232232
/// - a retag that would change their relative position
233+
///
233234
/// The type `TestEvent` models these kinds of events.
234235
///
235236
/// In order to prevent `x` or `y` from losing their protector,

0 commit comments

Comments
 (0)