[libc++] LWG2070: Use Allocator construction for objects created with allocate_shared
authorLouis Dionne <ldionne.2@gmail.com>
Fri, 11 Dec 2020 17:22:16 +0000 (12:22 -0500)
committerLouis Dionne <ldionne.2@gmail.com>
Fri, 8 Jan 2021 18:04:03 +0000 (13:04 -0500)
commit955dd7b7f3f6df79f573508ffb567f3923e892f7
tree016fbfea72292496403ebc878fe86d493341add9
parent95729f95d803c8e8f4ca3e6767404ec2c0492d53
[libc++] LWG2070: Use Allocator construction for objects created with allocate_shared

This patch updates `allocate_shared` to call `allocator_traits::construct`
when creating the object held inside the shared_pointer, and
`allocator_traits::destroy` when destroying it. This resolves
the part of P0674R1 that was originally filed as LWG2070.

This change is landed separately from the rest of P0674R1 because it is
incredibly tricky from an ABI perspective.

This is the reason why this change is so tricky is that we previously
used EBO in a compressed pair to store both the allocator and the object
type stored in the `shared_ptr`. However, starting in C++20, P0674
requires us to use Allocator construction for initializing the object type.
That requirement rules out the use of the EBO for the object type, since
using the EBO implies that the base will be initialized when the control
block is initialized (and hence we can't do it through Allocator construction).
Hence, supporting P0674 requires changing how we store the object type
inside the control block, which we do while being ABI compatible by using
some trickery with a properly aligned char buffer.

Fixes https://llvm.org/PR41900
Supersedes https://llvm.org/D62760

Differential Revision: https://reviews.llvm.org/D91201
libcxx/include/memory
libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/libcxx.control_block_layout.pass.cpp [new file with mode: 0644]
libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.pass.cpp
libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared_construct.pass.cpp [new file with mode: 0644]