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

            Bug ID: 89624
           Summary: HLE acquire/release bits in std::memory_order don't
                    work with -fshort-enums or -fstrict-enums
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Keywords: ABI
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

#include <atomic>

static_assert((std::memory_order_acquire | std::__memory_order_hle_acquire)
    != std::memory_order_acquire, "HLE acquire sets a bit");

This fails with -fshort-enums because it makes the std::memory_order enum only
occupy a single byte, so the HLE bits don't exist:

  enum __memory_order_modifier
    {
      __memory_order_mask          = 0x0ffff,
      __memory_order_modifier_mask = 0xffff0000,
      __memory_order_hle_acquire   = 0x10000,
      __memory_order_hle_release   = 0x20000
    };

For -fstrict-enums those bits create values which are not valid values of the
enum type.

I think we need to give std::memory_order a fixed underlying type of int, so
that its size doesn't change with -fshort-enums and all values of int are
valid.

This will be an ABI break for -fshort-enums though, but that's already happened
for PR 88996 because the new definition is a scoped enum, which always has a
fixed underlying type.

Reply via email to