From 44fad577711e0df1f9e9a251e978a0c0b36d7640 Mon Sep 17 00:00:00 2001 From: John Paul Adrian Glaubitz Date: Sat, 6 Jun 2020 06:45:53 +0000 Subject: [PATCH] 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 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 --- mfbt/tests/TestCompactPair.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mfbt/tests/TestCompactPair.cpp b/mfbt/tests/TestCompactPair.cpp index 2d7cf859a1c1..e93c6807b96c 100644 --- a/mfbt/tests/TestCompactPair.cpp +++ b/mfbt/tests/TestCompactPair.cpp @@ -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 {