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

            Bug ID: 90569
           Summary: __STDCPP_DEFAULT_NEW_ALIGNMENT__ is wrong for
                    i386-pc-solaris2.11
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
                CC: ro at gcc dot gnu.org
  Target Milestone: ---
            Target: i386-pc-solaris2.11

The default value for __STDCPP_DEFAULT_NEW_ALIGNMENT__ is alignof(max_align_t),
but GCC's max_align_t does not agree with the OS on i386-pc-solaris2.*, see PR
77691. This means that operator new(size_t) does not necessarily meet the
guarantee that __STDCPP_DEFAULT_NEW_ALIGNMENT__ is supposed to provide.

It looks like changing MALLOC_ABI_ALIGNMENT for the target should work, except
for this in gcc/cp/init.c:

/* Return the alignment we expect malloc to guarantee.  This should just be
   MALLOC_ABI_ALIGNMENT, but that macro defaults to only BITS_PER_WORD for some
   reason, so don't let the threshold be smaller than max_align_t_align.  */

unsigned
malloc_alignment ()
{
  return MAX (max_align_t_align(), MALLOC_ABI_ALIGNMENT);
}

Shouldn't we trust the target if it has overridden the default? e.g.

/* Return the alignment we expect malloc to guarantee.  This should just be
   MALLOC_ABI_ALIGNMENT, but that macro defaults to only BITS_PER_WORD for some
   reason.  If MALLOC_ABI_ALIGNMENT has been changed from the default, use it.
   Otherwise don't let the threshold be smaller than max_align_t_align.  */

unsigned
malloc_alignment ()
{
  if (MALLOC_ABI_ALIGNMENT != BITS_PER_WORD)
    return MALLOC_ABI_ALIGNMENT;
  return MAX (max_align_t_align(), MALLOC_ABI_ALIGNMENT);
}

Reply via email to