-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #129647 - tgross35:rollup-jume49s, r=tgross35
Rollup of 9 pull requests Successful merges: - #126985 (Implement `-Z embed-source` (DWARFv5 source code embedding extension)) - #127922 (Add unsafe to extern blocks in style guide) - #128731 (simd_shuffle intrinsic: allow argument to be passed as vector) - #128935 (More work on `zstd` compression) - #128942 (miri weak memory emulation: put previous value into initial store buffer) - #129418 (rustc: Simplify getting sysroot library directory) - #129490 (Add Trusty OS as tier 3 target) - #129536 (Add `f16` and `f128` inline ASM support for `aarch64`) - #129559 (float types: document NaN bit pattern guarantees) r? `@ghost` `@rustbot` modify labels: rollup
- Loading branch information
Showing
5 changed files
with
152 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//@compile-flags: -Zmiri-ignore-leaks -Zmiri-preemption-rate=0 | ||
|
||
// Tests showing weak memory behaviours are exhibited. All tests | ||
// return true when the desired behaviour is seen. | ||
// This is scheduler and pseudo-RNG dependent, so each test is | ||
// run multiple times until one try returns true. | ||
// Spurious failure is possible, if you are really unlucky with | ||
// the RNG and always read the latest value from the store buffer. | ||
#![feature(new_uninit)] | ||
|
||
use std::sync::atomic::*; | ||
use std::thread::spawn; | ||
|
||
#[allow(dead_code)] | ||
#[derive(Copy, Clone)] | ||
struct EvilSend<T>(pub T); | ||
|
||
unsafe impl<T> Send for EvilSend<T> {} | ||
unsafe impl<T> Sync for EvilSend<T> {} | ||
|
||
// We can't create static items because we need to run each test multiple times. | ||
fn static_uninit_atomic() -> &'static AtomicUsize { | ||
unsafe { Box::leak(Box::new_uninit()).assume_init_ref() } | ||
} | ||
|
||
fn relaxed() { | ||
let x = static_uninit_atomic(); | ||
let j1 = spawn(move || { | ||
x.store(1, Ordering::Relaxed); | ||
}); | ||
|
||
let j2 = spawn(move || x.load(Ordering::Relaxed)); //~ERROR: using uninitialized data | ||
|
||
j1.join().unwrap(); | ||
j2.join().unwrap(); | ||
} | ||
|
||
pub fn main() { | ||
// If we try often enough, we should hit UB. | ||
for _ in 0..100 { | ||
relaxed(); | ||
} | ||
} |
Oops, something went wrong.