This is an archive of the discontinued LLVM Phabricator instance.

Fix PR40230 - std::pair may have padding on FreeBSD.
ClosedPublic

Authored by EricWF on Jan 5 2019, 12:02 PM.

Details

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:

Diff Detail

Repository
rCXX libc++

Event Timeline

EricWF created this revision.Jan 5 2019, 12:02 PM
rsmith accepted this revision.Jan 6 2019, 10:09 PM

LGTM (assuming the FreeBSD folks are OK with it).

This revision is now accepted and ready to land.Jan 6 2019, 10:09 PM

I'm fine with this as well - assuming the FreeBSD people are happy.

This revision was automatically updated to reflect the committed changes.