<div dir="ltr"><div>I have started working on an implementation of atomic_ref. Implementing this requires performing atomic operations on arbitrary references. The behavior is undefined if a reference is provided that is not aligned per the public export required_alignment. What assumptions do the __c11_atomic builtins make about destination argument alignment, format, size etc.? Is it required that the destination argument be annotated as _Atomic like the corresponding standard c11 functions require? <br></div><div><br></div><div>The following code in libcxx/include/config implies that the c11 atomic builtins should be substituted for gcc atomic builtins if present:</div><div><br></div><div>#if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic)          </div>#  define _LIBCPP_HAS_C_ATOMIC_IMP                                                                   <br>#elif defined(_LIBCPP_COMPILER_GCC)                                                                  <br>#  define _LIBCPP_HAS_GCC_ATOMIC_IMP                                                                 <br><div>#endif</div><div><br></div><div>To implement atomic_ref, it might be cleaner to use the gcc builtins. By doing so, we avoid depending on the internals of the c11 atomic builtins. The required alignment of referenced variables would always be the first power of 2 >= max(type_size, type_alignment). Alternatively, we could use the c11 atomic builtins when available if it is enough to require that the input reference is aligned as the atomic type would be. What are your thoughts?</div><div><br></div><div>Regards,</div><div>Ben<br></div></div>