[all-commits] [llvm/llvm-project] 955dd7: [libc++] LWG2070: Use Allocator construction for o...

Louis Dionne via All-commits all-commits at lists.llvm.org
Fri Jan 8 10:04:51 PST 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 955dd7b7f3f6df79f573508ffb567f3923e892f7
      https://github.com/llvm/llvm-project/commit/955dd7b7f3f6df79f573508ffb567f3923e892f7
  Author: Louis Dionne <ldionne.2 at gmail.com>
  Date:   2021-01-08 (Fri, 08 Jan 2021)

  Changed paths:
    M libcxx/include/memory
    A libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/libcxx.control_block_layout.pass.cpp
    M libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.pass.cpp
    A libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared_construct.pass.cpp

  Log Message:
  -----------
  [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




More information about the All-commits mailing list