Skip to content

Commit

Permalink
Bug 1325771 - mfbt:tests: Handle targets with less strict alignment i…
Browse files Browse the repository at this point in the history
…n 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
  • Loading branch information
glaubitz committed Jun 6, 2020
1 parent 84fa53c commit 2ae4647
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions mfbt/tests/TestCompactPair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand All @@ -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 {
Expand Down

0 comments on commit 2ae4647

Please sign in to comment.