summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2019-01-16 01:54:34 +0000
committerEric Fiselier <eric@efcs.ca>2019-01-16 01:54:34 +0000
commit6840e5476ec952ebfb499481122724ac003378c7 (patch)
treefb09180f7553dfbc80955a60dd92b3b7f0c0f403 /include
parent272871b658429a2da4c28ddecbfbe7574f781a7f (diff)
downloadlibcxx-6840e5476ec952ebfb499481122724ac003378c7.tar.gz
Fix PR40230 - std::pair may have padding on FreeBSD.
Summary: FreeBSD ships a very old and deprecated ABI for std::pair where the copy and move constructors are not allowed to be trivial. D25389 change how this was implemented by introducing a non-trivial base class. This patch, introduced in October 2016, introduced an ABI bug that caused nested `std::pair` instantiations to have padding. For example: ``` using PairT = std::pair< std::pair<char, char>, char >; static_assert(offsetof(PairT, first) == 0, "First member should exist at offset zero"); // Fails on FreeBSD! ``` The bug occurs because the base class for the first element (the nested pair) cannot be put at offset zero because the top-level pair already has the same base class laid out there. This patch fixes that ABI bug by templating the dummy base class on the same parameters as the pair. Technically this fix is an ABI break for users who depend on the "broken" ABI introduced in 2016. I'm putting this up for review so that the FreeBSD maintainers can sign off on fixing the ABI by breaking the ABI. Another option, since we have to "break" the ABI to fix it, would be to move FreeBSD off the deprecated non-trivial pair ABI instead. Also see: * https://llvm.org/PR40230 * https://reviews.llvm.org/D21329 Reviewers: rsmith, dim, emaste Reviewed By: rsmith Subscribers: mclow.lists, krytarowski, christof, ldionne, libcxx-commits Differential Revision: https://reviews.llvm.org/D56357 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@351290 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/utility3
1 files changed, 2 insertions, 1 deletions
diff --git a/include/utility b/include/utility
index 3fa0bc4c7..74bbc5cf3 100644
--- a/include/utility
+++ b/include/utility
@@ -303,6 +303,7 @@ extern _LIBCPP_EXPORTED_FROM_ABI const piecewise_construct_t piecewise_construct
#endif
#if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR)
+template <class, class>
struct __non_trivially_copyable_base {
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
__non_trivially_copyable_base() _NOEXCEPT {}
@@ -314,7 +315,7 @@ struct __non_trivially_copyable_base {
template <class _T1, class _T2>
struct _LIBCPP_TEMPLATE_VIS pair
#if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR)
-: private __non_trivially_copyable_base
+: private __non_trivially_copyable_base<_T1, _T2>
#endif
{
typedef _T1 first_type;