diff options
author | Sami Nurmenniemi <sami.nurmenniemi@qt.io> | 2017-03-07 16:45:49 +0200 |
---|---|---|
committer | Sami Nurmenniemi <sami.nurmenniemi@qt.io> | 2017-04-07 05:54:04 +0000 |
commit | bbb67ca32cebad312f02e916dff54e591b92af24 (patch) | |
tree | 01fff48a0f0bf53098e2f87d6608705aaedf2ac3 /tests/auto | |
parent | 5c6d1324084f506fdb992d48515894a64e8f4841 (diff) |
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 <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/corelib/tools/collections/tst_collections.cpp | 42 |
1 files 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<typename C> void testVectorAlignment() @@ -3278,17 +3290,17 @@ void testAssociativeContainerAlignment() void tst_Collections::alignment() { testVectorAlignment<QVector<Aligned4> >(); - testVectorAlignment<QVector<Aligned128> >(); + testVectorAlignment<QVector<AlignedBiggest> >(); testContiguousCacheAlignment<QContiguousCache<Aligned4> >(); - testContiguousCacheAlignment<QContiguousCache<Aligned128> >(); + testContiguousCacheAlignment<QContiguousCache<AlignedBiggest> >(); testAssociativeContainerAlignment<QMap<Aligned4, Aligned4> >(); - testAssociativeContainerAlignment<QMap<Aligned4, Aligned128> >(); - testAssociativeContainerAlignment<QMap<Aligned128, Aligned4> >(); - testAssociativeContainerAlignment<QMap<Aligned128, Aligned128> >(); + testAssociativeContainerAlignment<QMap<Aligned4, AlignedBiggest> >(); + testAssociativeContainerAlignment<QMap<AlignedBiggest, Aligned4> >(); + testAssociativeContainerAlignment<QMap<AlignedBiggest, AlignedBiggest> >(); testAssociativeContainerAlignment<QHash<Aligned4, Aligned4> >(); - testAssociativeContainerAlignment<QHash<Aligned4, Aligned128> >(); - testAssociativeContainerAlignment<QHash<Aligned128, Aligned4> >(); - testAssociativeContainerAlignment<QHash<Aligned128, Aligned128> >(); + testAssociativeContainerAlignment<QHash<Aligned4, AlignedBiggest> >(); + testAssociativeContainerAlignment<QHash<AlignedBiggest, Aligned4> >(); + testAssociativeContainerAlignment<QHash<AlignedBiggest, AlignedBiggest> >(); } #else |