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 <vadorovsky@gmail.com>
This commit is contained in:
Michal Rostecki 2023-01-16 19:13:52 +08:00
parent c8e6a9e8b6
commit 1cd7dbfbf8

View File

@ -957,6 +957,7 @@ fn default_configuration(sess: &Session) -> CrateConfig {
if sess.target.has_thread_local {
ret.insert((sym::target_thread_local, None));
}
let mut has_atomic = false;
for (i, align) in [
(8, layout.i8_align.abi),
(16, layout.i16_align.abi),
@ -965,6 +966,7 @@ fn default_configuration(sess: &Session) -> CrateConfig {
(128, layout.i128_align.abi),
] {
if i >= min_atomic_width && i <= max_atomic_width {
has_atomic = true;
let mut insert_atomic = |s, align: Align| {
ret.insert((sym::target_has_atomic_load_store, Some(Symbol::intern(s))));
if atomic_cas {
@ -981,6 +983,12 @@ fn default_configuration(sess: &Session) -> CrateConfig {
}
}
}
if sess.is_nightly_build() && has_atomic {
ret.insert((sym::target_has_atomic_load_store, None));
if atomic_cas {
ret.insert((sym::target_has_atomic, None));
}
}
let panic_strategy = sess.panic_strategy();
ret.insert((sym::panic, Some(panic_strategy.desc_symbol())));