diff options
author | Jonathan Wakely <redi@gcc.gnu.org> | 2016-10-14 13:03:47 +0100 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2016-10-14 13:03:47 +0100 |
commit | ace4c2f060160bd3ef9032cc151e36b84e4ba3e8 (patch) | |
tree | b1ea7c7f07360d2914b518d2a602e9c3b524547e /libstdc++-v3/include/ext/mt_allocator.h | |
parent | cb3ac86754e416f716e478f309f13108f9e9ac7f (diff) | |
download | gcc-ace4c2f060160bd3ef9032cc151e36b84e4ba3e8.zip gcc-ace4c2f060160bd3ef9032cc151e36b84e4ba3e8.tar.gz gcc-ace4c2f060160bd3ef9032cc151e36b84e4ba3e8.tar.bz2 |
PR65122 extended alignment support in allocators
PR libstdc++/65122
* include/ext/malloc_allocator.h (malloc_allocator::allocate): Use
aligned_alloc for types with extended alignment if available,
otherwise throw bad_alloc if malloc doesn't return a suitable value.
* include/ext/bitmap_allocator.h (bitmap_allocator::allocate)
(bitmap_allocator::deallocate): Use aligned new/delete for types with
extended alignment.
* include/ext/mt_allocator.h (__mt_alloc::allocate)
(__mt_alloc::deallocate): Likewise.
* include/ext/new_allocator.h (new_allocator::allocate)
(new_allocator::deallocate): Likewise.
* include/ext/pool_allocator.h (__pool_alloc::allocate)
(__pool_alloc::deallocate): Likewise.
* testsuite/20_util/allocator/overaligned.cc: New test.
* testsuite/ext/bitmap_allocator/overaligned.cc: New test.
* testsuite/ext/malloc_allocator/overaligned.cc: New test.
* testsuite/ext/mt_allocator/overaligned.cc: New test.
* testsuite/ext/new_allocator/overaligned.cc: New test.
* testsuite/ext/pool_allocator/overaligned.cc: New test.
From-SVN: r241158
Diffstat (limited to 'libstdc++-v3/include/ext/mt_allocator.h')
-rw-r--r-- | libstdc++-v3/include/ext/mt_allocator.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/libstdc++-v3/include/ext/mt_allocator.h b/libstdc++-v3/include/ext/mt_allocator.h index 7016e48..d7ea7c1 100644 --- a/libstdc++-v3/include/ext/mt_allocator.h +++ b/libstdc++-v3/include/ext/mt_allocator.h @@ -691,6 +691,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION if (__n > this->max_size()) std::__throw_bad_alloc(); +#if __cpp_aligned_new + // Types with extended alignment are handled by operator new/delete. + if (alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__) + { + std::align_val_t __al = std::align_val_t(alignof(_Tp)); + return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), __al)); + } +#endif + __policy_type::_S_initialize_once(); // Requests larger than _M_max_bytes are handled by operator @@ -737,6 +746,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { if (__builtin_expect(__p != 0, true)) { +#if __cpp_aligned_new + // Types with extended alignment are handled by operator new/delete. + if (alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__) + { + ::operator delete(__p, std::align_val_t(alignof(_Tp))); + return; + } +#endif + // Requests larger than _M_max_bytes are handled by // operators new/delete directly. __pool_type& __pool = __policy_type::_S_get_pool(); |