Is There a Way to Emulate Atomic Alignment #[cfg] Check on Stable?

I'm trying to polyfill the AtomicU8::from_mut_slice unstable function in the standard library, and to do it I need to have some equivalent to the cfg(target_has_atomic_equal_alignment = "n") check.

Even if that is a whitelisted set of platforms where that cfg check will match, how would I find out which platforms have a particular atomic alignment? Or does anybody know which platforms this is safe on somehow?

The compiler sets that by checking the actual alignment of the types:

Those primitive alignments come from the target spec data_layout per LLVM:
https://llvm.org/docs/LangRef.html#data-layout

1 Like

Perfect, and then I can find the data layout by printing the target specification and looking at the data_layout field:

rustc +nightly -Z unstable-options --print target-spec-json --target wasm32-unknown-unknown
{
  "arch": "wasm32",
  "data-layout": "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20",
  ...
}

Thanks!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.