From e9f98af48388f1897f5329c9ca2bc7dbd6e9b68f Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Sat, 17 Jun 2023 20:16:25 +0900 Subject: [PATCH] Always use load(Acquire) for load_consume on Miri/TSan --- crossbeam-epoch/build.rs | 4 ++-- crossbeam-queue/build.rs | 4 ++-- crossbeam-skiplist/build.rs | 4 ++-- crossbeam-utils/build.rs | 8 +++++++- crossbeam-utils/src/atomic/consume.rs | 12 ++++++++++-- 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/crossbeam-epoch/build.rs b/crossbeam-epoch/build.rs index 978141aa5..86c3b6ff7 100644 --- a/crossbeam-epoch/build.rs +++ b/crossbeam-epoch/build.rs @@ -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) => { @@ -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"); } diff --git a/crossbeam-queue/build.rs b/crossbeam-queue/build.rs index 6975dd8c2..ffa02a663 100644 --- a/crossbeam-queue/build.rs +++ b/crossbeam-queue/build.rs @@ -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) => { @@ -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"); } diff --git a/crossbeam-skiplist/build.rs b/crossbeam-skiplist/build.rs index 6975dd8c2..ffa02a663 100644 --- a/crossbeam-skiplist/build.rs +++ b/crossbeam-skiplist/build.rs @@ -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) => { @@ -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"); } diff --git a/crossbeam-utils/build.rs b/crossbeam-utils/build.rs index 617162fb5..39785f030 100644 --- a/crossbeam-utils/build.rs +++ b/crossbeam-utils/build.rs @@ -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) => { @@ -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"); + } } diff --git a/crossbeam-utils/src/atomic/consume.rs b/crossbeam-utils/src/atomic/consume.rs index 277b370a5..9ab0143d1 100644 --- a/crossbeam-utils/src/atomic/consume.rs +++ b/crossbeam-utils/src/atomic/consume.rs @@ -27,7 +27,12 @@ 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] @@ -40,7 +45,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]