Bug 1325771 - mfbt:tests: Handle targets with less strict alignment in TestCompactPair r=jesup

Previously, the tests assumed that the alignment of int and long equals
their size. This commit fixes the tests for targets like m68k that have
sizeof(int) == 4 and alignof(int) == 2. A static helper function sizemax
was introduced as the offset of the second element in Pair<int,long>
might be either determined by its alignment requirement or the size of
the preceding int element and we use the helper function to pick the
larger of the two values.

Differential Revision: https://phabricator.services.mozilla.com/D77289
This commit is contained in:
John Paul Adrian Glaubitz 2020-06-06 06:45:53 +00:00
parent c53e11c2b2
commit 44fad57771

View File

@ -35,8 +35,13 @@ using mozilla::MakeCompactPair;
static_assert(sizeof(name##_2) == (size), \
"CompactPair<" #T2 ", " #T1 "> has an unexpected size");
static constexpr std::size_t sizemax(std::size_t a, std::size_t b)
{
return (a > b) ? a : b;
}
INSTANTIATE(int, int, prim1, 2 * sizeof(int));
INSTANTIATE(int, long, prim2, 2 * sizeof(long));
INSTANTIATE(int, long, prim2, sizeof(long) + sizemax(sizeof(int), alignof(long)));
struct EmptyClass {
explicit EmptyClass(int) {}
@ -47,7 +52,7 @@ struct NonEmpty {
};
INSTANTIATE(int, EmptyClass, both1, sizeof(int));
INSTANTIATE(int, NonEmpty, both2, 2 * sizeof(int));
INSTANTIATE(int, NonEmpty, both2, sizeof(int) + alignof(int));
INSTANTIATE(EmptyClass, NonEmpty, both3, 1);
struct A {