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>
bb10
Thiago Macieira 2014-12-03 11:43:57 -08:00 committed by Lars Knoll
parent a07925576a
commit d7e7befe50
1 changed files with 11 additions and 4 deletions

View File

@ -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)