From b67e34f5e5f2d029cb96e3d40c2aea5254f7db6d Mon Sep 17 00:00:00 2001 From: Nugine Date: Sat, 26 Nov 2022 19:05:33 +0800 Subject: [PATCH 1/2] Panics in cmpxchg16b instrinsic --- crates/core_arch/src/x86_64/cmpxchg16b.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/crates/core_arch/src/x86_64/cmpxchg16b.rs b/crates/core_arch/src/x86_64/cmpxchg16b.rs index a262932af6..16647fb9ff 100644 --- a/crates/core_arch/src/x86_64/cmpxchg16b.rs +++ b/crates/core_arch/src/x86_64/cmpxchg16b.rs @@ -37,9 +37,9 @@ use stdarch_test::assert_instr; /// The failure ordering must be [`Ordering::SeqCst`], [`Ordering::Acquire`] or /// [`Ordering::Relaxed`], or this function call is undefined. See the `Atomic*` /// documentation's `compare_exchange` function for more information. When -/// `compare_exchange` panics, this is undefined behavior. Currently this -/// function aborts the process with an undefined instruction. +/// `compare_exchange` panics, this is undefined behavior. #[inline] +#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces #[cfg_attr(test, assert_instr(cmpxchg16b, success = Ordering::SeqCst, failure = Ordering::SeqCst))] #[target_feature(enable = "cmpxchg16b")] pub unsafe fn cmpxchg16b( @@ -53,6 +53,8 @@ pub unsafe fn cmpxchg16b( debug_assert!(dst as usize % 16 == 0); + // Copied from `atomic_compare_exchange` in `core`. + // https://github.com/rust-lang/rust/blob/f8a2e49/library/core/src/sync/atomic.rs#L3046-L3079 let (val, _ok) = match (success, failure) { (Relaxed, Relaxed) => intrinsics::atomic_cxchg_relaxed_relaxed(dst, old, new), (Relaxed, Acquire) => intrinsics::atomic_cxchg_relaxed_acquire(dst, old, new), @@ -69,11 +71,12 @@ pub unsafe fn cmpxchg16b( (SeqCst, Relaxed) => intrinsics::atomic_cxchg_seqcst_relaxed(dst, old, new), (SeqCst, Acquire) => intrinsics::atomic_cxchg_seqcst_acquire(dst, old, new), (SeqCst, SeqCst) => intrinsics::atomic_cxchg_seqcst_seqcst(dst, old, new), + (_, AcqRel) => panic!("there is no such thing as an acquire-release failure ordering"), + (_, Release) => panic!("there is no such thing as a release failure ordering"), - // The above block is all copied from libcore, and this statement is - // also copied from libcore except that it's a panic in libcore and we - // have a little bit more of a lightweight panic here. - _ => crate::core_arch::x86::ud2(), + // `atomic::Ordering` is non_exhaustive. It warns when `core_arch` is built as a part of `core`. + #[allow(unreachable_patterns)] + (_, _) => unreachable!(), }; val } From 51f1c4f95f0404be6a20aa94477d7416f09c9cde Mon Sep 17 00:00:00 2001 From: Nugine Date: Sat, 26 Nov 2022 19:05:34 +0800 Subject: [PATCH 2/2] Stabilize cmpxchg16b instrinsic --- crates/core_arch/src/x86_64/cmpxchg16b.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/core_arch/src/x86_64/cmpxchg16b.rs b/crates/core_arch/src/x86_64/cmpxchg16b.rs index 16647fb9ff..574eb8305f 100644 --- a/crates/core_arch/src/x86_64/cmpxchg16b.rs +++ b/crates/core_arch/src/x86_64/cmpxchg16b.rs @@ -42,6 +42,7 @@ use stdarch_test::assert_instr; #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces #[cfg_attr(test, assert_instr(cmpxchg16b, success = Ordering::SeqCst, failure = Ordering::SeqCst))] #[target_feature(enable = "cmpxchg16b")] +#[stable(feature = "cmpxchg16b_instrinsic", since = "1.67.0")] pub unsafe fn cmpxchg16b( dst: *mut u128, old: u128,