Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miri: Use -Zmiri-tree-borrows instead of -Zmiri-disable-stacked-borrows #996

Merged
merged 2 commits into from
Jun 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions ci/miri.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,22 @@ MIRIFLAGS="-Zmiri-strict-provenance -Zmiri-symbolic-alignment-check -Zmiri-retag
cargo miri test \
-p crossbeam-channel 2>&1 | ts -i '%.s '

# -Zmiri-disable-stacked-borrows is needed for https://github.com/crossbeam-rs/crossbeam/issues/545
MIRIFLAGS="-Zmiri-strict-provenance -Zmiri-symbolic-alignment-check -Zmiri-retag-fields -Zmiri-disable-isolation -Zmiri-disable-stacked-borrows" \
# Use Tree Borrows instead of Stacked Borrows because epoch is not compatible with Stacked Borrows: https://github.com/crossbeam-rs/crossbeam/issues/545#issuecomment-1192785003
MIRIFLAGS="-Zmiri-strict-provenance -Zmiri-symbolic-alignment-check -Zmiri-retag-fields -Zmiri-disable-isolation -Zmiri-tree-borrows" \
cargo miri test \
-p crossbeam-epoch 2>&1 | ts -i '%.s '
-p crossbeam-epoch \
-p crossbeam 2>&1 | ts -i '%.s '

# Use Tree Borrows instead of Stacked Borrows because epoch is not compatible with Stacked Borrows: https://github.com/crossbeam-rs/crossbeam/issues/545#issuecomment-1192785003
# -Zmiri-ignore-leaks is needed for https://github.com/crossbeam-rs/crossbeam/issues/614
# -Zmiri-disable-stacked-borrows is needed for https://github.com/crossbeam-rs/crossbeam/issues/545
MIRIFLAGS="-Zmiri-strict-provenance -Zmiri-symbolic-alignment-check -Zmiri-retag-fields -Zmiri-disable-isolation -Zmiri-disable-stacked-borrows -Zmiri-ignore-leaks" \
MIRIFLAGS="-Zmiri-strict-provenance -Zmiri-symbolic-alignment-check -Zmiri-retag-fields -Zmiri-disable-isolation -Zmiri-tree-borrows -Zmiri-ignore-leaks" \
cargo miri test \
-p crossbeam-skiplist 2>&1 | ts -i '%.s '

# -Zmiri-disable-stacked-borrows is needed for https://github.com/crossbeam-rs/crossbeam/issues/545
# Use Tree Borrows instead of Stacked Borrows because epoch is not compatible with Stacked Borrows: https://github.com/crossbeam-rs/crossbeam/issues/545#issuecomment-1192785003
# -Zmiri-compare-exchange-weak-failure-rate=0.0 is needed because some sequential tests (e.g.,
# doctest of Stealer::steal) incorrectly assume that sequential weak CAS will never fail.
# -Zmiri-preemption-rate=0 is needed because this code technically has UB and Miri catches that.
MIRIFLAGS="-Zmiri-strict-provenance -Zmiri-symbolic-alignment-check -Zmiri-retag-fields -Zmiri-disable-stacked-borrows -Zmiri-compare-exchange-weak-failure-rate=0.0 -Zmiri-preemption-rate=0" \
MIRIFLAGS="-Zmiri-strict-provenance -Zmiri-symbolic-alignment-check -Zmiri-retag-fields -Zmiri-disable-isolation -Zmiri-tree-borrows -Zmiri-compare-exchange-weak-failure-rate=0.0 -Zmiri-preemption-rate=0" \
cargo miri test \
-p crossbeam-deque 2>&1 | ts -i '%.s '

# -Zmiri-disable-stacked-borrows is needed for https://github.com/crossbeam-rs/crossbeam/issues/545
MIRIFLAGS="-Zmiri-strict-provenance -Zmiri-symbolic-alignment-check -Zmiri-retag-fields -Zmiri-disable-stacked-borrows" \
cargo miri test \
-p crossbeam 2>&1 | ts -i '%.s '
4 changes: 2 additions & 2 deletions crossbeam-epoch/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ include!("no_atomic.rs");
include!("build-common.rs");

fn main() {
println!("cargo:rerun-if-changed=no_atomic.rs");

let target = match env::var("TARGET") {
Ok(target) => convert_custom_linux_target(target),
Err(e) => {
Expand Down Expand Up @@ -52,6 +54,4 @@ fn main() {
if !cfg.probe_rustc_version(1, 61) {
println!("cargo:rustc-cfg=crossbeam_no_const_fn_trait_bound");
}

println!("cargo:rerun-if-changed=no_atomic.rs");
}
4 changes: 2 additions & 2 deletions crossbeam-queue/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ include!("no_atomic.rs");
include!("build-common.rs");

fn main() {
println!("cargo:rerun-if-changed=no_atomic.rs");

let target = match env::var("TARGET") {
Ok(target) => convert_custom_linux_target(target),
Err(e) => {
Expand All @@ -36,6 +38,4 @@ fn main() {
if NO_ATOMIC_CAS.contains(&&*target) {
println!("cargo:rustc-cfg=crossbeam_no_atomic_cas");
}

println!("cargo:rerun-if-changed=no_atomic.rs");
}
4 changes: 2 additions & 2 deletions crossbeam-skiplist/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ include!("no_atomic.rs");
include!("build-common.rs");

fn main() {
println!("cargo:rerun-if-changed=no_atomic.rs");

let target = match env::var("TARGET") {
Ok(target) => convert_custom_linux_target(target),
Err(e) => {
Expand All @@ -36,6 +38,4 @@ fn main() {
if NO_ATOMIC_CAS.contains(&&*target) {
println!("cargo:rustc-cfg=crossbeam_no_atomic_cas");
}

println!("cargo:rerun-if-changed=no_atomic.rs");
}
8 changes: 7 additions & 1 deletion crossbeam-utils/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ include!("no_atomic.rs");
include!("build-common.rs");

fn main() {
println!("cargo:rerun-if-changed=no_atomic.rs");

let target = match env::var("TARGET") {
Ok(target) => convert_custom_linux_target(target),
Err(e) => {
Expand Down Expand Up @@ -57,5 +59,9 @@ fn main() {
// Otherwise, assuming `"max-atomic-width" == 64` or `"max-atomic-width" == 128`.
}

println!("cargo:rerun-if-changed=no_atomic.rs");
// `cfg(sanitize = "..")` is not stabilized.
let sanitize = env::var("CARGO_CFG_SANITIZE").unwrap_or_default();
if sanitize.contains("thread") {
println!("cargo:rustc-cfg=crossbeam_sanitize_thread");
}
}
15 changes: 11 additions & 4 deletions crossbeam-utils/src/atomic/consume.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
use crate::primitive::sync::atomic::compiler_fence;
#[cfg(not(crossbeam_no_atomic))]
use core::sync::atomic::Ordering;

Expand Down Expand Up @@ -27,11 +25,17 @@ pub trait AtomicConsume {
}

#[cfg(not(crossbeam_no_atomic))]
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
// Miri doesn't support "consume" ordering and ThreadSanitizer doesn't treat
// load(Relaxed) + compiler_fence(Acquire) as "consume" load.
#[cfg(all(
any(target_arch = "arm", target_arch = "aarch64"),
not(any(miri, crossbeam_sanitize_thread)),
))]
macro_rules! impl_consume {
() => {
#[inline]
fn load_consume(&self) -> Self::Val {
use crate::primitive::sync::atomic::compiler_fence;
let result = self.load(Ordering::Relaxed);
compiler_fence(Ordering::Acquire);
result
Expand All @@ -40,7 +44,10 @@ macro_rules! impl_consume {
}

#[cfg(not(crossbeam_no_atomic))]
#[cfg(not(any(target_arch = "arm", target_arch = "aarch64")))]
#[cfg(not(all(
any(target_arch = "arm", target_arch = "aarch64"),
not(any(miri, crossbeam_sanitize_thread)),
)))]
macro_rules! impl_consume {
() => {
#[inline]
Expand Down