Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit b5bc4e1

Browse files
committed
add tests that fail due to SRW protectors
also do more iterations of weak mem consistency, since now that is no longer the slowest test ;)
1 parent 3348869 commit b5bc4e1

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

tests/pass/0concurrency_arc_drop.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// ignore-windows: Concurrency on Windows is not supported yet.
2+
use std::sync::Arc;
3+
use std::thread;
4+
5+
/// Test for Arc::drop bug (https://github.com/rust-lang/rust/issues/55005)
6+
fn main() {
7+
// The bug seems to take up to 700 iterations to reproduce with most seeds (tested 0-9).
8+
for _ in 0..700 {
9+
let arc_1 = Arc::new(());
10+
let arc_2 = arc_1.clone();
11+
let thread = thread::spawn(|| drop(arc_2));
12+
let mut i = 0;
13+
while i < 256 {
14+
i += 1;
15+
}
16+
drop(arc_1);
17+
thread.join().unwrap();
18+
}
19+
}

tests/pass/0weak_memory_consistency.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ fn test_single_thread() {
214214
}
215215

216216
pub fn main() {
217-
for _ in 0..50 {
217+
for _ in 0..75 {
218218
test_single_thread();
219219
test_mixed_access();
220220
test_load_buffering_acq_rel();

tests/pass/stacked-borrows/interior_mutability.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
// compile-flags: -Zmiri-tag-raw-pointers
12
use std::cell::{Cell, RefCell, UnsafeCell};
2-
use std::mem::MaybeUninit;
3+
use std::mem::{self, MaybeUninit};
34

45
fn main() {
56
aliasing_mut_and_shr();
67
aliasing_frz_and_shr();
78
into_interior_mutability();
89
unsafe_cell_2phase();
10+
unsafe_cell_deallocate();
11+
unsafe_cell_invalidate();
912
}
1013

1114
fn aliasing_mut_and_shr() {
@@ -67,3 +70,33 @@ fn unsafe_cell_2phase() {
6770
let _val = (*x2.get()).get(0);
6871
}
6972
}
73+
74+
/// Make sure we can deallocate an UnsafeCell that was passed to an active fn call.
75+
/// (This is the fix for https://github.com/rust-lang/rust/issues/55005.)
76+
fn unsafe_cell_deallocate() {
77+
fn f(x: &UnsafeCell<i32>) {
78+
let b: Box<i32> = unsafe { Box::from_raw(x as *const _ as *mut i32) };
79+
drop(b)
80+
}
81+
82+
let b = Box::new(0i32);
83+
f(unsafe { mem::transmute(Box::into_raw(b)) });
84+
}
85+
86+
/// As a side-effect of the above, we also allow this -- at least for now.
87+
fn unsafe_cell_invalidate() {
88+
fn f(_x: &UnsafeCell<i32>, y: *mut i32) {
89+
// Writing to y invalidates x, but that is okay.
90+
unsafe {
91+
*y += 1;
92+
}
93+
}
94+
95+
let mut x = 0i32;
96+
let raw1 = &mut x as *mut _;
97+
let ref1 = unsafe { &mut *raw1 };
98+
let raw2 = ref1 as *mut _;
99+
// Now the borrow stack is: raw1, ref2, raw2.
100+
// So using raw1 invalidates raw2.
101+
f(unsafe { mem::transmute(raw2) }, raw1);
102+
}

0 commit comments

Comments
 (0)