https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127693

--- Comment #33 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <[email protected]>:

https://gcc.gnu.org/g:e509c1127d321143eff1d08219bb1def5b31da3e

commit r17-6112-ge509c1127d321143eff1d08219bb1def5b31da3e
Author: Jonathan Wakely <[email protected]>
Date:   Mon Oct 19 22:03:20 2026 +0100

    libstdc++: Use always_inline in <atomic> with memory_order params
[PR127693]

    As described in the bug report, std::atomic member functions might not
    be inlined at -Os and if that happens, the std::memory_order parameter
    becomes a runtime argument. This causes the atomic builtin to fall back
    to a seq_cst operation.

    By adding the always_inline attribute a compile-time constant memory
    order is propagated to the builtin and so it might be expanded to a more
    efficient implementation than for seq_cst.

    libstdc++-v3/ChangeLog:

            PR libstdc++/127693
            * include/bits/atomic_base.h (__atomic_float::store)
            (__atomic_float::load, __atomic_float::exchange)
            (__atomic_float::compare_exchange_weak)
            (__atomic_float::compare_exchange_strong)
            (__atomic_float::fetch_add, __atomic_float::fetch_sub)
            (__atomic_float::fetch_min, __atomic_float::fetch_max)
            (__atomic_ref_base::load, __atomic_ref_base::store)
            (__atomic_ref_base::exchange)
            (__atomic_ref_base::compare_exchange_strong)
            (__atomic_ref_base::compare_exchange_weak)
            (__atomic_ref<integral-type>::fetch_add)
            (__atomic_ref<integral-type>::fetch_sub)
            (__atomic_ref<integral-type>::fetch_and)
            (__atomic_ref<integral-type>::fetch_or)
            (__atomic_ref<integral-type>::fetch_xor)
            (__atomic_ref<integral-type>::fetch_min)
            (__atomic_ref<integral-type>::fetch_max)
            (__atomic_ref<floating-point-type>::fetch_add)
            (__atomic_ref<floating-point-type>::fetch_sub)
            (__atomic_ref<floating-point-type>::fetch_min)
            (__atomic_ref<floating-point-type>::fetch_max): Add macro for
            always_inline attribute.
            * include/std/atomic (atomic<bool>::store)
            (atomic<bool>::load, atomic<bool>::exchange)
            (atomic<bool>::compare_exchange_weak)
            (atomic<bool>::compare_exchange_strong, atomic<bool>::wait)
            (atomic::store, atomic::load, atomic::exchange)
            (atomic::compare_exchange_weak, atomic::compare_exchange_strong)
            (atomic::wait, atomic<T*>::store, atomic<T*>::load)
            (atomic<T*>::exchange, atomic<T*>::compare_exchange_weak)
            (atomic<T*>::compare_exchange_strong, atomic<T*>::wait)
            (atomic<T*>::fetch_add, atomic<T*>::fetch_sub)
            (atomic<T*>::fetch_min, atomic<T*>::fetch_max): Likewise.
            * testsuite/29_atomics/atomic/127693.cc: New test.
            * testsuite/29_atomics/atomic_ref/127693.cc: New test.

    Reviewed-by: Tomasz KamiÅski <[email protected]>

Reply via email to