This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] PR libstdc++/77691 fix resource_adaptor failures due to max_align_t bugs


On 22/05/19 23:17 +0100, Jonathan Wakely wrote:
On 22/05/19 21:40 +0100, Jonathan Wakely wrote:
Remove the hardcoded whitelist of allocators expected to return memory
aligned to alignof(max_align_t), because that doesn't work when the
platform's malloc() and GCC's max_align_t do not agree what the largest
fundamental alignment is. It's also sub-optimal for user-defined
allocators that return memory suitable for any fundamental alignment.

Instead use a hardcoded list of alignments that are definitely supported
by the platform malloc, and use a copy of the allocator rebound to a POD
type with the requested alignment. Only allocate an oversized
buffer to use with std::align for alignments larger than any of the
hardcoded values.

For 32-bit Solaris x86 do not include alignof(max_align_t) in the
hardcoded values.

	PR libstdc++/77691
	* include/experimental/memory_resource: Add system header pragma.
	(__resource_adaptor_common::__guaranteed_alignment): Remove.
	(__resource_adaptor_common::_Types)
	(__resource_adaptor_common::__new_list)
	(__resource_adaptor_common::_New_list)
	(__resource_adaptor_common::_Alignments)
	(__resource_adaptor_common::_Fund_align_types): New utilities for
	creating a list of types with fundamental alignments.
	(__resource_adaptor_imp::do_allocate): Call new _M_allocate function.
	(__resource_adaptor_imp::do_deallocate): Call new _M_deallocate
	function.
	(__resource_adaptor_imp::_M_allocate): New function that first tries
	to use an allocator rebound to a type with a fundamental alignment.
	(__resource_adaptor_imp::_M_deallocate): Likewise for deallocation.
	* testsuite/experimental/memory_resource/new_delete_resource.cc:
	Adjust expected allocation sizes.
	* testsuite/experimental/memory_resource/resource_adaptor.cc: Remove
	xfail.

Gah, that's the wrong ChangeLog, from an earlier version of the patch.
The right one is in the ChangeLog file, but the svn commit has the
wrong info, sorry.

The correct one is:

      PR libstdc++/77691
      * include/experimental/memory_resource: Add system header pragma and
      do not define anything unless compiled as C++14 or later.
      (__resource_adaptor_common::__guaranteed_alignment): Remove.
      (__resource_adaptor_imp::do_allocate): If the requested alignment
      is a fundamental alignment then either allocate directly from _M_alloc
      or call the new _M_allocate function.
      (__resource_adaptor_imp::do_deallocate): Likewise for deallocation.
      (__resource_adaptor_imp::_M_allocate): New function that uses a copy
      of the allocator rebound to a POD type with the specified alignment.
      (__resource_adaptor_imp::_M_deallocate): Likewise for deallocation.
      * testsuite/experimental/memory_resource/new_delete_resource.cc:
      Adjust expected allocation sizes.
      * testsuite/experimental/memory_resource/resource_adaptor.cc: Remove
      xfail for Solaris x86.

Double-gah, the tests are failing for 32-bit x86-linux, but not on my
machine. Presumably because glibc malloc only used to guarantee 8-byte
alignment until fairly recently.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]