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

Commit a477b81

Browse files
committed
Auto merge of rust-lang#2880 - RalfJung:sync, r=RalfJung
increase timing slack for sync tests; port tests to 2021 edition
2 parents 3d5a516 + 3309f12 commit a477b81

Some content is hidden

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

48 files changed

+115
-35
lines changed

src/tools/miri/tests/compiletest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn run_tests(mode: Mode, path: &str, target: &str, with_dependencies: bool) -> R
5252
mode,
5353
program: miri_path(),
5454
quiet: false,
55-
edition: Some("2018".into()),
55+
edition: Some("2021".into()),
5656
..Config::default()
5757
};
5858

src/tools/miri/tests/fail/concurrency/libc_pthread_create_too_few_args.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ LL | panic!()
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
99
= note: BACKTRACE:
10-
= note: inside `thread_start` at RUSTLIB/std/src/panic.rs:LL:CC
11-
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
10+
= note: inside `thread_start` at RUSTLIB/core/src/panic.rs:LL:CC
11+
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
1212

1313
error: aborting due to previous error
1414

src/tools/miri/tests/fail/concurrency/libc_pthread_create_too_many_args.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ LL | panic!()
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
99
= note: BACKTRACE:
10-
= note: inside `thread_start` at RUSTLIB/std/src/panic.rs:LL:CC
11-
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
10+
= note: inside `thread_start` at RUSTLIB/core/src/panic.rs:LL:CC
11+
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
1212

1313
error: aborting due to previous error
1414

src/tools/miri/tests/fail/data_race/alloc_read_race.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub fn main() {
2626
// 2. write
2727
unsafe {
2828
let j1 = spawn(move || {
29+
let ptr = ptr; // avoid field capturing
2930
// Concurrent allocate the memory.
3031
// Uses relaxed semantics to not generate
3132
// a release sequence.
@@ -34,6 +35,7 @@ pub fn main() {
3435
});
3536

3637
let j2 = spawn(move || {
38+
let ptr = ptr; // avoid field capturing
3739
let pointer = &*ptr.0;
3840

3941
// Note: could also error due to reading uninitialized memory, but the data-race detector triggers first.

src/tools/miri/tests/fail/data_race/alloc_write_race.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub fn main() {
2525
// 2. write
2626
unsafe {
2727
let j1 = spawn(move || {
28+
let ptr = ptr; // avoid field capturing
2829
// Concurrent allocate the memory.
2930
// Uses relaxed semantics to not generate
3031
// a release sequence.
@@ -34,6 +35,7 @@ pub fn main() {
3435
});
3536

3637
let j2 = spawn(move || {
38+
let ptr = ptr; // avoid field capturing
3739
let pointer = &*ptr.0;
3840
*pointer.load(Ordering::Relaxed) = 2; //~ ERROR: Data race detected between (1) Allocate on thread `<unnamed>` and (2) Write on thread `<unnamed>`
3941
});

src/tools/miri/tests/fail/data_race/atomic_read_na_write_race1.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ pub fn main() {
1616
let c = EvilSend(b);
1717
unsafe {
1818
let j1 = spawn(move || {
19+
let c = c; // avoid field capturing
1920
*(c.0 as *mut usize) = 32;
2021
});
2122

2223
let j2 = spawn(move || {
24+
let c = c; // avoid field capturing
2325
(&*c.0).load(Ordering::SeqCst) //~ ERROR: Data race detected between (1) Write on thread `<unnamed>` and (2) Atomic Load on thread `<unnamed>`
2426
});
2527

src/tools/miri/tests/fail/data_race/atomic_read_na_write_race2.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ pub fn main() {
1717
let c = EvilSend(b);
1818
unsafe {
1919
let j1 = spawn(move || {
20+
let c = c; // avoid field capturing
2021
let atomic_ref = &mut *c.0;
2122
atomic_ref.load(Ordering::SeqCst)
2223
});
2324

2425
let j2 = spawn(move || {
26+
let c = c; // avoid field capturing
2527
let atomic_ref = &mut *c.0;
2628
*atomic_ref.get_mut() = 32; //~ ERROR: Data race detected between (1) Atomic Load on thread `<unnamed>` and (2) Write on thread `<unnamed>`
2729
});

src/tools/miri/tests/fail/data_race/atomic_write_na_read_race1.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ pub fn main() {
1717
let c = EvilSend(b);
1818
unsafe {
1919
let j1 = spawn(move || {
20+
let c = c; // avoid field capturing
2021
let atomic_ref = &mut *c.0;
2122
atomic_ref.store(32, Ordering::SeqCst)
2223
});
2324

2425
let j2 = spawn(move || {
26+
let c = c; // avoid field capturing
2527
let atomic_ref = &mut *c.0;
2628
*atomic_ref.get_mut() //~ ERROR: Data race detected between (1) Atomic Store on thread `<unnamed>` and (2) Read on thread `<unnamed>`
2729
});

src/tools/miri/tests/fail/data_race/atomic_write_na_read_race2.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ pub fn main() {
1616
let c = EvilSend(b);
1717
unsafe {
1818
let j1 = spawn(move || {
19+
let c = c; // avoid field capturing
1920
let _val = *(c.0 as *mut usize);
2021
});
2122

2223
let j2 = spawn(move || {
24+
let c = c; // avoid field capturing
2325
(&*c.0).store(32, Ordering::SeqCst); //~ ERROR: Data race detected between (1) Read on thread `<unnamed>` and (2) Atomic Store on thread `<unnamed>`
2426
});
2527

src/tools/miri/tests/fail/data_race/atomic_write_na_write_race1.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ pub fn main() {
1616
let c = EvilSend(b);
1717
unsafe {
1818
let j1 = spawn(move || {
19+
let c = c; // avoid field capturing
1920
*(c.0 as *mut usize) = 32;
2021
});
2122

2223
let j2 = spawn(move || {
24+
let c = c; // avoid field capturing
2325
(&*c.0).store(64, Ordering::SeqCst); //~ ERROR: Data race detected between (1) Write on thread `<unnamed>` and (2) Atomic Store on thread `<unnamed>`
2426
});
2527

src/tools/miri/tests/fail/data_race/atomic_write_na_write_race2.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ pub fn main() {
1717
let c = EvilSend(b);
1818
unsafe {
1919
let j1 = spawn(move || {
20+
let c = c; // avoid field capturing
2021
let atomic_ref = &mut *c.0;
2122
atomic_ref.store(64, Ordering::SeqCst);
2223
});
2324

2425
let j2 = spawn(move || {
26+
let c = c; // avoid field capturing
2527
let atomic_ref = &mut *c.0;
2628
*atomic_ref.get_mut() = 32; //~ ERROR: Data race detected between (1) Atomic Store on thread `<unnamed>` and (2) Write on thread `<unnamed>`
2729
});

src/tools/miri/tests/fail/data_race/dangling_thread_async_race.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ fn main() {
1818

1919
let join = unsafe {
2020
spawn(move || {
21+
let c = c; // capture `c`, not just its field.
2122
*c.0 = 32;
2223
})
2324
};
@@ -34,6 +35,7 @@ fn main() {
3435

3536
let join2 = unsafe {
3637
spawn(move || {
38+
let c = c; // capture `c`, not just its field.
3739
*c.0 = 64; //~ ERROR: Data race detected between (1) Write on thread `<unnamed>` and (2) Write on thread `<unnamed>`
3840
})
3941
};

src/tools/miri/tests/fail/data_race/dangling_thread_race.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ fn main() {
1818

1919
let join = unsafe {
2020
spawn(move || {
21+
let c = c; // avoid field capturing
2122
*c.0 = 32;
2223
})
2324
};

src/tools/miri/tests/fail/data_race/dealloc_read_race1.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ pub fn main() {
2020

2121
unsafe {
2222
let j1 = spawn(move || {
23+
let ptr = ptr; // avoid field capturing
2324
let _val = *ptr.0;
2425
});
2526

2627
let j2 = spawn(move || {
28+
let ptr = ptr; // avoid field capturing
2729
__rust_dealloc(
2830
//~^ ERROR: Data race detected between (1) Read on thread `<unnamed>` and (2) Deallocate on thread `<unnamed>`
2931
ptr.0 as *mut _,

src/tools/miri/tests/fail/data_race/dealloc_read_race2.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub fn main() {
2020

2121
unsafe {
2222
let j1 = spawn(move || {
23+
let ptr = ptr; // avoid field capturing
2324
__rust_dealloc(
2425
ptr.0 as *mut _,
2526
std::mem::size_of::<usize>(),
@@ -28,6 +29,7 @@ pub fn main() {
2829
});
2930

3031
let j2 = spawn(move || {
32+
let ptr = ptr; // avoid field capturing
3133
// Also an error of the form: Data race detected between (1) Deallocate on thread `<unnamed>` and (2) Read on thread `<unnamed>`
3234
// but the invalid allocation is detected first.
3335
*ptr.0 //~ ERROR: dereferenced after this allocation got freed

src/tools/miri/tests/fail/data_race/dealloc_read_race_stack.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub fn main() {
2626
// 3. stack-deallocate
2727
unsafe {
2828
let j1 = spawn(move || {
29+
let ptr = ptr; // avoid field capturing
2930
let pointer = &*ptr.0;
3031
{
3132
let mut stack_var = 0usize;
@@ -39,6 +40,7 @@ pub fn main() {
3940
});
4041

4142
let j2 = spawn(move || {
43+
let ptr = ptr; // avoid field capturing
4244
let pointer = &*ptr.0;
4345
*pointer.load(Ordering::Acquire)
4446
});

src/tools/miri/tests/fail/data_race/dealloc_write_race1.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ pub fn main() {
1919

2020
unsafe {
2121
let j1 = spawn(move || {
22+
let ptr = ptr; // avoid field capturing
2223
*ptr.0 = 2;
2324
});
2425

2526
let j2 = spawn(move || {
27+
let ptr = ptr; // avoid field capturing
2628
__rust_dealloc(
2729
//~^ ERROR: Data race detected between (1) Write on thread `<unnamed>` and (2) Deallocate on thread `<unnamed>`
2830
ptr.0 as *mut _,

src/tools/miri/tests/fail/data_race/dealloc_write_race2.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub fn main() {
1919

2020
unsafe {
2121
let j1 = spawn(move || {
22+
let ptr = ptr; // avoid field capturing
2223
__rust_dealloc(
2324
ptr.0 as *mut _,
2425
std::mem::size_of::<usize>(),
@@ -27,6 +28,7 @@ pub fn main() {
2728
});
2829

2930
let j2 = spawn(move || {
31+
let ptr = ptr; // avoid field capturing
3032
// Also an error of the form: Data race detected between (1) Deallocate on thread `<unnamed>` and (2) Write on thread `<unnamed>`
3133
// but the invalid allocation is detected first.
3234
*ptr.0 = 2; //~ ERROR: dereferenced after this allocation got freed

src/tools/miri/tests/fail/data_race/dealloc_write_race_stack.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub fn main() {
2626
// 3. stack-deallocate
2727
unsafe {
2828
let j1 = spawn(move || {
29+
let ptr = ptr; // avoid field capturing
2930
let pointer = &*ptr.0;
3031
{
3132
let mut stack_var = 0usize;
@@ -39,6 +40,7 @@ pub fn main() {
3940
});
4041

4142
let j2 = spawn(move || {
43+
let ptr = ptr; // avoid field capturing
4244
let pointer = &*ptr.0;
4345
*pointer.load(Ordering::Acquire) = 3;
4446
});

src/tools/miri/tests/fail/data_race/enable_after_join_to_main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ pub fn main() {
2626
let c = EvilSend(b);
2727
unsafe {
2828
let j1 = spawn(move || {
29+
let c = c; // avoid field capturing
2930
*c.0 = 32;
3031
});
3132

3233
let j2 = spawn(move || {
34+
let c = c; // avoid field capturing
3335
*c.0 = 64; //~ ERROR: Data race detected between (1) Write on thread `<unnamed>` and (2) Write on thread `<unnamed>`
3436
});
3537

src/tools/miri/tests/fail/data_race/read_write_race.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ pub fn main() {
1515
let c = EvilSend(b);
1616
unsafe {
1717
let j1 = spawn(move || {
18+
let c = c; // avoid field capturing
1819
let _val = *c.0;
1920
});
2021

2122
let j2 = spawn(move || {
23+
let c = c; // avoid field capturing
2224
*c.0 = 64; //~ ERROR: Data race detected between (1) Read on thread `<unnamed>` and (2) Write on thread `<unnamed>`
2325
});
2426

src/tools/miri/tests/fail/data_race/read_write_race_stack.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub fn main() {
3131
// 5. read-value
3232
unsafe {
3333
let j1 = spawn(move || {
34+
let ptr = ptr; // avoid field capturing
3435
// Concurrent allocate the memory.
3536
// Uses relaxed semantics to not generate
3637
// a release sequence.
@@ -46,6 +47,7 @@ pub fn main() {
4647
});
4748

4849
let j2 = spawn(move || {
50+
let ptr = ptr; // avoid field capturing
4951
let pointer = &*ptr.0;
5052
*pointer.load(Ordering::Acquire) = 3;
5153
});

src/tools/miri/tests/fail/data_race/relax_acquire_race.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub fn main() {
2525
// 4. load acquire : 2
2626
unsafe {
2727
let j1 = spawn(move || {
28+
let c = c; // avoid field capturing
2829
*c.0 = 1;
2930
SYNC.store(1, Ordering::Release);
3031
});
@@ -36,6 +37,7 @@ pub fn main() {
3637
});
3738

3839
let j3 = spawn(move || {
40+
let c = c; // avoid field capturing
3941
if SYNC.load(Ordering::Acquire) == 2 {
4042
*c.0 //~ ERROR: Data race detected between (1) Write on thread `<unnamed>` and (2) Read on thread `<unnamed>`
4143
} else {

src/tools/miri/tests/fail/data_race/release_seq_race.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub fn main() {
2727
// 4. load acquire : 3
2828
unsafe {
2929
let j1 = spawn(move || {
30+
let c = c; // avoid field capturing
3031
*c.0 = 1;
3132
SYNC.store(1, Ordering::Release);
3233
sleep(Duration::from_millis(200));
@@ -39,6 +40,7 @@ pub fn main() {
3940
});
4041

4142
let j3 = spawn(move || {
43+
let c = c; // avoid field capturing
4244
sleep(Duration::from_millis(500));
4345
if SYNC.load(Ordering::Acquire) == 3 {
4446
*c.0 //~ ERROR: Data race detected between (1) Write on thread `<unnamed>` and (2) Read on thread `<unnamed>`

src/tools/miri/tests/fail/data_race/release_seq_race_same_thread.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub fn main() {
2525
// 3. load acquire : 2
2626
unsafe {
2727
let j1 = spawn(move || {
28+
let c = c; // avoid field capturing
2829
*c.0 = 1;
2930
SYNC.store(1, Ordering::Release);
3031

@@ -36,6 +37,7 @@ pub fn main() {
3637
});
3738

3839
let j2 = spawn(move || {
40+
let c = c; // avoid field capturing
3941
if SYNC.load(Ordering::Acquire) == 2 {
4042
*c.0 //~ ERROR: Data race detected between (1) Write on thread `<unnamed>` and (2) Read on thread `<unnamed>`
4143
} else {

src/tools/miri/tests/fail/data_race/rmw_race.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub fn main() {
2525
// 4. load acquire : 3
2626
unsafe {
2727
let j1 = spawn(move || {
28+
let c = c; // capture `c`, not just its field.
2829
*c.0 = 1;
2930
SYNC.store(1, Ordering::Release);
3031
});
@@ -37,6 +38,7 @@ pub fn main() {
3738
});
3839

3940
let j3 = spawn(move || {
41+
let c = c; // capture `c`, not just its field.
4042
if SYNC.load(Ordering::Acquire) == 3 {
4143
*c.0 //~ ERROR: Data race detected between (1) Write on thread `<unnamed>` and (2) Read on thread `<unnamed>`
4244
} else {

src/tools/miri/tests/fail/data_race/stack_pop_race.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn main() {
1313
fn race(local: i32) {
1414
let ptr = MakeSend(&local as *const i32);
1515
thread::spawn(move || {
16-
let ptr = ptr;
16+
let ptr = ptr; // avoid field capturing
1717
let _val = unsafe { *ptr.0 };
1818
});
1919
// Make the other thread go first so that it does not UAF.

src/tools/miri/tests/fail/data_race/write_write_race.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ pub fn main() {
1515
let c = EvilSend(b);
1616
unsafe {
1717
let j1 = spawn(move || {
18+
let c = c; // avoid field capturing
1819
*c.0 = 32;
1920
});
2021

2122
let j2 = spawn(move || {
23+
let c = c; // avoid field capturing
2224
*c.0 = 64; //~ ERROR: Data race detected between (1) Write on thread `<unnamed>` and (2) Write on thread `<unnamed>`
2325
});
2426

0 commit comments

Comments
 (0)