Bug 1325771 - mfbt:tests: Handle targets with less strict alignment in TestPair. r?Waldo draft
authorMichael Karcher <debian@mkarcher.dialup.fu-berlin.de>
Sat, 24 Dec 2016 15:24:19 +0100
changeset 458873 85ba7f2cf2b5890681c5cf14c010a6b023e8c2c4
parent 458872 e2fa1647bd3a602661a908c386c9178ba696d923
child 458874 e94b7e14812c1137794ff6ec82f213531a47c7a8
push id41085
push userbmo:mh+mozilla@glandium.org
push dateWed, 11 Jan 2017 07:28:36 +0000
reviewersWaldo
bugs1325771
milestone53.0a1
Bug 1325771 - mfbt:tests: Handle targets with less strict alignment in TestPair. r?Waldo 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.
mfbt/tests/TestPair.cpp
--- a/mfbt/tests/TestPair.cpp
+++ b/mfbt/tests/TestPair.cpp
@@ -24,24 +24,29 @@ using mozilla::Pair;
   Pair<T2, T1> name##_2(T2(0), T1(0)); \
   static_assert(sizeof(name##_2.first()) > 0, \
                 "first method should work on Pair<" #T2 ", " #T1 ">"); \
   static_assert(sizeof(name##_2.second()) > 0, \
                 "second method should work on Pair<" #T2 ", " #T1 ">"); \
   static_assert(sizeof(name##_2) == (size), \
                 "Pair<" #T2 ", " #T1 "> has an unexpected size");
 
+static constexpr size_t sizemax(size_t a, 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) {} };
 struct NonEmpty { char mC; explicit NonEmpty(int) {} };
 
 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 { char dummy; explicit A(int) {} };
 struct B : A { explicit B(int aI) : A(aI) {} };
 
 INSTANTIATE(A, A, class1, 2);
 INSTANTIATE(A, B, class2, 2);
 INSTANTIATE(A, EmptyClass, class3, 1);