+2018-10-12 Jonathan Wakely <jwakely@redhat.com>
+
+ PR libstdc++/77691
+ * include/experimental/memory_resource (__resource_adaptor_imp): Do
+ not allocate sizes smaller than alignment when relying on guaranteed
+ alignment.
+ * testsuite/experimental/memory_resource/new_delete_resource.cc:
+ Adjust expected number of bytes allocated for alignof(max_align_t).
+
2018-10-11 François Dumont <fdumont@gcc.gnu.org>
* include/debug/forward_list
do_allocate(size_t __bytes, size_t __alignment) override
{
if (__alignment <= __guaranteed_alignment<_Alloc>::value)
- return _M_alloc.allocate(__bytes);
+ {
+ if (__bytes < __alignment)
+ __bytes = __alignment;
+ return _M_alloc.allocate(__bytes);
+ }
+
const _AlignMgr __mgr(__bytes, __alignment);
// Assume _M_alloc returns 1-byte aligned memory, so allocate enough
auto __ptr = static_cast<char*>(__p);
if (__alignment <= __guaranteed_alignment<_Alloc>::value)
{
+ if (__bytes < __alignment)
+ __bytes = __alignment;
_M_alloc.deallocate(__ptr, __bytes);
return;
}
using std::size_t;
void* p = nullptr;
+ auto max = [](int n, int a) { return n > a ? n : a; };
+
bytes_allocated = 0;
memory_resource* r1 = new_delete_resource();
- p = r1->allocate(1);
- VERIFY( bytes_allocated == 1 );
+ p = r1->allocate(1); // uses alignment = alignof(max_align_t)
+ VERIFY( bytes_allocated <= alignof(max_align_t) );
VERIFY( aligned<max_align_t>(p) );
r1->deallocate(p, 1);
VERIFY( bytes_allocated == 0 );
VERIFY( bytes_allocated == 0 );
p = r1->allocate(3, alignof(short));
- VERIFY( bytes_allocated == 3 );
+ VERIFY( bytes_allocated == max(3, alignof(short)) );
VERIFY( aligned<short>(p) );
r1->deallocate(p, 3, alignof(short));
VERIFY( bytes_allocated == 0 );
p = r1->allocate(4, alignof(long));
- VERIFY( bytes_allocated == 4 );
+ VERIFY( bytes_allocated == max(4, alignof(long)) );
VERIFY( aligned<long>(p) );
r1->deallocate(p, 4, alignof(long));
VERIFY( bytes_allocated == 0 );