diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2014-12-03 11:43:57 -0800 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2019-12-07 14:17:23 +0100 |
commit | d7e7befe500931afce6dee00bea81ac85b32a69f (patch) | |
tree | 34bbb77bfba212428438f4ebb76dda92e145ae6d /src/corelib/tools/qarraydata.h | |
parent | a07925576a82e8e6e627d13d22416b05f5bb534b (diff) |
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 <simon.hausmann@qt.io>
Diffstat (limited to 'src/corelib/tools/qarraydata.h')
-rw-r--r-- | src/corelib/tools/qarraydata.h | 15 |
1 files 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<QTypedArrayData *>(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<QTypedArrayData *>(result); } static QTypedArrayData *reallocateUnaligned(QTypedArrayData *data, size_t capacity, AllocationOptions options = Default) { Q_STATIC_ASSERT(sizeof(QTypedArrayData) == sizeof(QArrayData)); - return static_cast<QTypedArrayData *>(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<QTypedArrayData *>(result); } static void deallocate(QArrayData *data) |