From d7e7befe500931afce6dee00bea81ac85b32a69f Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 3 Dec 2014 11:43:57 -0800 Subject: [PATCH] Tell the compiler that QArrayData returns aligned pointers GCC 4.9 and later support the __attribute__((alloc_align)) attributes that indicate the alignment of the data. To make it work on GCC since 4.7 and Clang as of 3.6, we instead use __builtin_assume_aligned(). I don't know which version of ICC first implemented this, but ICC 15 does and it also reports itself as GCC 4.9. Change-Id: I58bd914b9bdd0ed3349ba56fa78220ab06114852 Reviewed-by: Simon Hausmann --- src/corelib/tools/qarraydata.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/corelib/tools/qarraydata.h b/src/corelib/tools/qarraydata.h index 0063cf046f..94182a531c 100644 --- a/src/corelib/tools/qarraydata.h +++ b/src/corelib/tools/qarraydata.h @@ -218,16 +218,23 @@ struct QTypedArrayData AllocationOptions options = Default) { Q_STATIC_ASSERT(sizeof(QTypedArrayData) == sizeof(QArrayData)); - return static_cast(QArrayData::allocate(sizeof(T), - alignof(AlignmentDummy), capacity, options)); + void *result = QArrayData::allocate(sizeof(T), + alignof(AlignmentDummy), capacity, options); +#if (defined(Q_CC_GNU) && Q_CC_GNU >= 407) || QT_HAS_BUILTIN(__builtin_assume_aligned) + result = __builtin_assume_aligned(result, Q_ALIGNOF(AlignmentDummy)); +#endif + return static_cast(result); } static QTypedArrayData *reallocateUnaligned(QTypedArrayData *data, size_t capacity, AllocationOptions options = Default) { Q_STATIC_ASSERT(sizeof(QTypedArrayData) == sizeof(QArrayData)); - return static_cast(QArrayData::reallocateUnaligned(data, sizeof(T), - capacity, options)); + void *result = QArrayData::reallocateUnaligned(data, sizeof(T), capacity, options)); +#if (defined(Q_CC_GNU) && Q_CC_GNU >= 407) || QT_HAS_BUILTIN(__builtin_assume_aligned) + result =__builtin_assume_aligned(result, Q_ALIGNOF(AlignmentDummy)); +#endif + return static_cast(result); } static void deallocate(QArrayData *data)