Skip to content

Commit 5e377a8

Browse files
committed
Add target_has_atomic* symbols if any atomic width is supported
Atomic operations for different widths (8-bit, 16-bit, 32-bit etc.) are guarded by `target_has_atomic = "value"` symbol (i.e. `target_has_atomic = "8"`) (and the other derivatives), but before this change, there was no width-agnostic symbol indicating a general availability of atomic operations. This change introduces: * `target_has_atomic_load_store` symbol when atomics for any integer width are supported by the target. * `target_has_atomic` symbol when also CAS is supported. Fixes #106845 Signed-off-by: Michal Rostecki <[email protected]>
1 parent 44a500c commit 5e377a8

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

compiler/rustc_session/src/config.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,7 @@ fn default_configuration(sess: &Session) -> CrateConfig {
939939
if sess.target.has_thread_local {
940940
ret.insert((sym::target_thread_local, None));
941941
}
942+
let mut has_atomic = false;
942943
for (i, align) in [
943944
(8, layout.i8_align.abi),
944945
(16, layout.i16_align.abi),
@@ -947,6 +948,7 @@ fn default_configuration(sess: &Session) -> CrateConfig {
947948
(128, layout.i128_align.abi),
948949
] {
949950
if i >= min_atomic_width && i <= max_atomic_width {
951+
has_atomic = true;
950952
let mut insert_atomic = |s, align: Align| {
951953
ret.insert((sym::target_has_atomic_load_store, Some(Symbol::intern(s))));
952954
if atomic_cas {
@@ -963,6 +965,12 @@ fn default_configuration(sess: &Session) -> CrateConfig {
963965
}
964966
}
965967
}
968+
if has_atomic {
969+
ret.insert((sym::target_has_atomic_load_store, None));
970+
if atomic_cas {
971+
ret.insert((sym::target_has_atomic, None));
972+
}
973+
}
966974

967975
let panic_strategy = sess.panic_strategy();
968976
ret.insert((sym::panic, Some(panic_strategy.desc_symbol())));

0 commit comments

Comments
 (0)