Skip to content

Commit 7a04ff6

Browse files
committed
Gate Atomic::from_mut on cfg(target_has_atomic_equal_alignment).
Instead of a few hardcoded cfg(target_arch = ..) like before.
1 parent 668225d commit 7a04ff6

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

Diff for: library/core/src/sync/atomic.rs

+19-8
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ use self::Ordering::*;
110110
use crate::cell::UnsafeCell;
111111
use crate::fmt;
112112
use crate::intrinsics;
113+
114+
#[allow(unused_imports)]
113115
use crate::mem::align_of;
114116

115117
use crate::hint::spin_loop;
@@ -342,6 +344,7 @@ impl AtomicBool {
342344
/// assert_eq!(some_bool, false);
343345
/// ```
344346
#[inline]
347+
#[cfg(target_has_atomic_equal_alignment = "8")]
345348
#[unstable(feature = "atomic_from_mut", issue = "76314")]
346349
pub fn from_mut(v: &mut bool) -> &Self {
347350
// SAFETY: the mutable reference guarantees unique ownership, and
@@ -855,6 +858,7 @@ impl<T> AtomicPtr<T> {
855858
/// assert_eq!(unsafe { *some_ptr }, 456);
856859
/// ```
857860
#[inline]
861+
#[cfg(target_has_atomic_equal_alignment = "ptr")]
858862
#[unstable(feature = "atomic_from_mut", issue = "76314")]
859863
pub fn from_mut(v: &mut *mut T) -> &Self {
860864
let [] = [(); align_of::<AtomicPtr<()>>() - align_of::<*mut ()>()];
@@ -1159,6 +1163,7 @@ macro_rules! if_not_8_bit {
11591163
#[cfg(target_has_atomic_load_store = "8")]
11601164
macro_rules! atomic_int {
11611165
($cfg_cas:meta,
1166+
$cfg_align:meta,
11621167
$stable:meta,
11631168
$stable_cxchg:meta,
11641169
$stable_debug:meta,
@@ -1167,7 +1172,6 @@ macro_rules! atomic_int {
11671172
$stable_nand:meta,
11681173
$const_stable:meta,
11691174
$stable_init_const:meta,
1170-
$(from_mut: cfg($from_mut_cfg:meta),)?
11711175
$s_int_type:literal, $int_ref:expr,
11721176
$extra_feature:expr,
11731177
$min_fn:ident, $max_fn:ident,
@@ -1304,15 +1308,14 @@ assert_eq!(some_int, 100);
13041308
```
13051309
"),
13061310
#[inline]
1307-
$(#[cfg($from_mut_cfg)])?
1311+
#[$cfg_align]
13081312
#[unstable(feature = "atomic_from_mut", issue = "76314")]
13091313
pub fn from_mut(v: &mut $int_type) -> &Self {
13101314
let [] = [(); align_of::<Self>() - align_of::<$int_type>()];
13111315
// SAFETY:
13121316
// - the mutable reference guarantees unique ownership.
13131317
// - the alignment of `$int_type` and `Self` is the
1314-
// same on all platforms enabled by `$from_mut_cfg`
1315-
// as verified above.
1318+
// same, as promised by $cfg_align and verified above.
13161319
unsafe { &*(v as *mut $int_type as *mut Self) }
13171320
}
13181321
}
@@ -1959,6 +1962,7 @@ let mut atomic = ", stringify!($atomic_type), "::new(1);
19591962
#[cfg(target_has_atomic_load_store = "8")]
19601963
atomic_int! {
19611964
cfg(target_has_atomic = "8"),
1965+
cfg(target_has_atomic_equal_alignment = "8"),
19621966
stable(feature = "integer_atomics_stable", since = "1.34.0"),
19631967
stable(feature = "integer_atomics_stable", since = "1.34.0"),
19641968
stable(feature = "integer_atomics_stable", since = "1.34.0"),
@@ -1977,6 +1981,7 @@ atomic_int! {
19771981
#[cfg(target_has_atomic_load_store = "8")]
19781982
atomic_int! {
19791983
cfg(target_has_atomic = "8"),
1984+
cfg(target_has_atomic_equal_alignment = "8"),
19801985
stable(feature = "integer_atomics_stable", since = "1.34.0"),
19811986
stable(feature = "integer_atomics_stable", since = "1.34.0"),
19821987
stable(feature = "integer_atomics_stable", since = "1.34.0"),
@@ -1995,6 +2000,7 @@ atomic_int! {
19952000
#[cfg(target_has_atomic_load_store = "16")]
19962001
atomic_int! {
19972002
cfg(target_has_atomic = "16"),
2003+
cfg(target_has_atomic_equal_alignment = "16"),
19982004
stable(feature = "integer_atomics_stable", since = "1.34.0"),
19992005
stable(feature = "integer_atomics_stable", since = "1.34.0"),
20002006
stable(feature = "integer_atomics_stable", since = "1.34.0"),
@@ -2013,6 +2019,7 @@ atomic_int! {
20132019
#[cfg(target_has_atomic_load_store = "16")]
20142020
atomic_int! {
20152021
cfg(target_has_atomic = "16"),
2022+
cfg(target_has_atomic_equal_alignment = "16"),
20162023
stable(feature = "integer_atomics_stable", since = "1.34.0"),
20172024
stable(feature = "integer_atomics_stable", since = "1.34.0"),
20182025
stable(feature = "integer_atomics_stable", since = "1.34.0"),
@@ -2031,6 +2038,7 @@ atomic_int! {
20312038
#[cfg(target_has_atomic_load_store = "32")]
20322039
atomic_int! {
20332040
cfg(target_has_atomic = "32"),
2041+
cfg(target_has_atomic_equal_alignment = "32"),
20342042
stable(feature = "integer_atomics_stable", since = "1.34.0"),
20352043
stable(feature = "integer_atomics_stable", since = "1.34.0"),
20362044
stable(feature = "integer_atomics_stable", since = "1.34.0"),
@@ -2049,6 +2057,7 @@ atomic_int! {
20492057
#[cfg(target_has_atomic_load_store = "32")]
20502058
atomic_int! {
20512059
cfg(target_has_atomic = "32"),
2060+
cfg(target_has_atomic_equal_alignment = "32"),
20522061
stable(feature = "integer_atomics_stable", since = "1.34.0"),
20532062
stable(feature = "integer_atomics_stable", since = "1.34.0"),
20542063
stable(feature = "integer_atomics_stable", since = "1.34.0"),
@@ -2067,6 +2076,7 @@ atomic_int! {
20672076
#[cfg(target_has_atomic_load_store = "64")]
20682077
atomic_int! {
20692078
cfg(target_has_atomic = "64"),
2079+
cfg(target_has_atomic_equal_alignment = "64"),
20702080
stable(feature = "integer_atomics_stable", since = "1.34.0"),
20712081
stable(feature = "integer_atomics_stable", since = "1.34.0"),
20722082
stable(feature = "integer_atomics_stable", since = "1.34.0"),
@@ -2075,7 +2085,6 @@ atomic_int! {
20752085
stable(feature = "integer_atomics_stable", since = "1.34.0"),
20762086
rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"),
20772087
unstable(feature = "integer_atomics", issue = "32976"),
2078-
from_mut: cfg(not(target_arch = "x86")),
20792088
"i64", "../../../std/primitive.i64.html",
20802089
"",
20812090
atomic_min, atomic_max,
@@ -2086,6 +2095,7 @@ atomic_int! {
20862095
#[cfg(target_has_atomic_load_store = "64")]
20872096
atomic_int! {
20882097
cfg(target_has_atomic = "64"),
2098+
cfg(target_has_atomic_equal_alignment = "64"),
20892099
stable(feature = "integer_atomics_stable", since = "1.34.0"),
20902100
stable(feature = "integer_atomics_stable", since = "1.34.0"),
20912101
stable(feature = "integer_atomics_stable", since = "1.34.0"),
@@ -2094,7 +2104,6 @@ atomic_int! {
20942104
stable(feature = "integer_atomics_stable", since = "1.34.0"),
20952105
rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"),
20962106
unstable(feature = "integer_atomics", issue = "32976"),
2097-
from_mut: cfg(not(target_arch = "x86")),
20982107
"u64", "../../../std/primitive.u64.html",
20992108
"",
21002109
atomic_umin, atomic_umax,
@@ -2105,6 +2114,7 @@ atomic_int! {
21052114
#[cfg(target_has_atomic_load_store = "128")]
21062115
atomic_int! {
21072116
cfg(target_has_atomic = "128"),
2117+
cfg(target_has_atomic_equal_alignment = "128"),
21082118
unstable(feature = "integer_atomics", issue = "32976"),
21092119
unstable(feature = "integer_atomics", issue = "32976"),
21102120
unstable(feature = "integer_atomics", issue = "32976"),
@@ -2113,7 +2123,6 @@ atomic_int! {
21132123
unstable(feature = "integer_atomics", issue = "32976"),
21142124
rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"),
21152125
unstable(feature = "integer_atomics", issue = "32976"),
2116-
from_mut: cfg(not(target_arch = "x86_64")),
21172126
"i128", "../../../std/primitive.i128.html",
21182127
"#![feature(integer_atomics)]\n\n",
21192128
atomic_min, atomic_max,
@@ -2124,6 +2133,7 @@ atomic_int! {
21242133
#[cfg(target_has_atomic_load_store = "128")]
21252134
atomic_int! {
21262135
cfg(target_has_atomic = "128"),
2136+
cfg(target_has_atomic_equal_alignment = "128"),
21272137
unstable(feature = "integer_atomics", issue = "32976"),
21282138
unstable(feature = "integer_atomics", issue = "32976"),
21292139
unstable(feature = "integer_atomics", issue = "32976"),
@@ -2132,7 +2142,6 @@ atomic_int! {
21322142
unstable(feature = "integer_atomics", issue = "32976"),
21332143
rustc_const_stable(feature = "const_integer_atomics", since = "1.34.0"),
21342144
unstable(feature = "integer_atomics", issue = "32976"),
2135-
from_mut: cfg(not(target_arch = "x86_64")),
21362145
"u128", "../../../std/primitive.u128.html",
21372146
"#![feature(integer_atomics)]\n\n",
21382147
atomic_umin, atomic_umax,
@@ -2164,6 +2173,7 @@ macro_rules! ptr_width {
21642173
#[cfg(target_has_atomic_load_store = "ptr")]
21652174
atomic_int! {
21662175
cfg(target_has_atomic = "ptr"),
2176+
cfg(target_has_atomic_equal_alignment = "ptr"),
21672177
stable(feature = "rust1", since = "1.0.0"),
21682178
stable(feature = "extended_compare_and_swap", since = "1.10.0"),
21692179
stable(feature = "atomic_debug", since = "1.3.0"),
@@ -2182,6 +2192,7 @@ atomic_int! {
21822192
#[cfg(target_has_atomic_load_store = "ptr")]
21832193
atomic_int! {
21842194
cfg(target_has_atomic = "ptr"),
2195+
cfg(target_has_atomic_equal_alignment = "ptr"),
21852196
stable(feature = "rust1", since = "1.0.0"),
21862197
stable(feature = "extended_compare_and_swap", since = "1.10.0"),
21872198
stable(feature = "atomic_debug", since = "1.3.0"),

0 commit comments

Comments
 (0)