From bbb67ca32cebad312f02e916dff54e591b92af24 Mon Sep 17 00:00:00 2001 From: Sami Nurmenniemi Date: Tue, 7 Mar 2017 16:45:49 +0200 Subject: Fix tst_Collections for gcc/arm - Alignment test was not compiling or passing on GCC / arm - Using C++11 alignas() enforces maximum limit for the alignment, which at least on GCC / arm is __BIGGEST_ALIGNMENT__ multiplied by 8 - On GCC 6.2.0 / x86_84, maximum alignment accepted by alignas is 128 - On GCC 5.3.0 / arm, maximum alignment accepted by alignas is 64 - This change calculates biggest tested alignment on ARM targets and compilers supporting alignas() to the value calculated from __BIGGEST_ALIGNMENT__ Task-number: QTBUG-55492 Change-Id: If2b70000ff9cdc5ae8c5a00e39f79efcc6ba1221 Reviewed-by: Thiago Macieira --- .../corelib/tools/collections/tst_collections.cpp | 42 ++++++++++++++-------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/tests/auto/corelib/tools/collections/tst_collections.cpp b/tests/auto/corelib/tools/collections/tst_collections.cpp index af270ded98..38366e86ff 100644 --- a/tests/auto/corelib/tools/collections/tst_collections.cpp +++ b/tests/auto/corelib/tools/collections/tst_collections.cpp @@ -3208,19 +3208,31 @@ public: }; Q_STATIC_ASSERT(Q_ALIGNOF(Aligned4) % 4 == 0); -class Q_DECL_ALIGN(128) Aligned128 +#if defined(Q_PROCESSOR_ARM) +# if defined(Q_COMPILER_ALIGNAS) && defined(__BIGGEST_ALIGNMENT__) + // On ARM __BIGGEST_ALIGNMENT__ must be multiplied by 8 to + // get the same limit as enforced by alignas() +# define BIGGEST_ALIGNMENT_TO_TEST (__BIGGEST_ALIGNMENT__ << 3) +# endif +#endif + +#if !defined(BIGGEST_ALIGNMENT_TO_TEST) +# define BIGGEST_ALIGNMENT_TO_TEST 128 +#endif + +class Q_DECL_ALIGN(BIGGEST_ALIGNMENT_TO_TEST) AlignedBiggest { char i; public: - Aligned128(int i = 0) : i(i) {} + AlignedBiggest(int i = 0) : i(i) {} - enum { PreferredAlignment = 128 }; + enum { PreferredAlignment = BIGGEST_ALIGNMENT_TO_TEST }; - inline bool operator==(const Aligned128 &other) const { return i == other.i; } - inline bool operator<(const Aligned128 &other) const { return i < other.i; } - friend inline int qHash(const Aligned128 &a) { return qHash(a.i); } + inline bool operator==(const AlignedBiggest &other) const { return i == other.i; } + inline bool operator<(const AlignedBiggest &other) const { return i < other.i; } + friend inline int qHash(const AlignedBiggest &a) { return qHash(a.i); } }; -Q_STATIC_ASSERT(Q_ALIGNOF(Aligned128) % 128 == 0); +Q_STATIC_ASSERT(Q_ALIGNOF(AlignedBiggest) % BIGGEST_ALIGNMENT_TO_TEST == 0); template void testVectorAlignment() @@ -3278,17 +3290,17 @@ void testAssociativeContainerAlignment() void tst_Collections::alignment() { testVectorAlignment >(); - testVectorAlignment >(); + testVectorAlignment >(); testContiguousCacheAlignment >(); - testContiguousCacheAlignment >(); + testContiguousCacheAlignment >(); testAssociativeContainerAlignment >(); - testAssociativeContainerAlignment >(); - testAssociativeContainerAlignment >(); - testAssociativeContainerAlignment >(); + testAssociativeContainerAlignment >(); + testAssociativeContainerAlignment >(); + testAssociativeContainerAlignment >(); testAssociativeContainerAlignment >(); - testAssociativeContainerAlignment >(); - testAssociativeContainerAlignment >(); - testAssociativeContainerAlignment >(); + testAssociativeContainerAlignment >(); + testAssociativeContainerAlignment >(); + testAssociativeContainerAlignment >(); } #else -- cgit v1.2.3