Skip to content

Commit 1cd7dbf

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 c8e6a9e commit 1cd7dbf

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
@@ -957,6 +957,7 @@ fn default_configuration(sess: &Session) -> CrateConfig {
957957
if sess.target.has_thread_local {
958958
ret.insert((sym::target_thread_local, None));
959959
}
960+
let mut has_atomic = false;
960961
for (i, align) in [
961962
(8, layout.i8_align.abi),
962963
(16, layout.i16_align.abi),
@@ -965,6 +966,7 @@ fn default_configuration(sess: &Session) -> CrateConfig {
965966
(128, layout.i128_align.abi),
966967
] {
967968
if i >= min_atomic_width && i <= max_atomic_width {
969+
has_atomic = true;
968970
let mut insert_atomic = |s, align: Align| {
969971
ret.insert((sym::target_has_atomic_load_store, Some(Symbol::intern(s))));
970972
if atomic_cas {
@@ -981,6 +983,12 @@ fn default_configuration(sess: &Session) -> CrateConfig {
981983
}
982984
}
983985
}
986+
if sess.is_nightly_build() && has_atomic {
987+
ret.insert((sym::target_has_atomic_load_store, None));
988+
if atomic_cas {
989+
ret.insert((sym::target_has_atomic, None));
990+
}
991+
}
984992

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

0 commit comments

Comments
 (0)