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

--- Comment #41 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #39)
> (In reply to r...@cebitec.uni-bielefeld.de from comment #37)
> >   AFAICS, alignof is C++ >= 11 only.  I've used the attached patch to
> >   use __alignof__ instead, although I don't know if that's the best fix.
> 
> Yes, alignof is C++11 only, but the reason it's OK to use there is that
> __STDCPP_DEFAULT_NEW_ALIGNMENT__ is C++17 only, and alignof is guarded by:
> 
> #if __cpp_aligned_new
>         if (alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
> 
> Strictly speaking, this code is enabled when -faligned-new is active, which
> is true for C++17 by default.
> 
> It appears that Jakub's patch makes -faligned-new always active for Solaris
> x86, which we don't want.

Ah, indeed, I thought the threshold is separate from it being enabled, but it
is not.
So, we want to change it in the option override handling only if cxx_dialect >=
cxx17, but that is something only defined in c-family, while the backend option
overriding is in code linked with all FEs.
Thus, we'd need to override it instead somewhere in i386-c.cc.
But nothing in that file is called early enough, from what I can see, the
sequence of initialization is:
cxx_dialect set to the default (cxx17 now)
possibly cxx_dialect changed if -std= used on command line
SUBTARGET_OVERRIDE_OPTIONS invoked
cxx_init_decl_processing
4645      if (aligned_new_threshold == -1)
4646        aligned_new_threshold = (cxx_dialect >= cxx17) ? 1 : 0;
4647      if (aligned_new_threshold == 1)
4648        aligned_new_threshold = malloc_alignment () / BITS_PER_UNIT;
code invoked
ix86_register_pragmas from i386-c.cc called
ix86_target_macros from i386-c.cc called

Also, the -Waligned-new= warning uses malloc_alignment () rather than
aligned_new_threshold, so if we want to override something for 32-bit x86
solaris, mingw and vxworks, we probably need something to hook into
malloc_alignment rather than to tweak aligned_new_threshold.

I think we need a target macro for it though rather than target hook, because
it needs to be invoked from the C++ FE and implemented in config/*-c.cc

Reply via email to