PR libstdc++/86861 Meet precondition for Solaris memalign
commit8542a4f6bc0604503ed5a5733c00bc7c6c426dd1
authorredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 7 Aug 2018 16:10:29 +0000 (7 16:10 +0000)
committerredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 7 Aug 2018 16:10:29 +0000 (7 16:10 +0000)
tree2eca860ce69658e282f224ed7764199fd83d39ba
parentdc65ac08afe2f05182ca38df67535913bf1efd80
PR libstdc++/86861 Meet precondition for Solaris memalign

Solaris memalign requires alignment to be at least sizeof(int), so
increase it as needed.

Also move the check for valid alignments from the fallback
implementation of aligned_alloc into operator new, as it's required for
all of aligned_alloc, memalign, posix_memalign and __aligned_malloc.
This adds a branch to check for undefined behaviour which we could just
ignore, so the check could just be removed. It should certainly be
removed if PR 86878 is implemented to issue a warning about calls with
invalid alignments.

PR libstdc++/86861
* libsupc++/new_opa.cc [_GLIBCXX_HAVE_MEMALIGN] (aligned_alloc):
Replace macro with inline function.
[__sun]: Increase alignment to meet memalign precondition.
[!HAVE__ALIGNED_MALLOC && !HAVE_POSIX_MEMALIGN && !HAVE_MEMALIGN]
(aligned_alloc): Move check for valid alignment to operator new.
Remove redundant check for non-zero size, it's enforced by the caller.
(operator new): Move check for valid alignment here. Use
__builtin_expect on check for zero size.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@263360 138bc75d-0d04-0410-961f-82ee72b054a4
libstdc++-v3/ChangeLog
libstdc++-v3/libsupc++/new_opa.cc