Bug 1288016 - Replaced MOZ_ALIGNOF() with alignof(). r=media-playback-reviewers,xpcom-reviewers,emilio,glandium,karlt
Replaced all instances of `MOZ_ALIGNOF` with `alignof` and removed said function. Removed `MOZ_ALIGNAS_IN_STRUCT` (unused since bug 1572205). Differential Revision: https://phabricator.services.mozilla.com/D230730
This commit is contained in:
@@ -52,8 +52,7 @@ class AlignedAutoTArray : private AutoTArray<E, S + N> {
|
||||
AlignedAutoTArray(const AlignedAutoTArray& other) = delete;
|
||||
void operator=(const AlignedAutoTArray& other) = delete;
|
||||
|
||||
static const size_type sPadding =
|
||||
N <= MOZ_ALIGNOF(E) ? 0 : N - MOZ_ALIGNOF(E);
|
||||
static const size_type sPadding = N <= alignof(E) ? 0 : N - alignof(E);
|
||||
static const size_type sExtra = (sPadding + sizeof(E) - 1) / sizeof(E);
|
||||
|
||||
template <typename U>
|
||||
@@ -102,8 +101,7 @@ class AlignedTArray : private nsTArray_Impl<E, nsTArrayInfallibleAllocator> {
|
||||
AlignedTArray(const AlignedTArray& other) = delete;
|
||||
void operator=(const AlignedTArray& other) = delete;
|
||||
|
||||
static const size_type sPadding =
|
||||
N <= MOZ_ALIGNOF(E) ? 0 : N - MOZ_ALIGNOF(E);
|
||||
static const size_type sPadding = N <= alignof(E) ? 0 : N - alignof(E);
|
||||
static const size_type sExtra = (sPadding + sizeof(E) - 1) / sizeof(E);
|
||||
|
||||
template <typename U>
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
static_assert(MOZ_ALIGNOF(Pickle::memberAlignmentType) >= MOZ_ALIGNOF(uint32_t),
|
||||
static_assert(alignof(Pickle::memberAlignmentType) >= alignof(uint32_t),
|
||||
"Insufficient alignment");
|
||||
|
||||
static const uint32_t kHeaderSegmentCapacity = 64;
|
||||
@@ -62,7 +62,7 @@ struct Copier<T, sizeof(uint64_t), false> {
|
||||
# else
|
||||
static const int loIndex = 1, hiIndex = 0;
|
||||
# endif
|
||||
static_assert(MOZ_ALIGNOF(uint32_t*) == MOZ_ALIGNOF(void*),
|
||||
static_assert(alignof(uint32_t*) == alignof(void*),
|
||||
"Pointers have different alignments");
|
||||
const uint32_t* src = reinterpret_cast<const uint32_t*>(iter);
|
||||
uint32_t* uint32dest = reinterpret_cast<uint32_t*>(dest);
|
||||
@@ -76,7 +76,7 @@ template <typename T, size_t size>
|
||||
struct Copier<T, size, true> {
|
||||
static void Copy(T* dest, const char* iter) {
|
||||
// The pointer ought to be properly aligned.
|
||||
DCHECK_EQ((((uintptr_t)iter) & (MOZ_ALIGNOF(T) - 1)), 0);
|
||||
DCHECK_EQ((((uintptr_t)iter) & (alignof(T) - 1)), 0);
|
||||
*dest = *reinterpret_cast<const T*>(iter);
|
||||
}
|
||||
};
|
||||
@@ -92,9 +92,8 @@ template <typename T>
|
||||
void PickleIterator::CopyInto(T* dest) {
|
||||
static_assert(std::is_trivially_copyable<T>::value,
|
||||
"Copied type must be a POD type");
|
||||
Copier<T, sizeof(T),
|
||||
(MOZ_ALIGNOF(T) <=
|
||||
sizeof(Pickle::memberAlignmentType))>::Copy(dest, iter_.Data());
|
||||
Copier<T, sizeof(T), (alignof(T) <= sizeof(Pickle::memberAlignmentType))>::
|
||||
Copy(dest, iter_.Data());
|
||||
}
|
||||
template void PickleIterator::CopyInto<char>(char*);
|
||||
|
||||
|
||||
@@ -15,48 +15,6 @@
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
/*
|
||||
* This class, and the corresponding macro MOZ_ALIGNOF, figures out how many
|
||||
* bytes of alignment a given type needs.
|
||||
*/
|
||||
template <typename T>
|
||||
class AlignmentFinder {
|
||||
struct Aligner {
|
||||
char mChar;
|
||||
T mT;
|
||||
|
||||
// Aligner may be used to check alignment of types with deleted dtors. This
|
||||
// results in such specializations having implicitly deleted dtors, which
|
||||
// causes fatal warnings on MSVC (see bug 1481005). As we don't create
|
||||
// Aligners, we can avoid this warning by explicitly deleting the dtor.
|
||||
~Aligner() = delete;
|
||||
};
|
||||
|
||||
public:
|
||||
static const size_t alignment = sizeof(Aligner) - sizeof(T);
|
||||
};
|
||||
|
||||
#define MOZ_ALIGNOF(T) mozilla::AlignmentFinder<T>::alignment
|
||||
|
||||
namespace detail {
|
||||
template <typename T>
|
||||
struct AlignasHelper {
|
||||
T mT;
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
/*
|
||||
* Use this instead of alignof to align struct field as if it is inside
|
||||
* a struct. On some platforms, there exist types which have different
|
||||
* alignment between when it is used on its own and when it is used on
|
||||
* a struct field.
|
||||
*
|
||||
* Known examples are 64bit types (uint64_t, double) on 32bit Linux,
|
||||
* where they have 8byte alignment on their own, and 4byte alignment
|
||||
* when in struct.
|
||||
*/
|
||||
#define MOZ_ALIGNAS_IN_STRUCT(T) alignas(mozilla::detail::AlignasHelper<T>)
|
||||
|
||||
/*
|
||||
* Declare the MOZ_ALIGNED_DECL macro for declaring aligned types.
|
||||
*
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace detail {
|
||||
template <typename AlignType, typename Pointee, typename = void>
|
||||
struct AlignedChecker {
|
||||
static void test(const Pointee* aPtr) {
|
||||
MOZ_ASSERT((uintptr_t(aPtr) % MOZ_ALIGNOF(AlignType)) == 0,
|
||||
MOZ_ASSERT((uintptr_t(aPtr) % alignof(AlignType)) == 0,
|
||||
"performing a range-check with a misaligned pointer");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -65,7 +65,7 @@ nsTArray_base<Alloc, RelocationStrategy>::GetAutoArrayBufferUnsafe(
|
||||
// pointer to take into account the extra alignment in the auto array.
|
||||
|
||||
static_assert(
|
||||
sizeof(void*) != 4 || (MOZ_ALIGNOF(mozilla::AlignedElem<8>) == 8 &&
|
||||
sizeof(void*) != 4 || (alignof(mozilla::AlignedElem<8>) == 8 &&
|
||||
sizeof(AutoTArray<mozilla::AlignedElem<8>, 1>) ==
|
||||
sizeof(void*) + sizeof(nsTArrayHeader) + 4 +
|
||||
sizeof(mozilla::AlignedElem<8>)),
|
||||
|
||||
@@ -1029,7 +1029,7 @@ class nsTArray_Impl
|
||||
|
||||
// This does not use SwapArrayElements because that's unnecessarily complex.
|
||||
this->MoveConstructNonAutoArray(aOther, sizeof(value_type),
|
||||
MOZ_ALIGNOF(value_type));
|
||||
alignof(value_type));
|
||||
}
|
||||
|
||||
// The array's copy-constructor performs a 'deep' copy of the given array.
|
||||
@@ -1074,7 +1074,7 @@ class nsTArray_Impl
|
||||
self_type& operator=(self_type&& aOther) {
|
||||
if (this != &aOther) {
|
||||
Clear();
|
||||
this->MoveInit(aOther, sizeof(value_type), MOZ_ALIGNOF(value_type));
|
||||
this->MoveInit(aOther, sizeof(value_type), alignof(value_type));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@@ -1120,7 +1120,7 @@ class nsTArray_Impl
|
||||
template <typename Allocator>
|
||||
self_type& operator=(nsTArray_Impl<E, Allocator>&& aOther) {
|
||||
Clear();
|
||||
this->MoveInit(aOther, sizeof(value_type), MOZ_ALIGNOF(value_type));
|
||||
this->MoveInit(aOther, sizeof(value_type), alignof(value_type));
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -1439,7 +1439,7 @@ class nsTArray_Impl
|
||||
template <class Allocator>
|
||||
void Assign(nsTArray_Impl<E, Allocator>&& aOther) {
|
||||
Clear();
|
||||
this->MoveInit(aOther, sizeof(value_type), MOZ_ALIGNOF(value_type));
|
||||
this->MoveInit(aOther, sizeof(value_type), alignof(value_type));
|
||||
}
|
||||
|
||||
// This method call the destructor on each element of the array, empties it,
|
||||
@@ -1914,8 +1914,7 @@ class nsTArray_Impl
|
||||
|
||||
void Clear() {
|
||||
ClearAndRetainStorage();
|
||||
base_type::ShrinkCapacityToZero(sizeof(value_type),
|
||||
MOZ_ALIGNOF(value_type));
|
||||
base_type::ShrinkCapacityToZero(sizeof(value_type), alignof(value_type));
|
||||
}
|
||||
|
||||
// This method removes elements based on the return value of the
|
||||
@@ -1981,7 +1980,7 @@ class nsTArray_Impl
|
||||
// AutoTArray upcast to nsTArray_Impl, under the conditions mentioned in the
|
||||
// overload for AutoTArray below.
|
||||
this->template SwapArrayElements<InfallibleAlloc>(
|
||||
aOther, sizeof(value_type), MOZ_ALIGNOF(value_type));
|
||||
aOther, sizeof(value_type), alignof(value_type));
|
||||
}
|
||||
|
||||
template <size_t N>
|
||||
@@ -1992,7 +1991,7 @@ class nsTArray_Impl
|
||||
static_assert(!std::is_same_v<Alloc, FallibleAlloc> ||
|
||||
sizeof(E) * N <= 1024);
|
||||
this->template SwapArrayElements<InfallibleAlloc>(
|
||||
aOther, sizeof(value_type), MOZ_ALIGNOF(value_type));
|
||||
aOther, sizeof(value_type), alignof(value_type));
|
||||
}
|
||||
|
||||
template <class Allocator>
|
||||
@@ -2002,7 +2001,7 @@ class nsTArray_Impl
|
||||
// Allocator==InfallibleAlloc and aOther uses auto storage.
|
||||
return FallibleAlloc::Result(
|
||||
this->template SwapArrayElements<FallibleAlloc>(
|
||||
aOther, sizeof(value_type), MOZ_ALIGNOF(value_type)));
|
||||
aOther, sizeof(value_type), alignof(value_type)));
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -2278,7 +2277,7 @@ class nsTArray_Impl
|
||||
template <typename ActualAlloc>
|
||||
value_type* InsertElementsAtInternal(index_type aIndex, size_type aCount) {
|
||||
if (!ActualAlloc::Successful(this->template InsertSlotsAt<ActualAlloc>(
|
||||
aIndex, aCount, sizeof(value_type), MOZ_ALIGNOF(value_type)))) {
|
||||
aIndex, aCount, sizeof(value_type), alignof(value_type)))) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -2321,9 +2320,7 @@ class nsTArray_Impl
|
||||
}
|
||||
|
||||
// This method may be called to minimize the memory used by this array.
|
||||
void Compact() {
|
||||
ShrinkCapacity(sizeof(value_type), MOZ_ALIGNOF(value_type));
|
||||
}
|
||||
void Compact() { ShrinkCapacity(sizeof(value_type), alignof(value_type)); }
|
||||
|
||||
//
|
||||
// Sorting
|
||||
@@ -2466,7 +2463,7 @@ auto nsTArray_Impl<E, Alloc>::ReplaceElementsAtInternal(index_type aStart,
|
||||
}
|
||||
DestructRange(aStart, aCount);
|
||||
this->template ShiftData<ActualAlloc>(
|
||||
aStart, aCount, aArrayLen, sizeof(value_type), MOZ_ALIGNOF(value_type));
|
||||
aStart, aCount, aArrayLen, sizeof(value_type), alignof(value_type));
|
||||
AssignRange(aStart, aArrayLen, aArray);
|
||||
return Elements() + aStart;
|
||||
}
|
||||
@@ -2491,7 +2488,7 @@ void nsTArray_Impl<E, Alloc>::RemoveElementsAtUnsafe(index_type aStart,
|
||||
size_type aCount) {
|
||||
DestructRange(aStart, aCount);
|
||||
this->template ShiftData<InfallibleAlloc>(
|
||||
aStart, aCount, 0, sizeof(value_type), MOZ_ALIGNOF(value_type));
|
||||
aStart, aCount, 0, sizeof(value_type), alignof(value_type));
|
||||
}
|
||||
|
||||
template <typename E, class Alloc>
|
||||
@@ -2511,7 +2508,7 @@ void nsTArray_Impl<E, Alloc>::UnorderedRemoveElementsAt(index_type aStart,
|
||||
// function.
|
||||
DestructRange(aStart, aCount);
|
||||
this->template SwapFromEnd<InfallibleAlloc>(
|
||||
aStart, aCount, sizeof(value_type), MOZ_ALIGNOF(value_type));
|
||||
aStart, aCount, sizeof(value_type), alignof(value_type));
|
||||
}
|
||||
|
||||
template <typename E, class Alloc>
|
||||
@@ -2554,7 +2551,7 @@ auto nsTArray_Impl<E, Alloc>::InsertElementsAtInternal(index_type aIndex,
|
||||
const Item& aItem)
|
||||
-> value_type* {
|
||||
if (!ActualAlloc::Successful(this->template InsertSlotsAt<ActualAlloc>(
|
||||
aIndex, aCount, sizeof(value_type), MOZ_ALIGNOF(value_type)))) {
|
||||
aIndex, aCount, sizeof(value_type), alignof(value_type)))) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -2582,7 +2579,7 @@ auto nsTArray_Impl<E, Alloc>::InsertElementAtInternal(index_type aIndex)
|
||||
return nullptr;
|
||||
}
|
||||
this->template ShiftData<ActualAlloc>(aIndex, 0, 1, sizeof(value_type),
|
||||
MOZ_ALIGNOF(value_type));
|
||||
alignof(value_type));
|
||||
value_type* elem = Elements() + aIndex;
|
||||
elem_traits::Construct(elem);
|
||||
return elem;
|
||||
@@ -2603,7 +2600,7 @@ auto nsTArray_Impl<E, Alloc>::InsertElementAtInternal(index_type aIndex,
|
||||
return nullptr;
|
||||
}
|
||||
this->template ShiftData<ActualAlloc>(aIndex, 0, 1, sizeof(value_type),
|
||||
MOZ_ALIGNOF(value_type));
|
||||
alignof(value_type));
|
||||
value_type* elem = Elements() + aIndex;
|
||||
elem_traits::Construct(elem, std::forward<Item>(aItem));
|
||||
return elem;
|
||||
@@ -2634,8 +2631,8 @@ auto nsTArray_Impl<E, Alloc>::AppendElementsInternal(
|
||||
if (Length() == 0) {
|
||||
// XXX This might still be optimized. If aArray uses auto-storage but we
|
||||
// won't, we might better retain our storage if it's sufficiently large.
|
||||
this->ShrinkCapacityToZero(sizeof(value_type), MOZ_ALIGNOF(value_type));
|
||||
this->MoveInit(aArray, sizeof(value_type), MOZ_ALIGNOF(value_type));
|
||||
this->ShrinkCapacityToZero(sizeof(value_type), alignof(value_type));
|
||||
this->MoveInit(aArray, sizeof(value_type), alignof(value_type));
|
||||
return Elements();
|
||||
}
|
||||
|
||||
@@ -2649,7 +2646,7 @@ auto nsTArray_Impl<E, Alloc>::AppendElementsInternal(
|
||||
Elements() + len, aArray.Elements(), otherLen, sizeof(value_type));
|
||||
this->IncrementLength(otherLen);
|
||||
aArray.template ShiftData<ActualAlloc>(0, otherLen, 0, sizeof(value_type),
|
||||
MOZ_ALIGNOF(value_type));
|
||||
alignof(value_type));
|
||||
return Elements() + len;
|
||||
}
|
||||
|
||||
@@ -3022,18 +3019,18 @@ class MOZ_NON_MEMMOVABLE AutoTArray : public nsTArray<E> {
|
||||
|
||||
AutoTArray(self_type&& aOther) : nsTArray<E>() {
|
||||
Init();
|
||||
this->MoveInit(aOther, sizeof(value_type), MOZ_ALIGNOF(value_type));
|
||||
this->MoveInit(aOther, sizeof(value_type), alignof(value_type));
|
||||
}
|
||||
|
||||
explicit AutoTArray(base_type&& aOther) : mAlign() {
|
||||
Init();
|
||||
this->MoveInit(aOther, sizeof(value_type), MOZ_ALIGNOF(value_type));
|
||||
this->MoveInit(aOther, sizeof(value_type), alignof(value_type));
|
||||
}
|
||||
|
||||
template <typename Allocator>
|
||||
explicit AutoTArray(nsTArray_Impl<value_type, Allocator>&& aOther) {
|
||||
Init();
|
||||
this->MoveInit(aOther, sizeof(value_type), MOZ_ALIGNOF(value_type));
|
||||
this->MoveInit(aOther, sizeof(value_type), alignof(value_type));
|
||||
}
|
||||
|
||||
MOZ_IMPLICIT AutoTArray(std::initializer_list<E> aIL) : mAlign() {
|
||||
@@ -3067,7 +3064,7 @@ class MOZ_NON_MEMMOVABLE AutoTArray : public nsTArray<E> {
|
||||
friend class nsTArray_base;
|
||||
|
||||
void Init() {
|
||||
static_assert(MOZ_ALIGNOF(value_type) <= 8,
|
||||
static_assert(alignof(value_type) <= 8,
|
||||
"can't handle alignments greater than 8, "
|
||||
"see nsTArray_base::UsesAutoArrayBuffer()");
|
||||
// Temporary work around for VS2012 RC compiler crash
|
||||
@@ -3077,7 +3074,7 @@ class MOZ_NON_MEMMOVABLE AutoTArray : public nsTArray<E> {
|
||||
(*phdr)->mCapacity = N;
|
||||
(*phdr)->mIsAutoArray = 1;
|
||||
|
||||
MOZ_ASSERT(base_type::GetAutoArrayBuffer(MOZ_ALIGNOF(value_type)) ==
|
||||
MOZ_ASSERT(base_type::GetAutoArrayBuffer(alignof(value_type)) ==
|
||||
reinterpret_cast<Header*>(&mAutoBuf),
|
||||
"GetAutoArrayBuffer needs to be fixed");
|
||||
}
|
||||
@@ -3089,9 +3086,9 @@ class MOZ_NON_MEMMOVABLE AutoTArray : public nsTArray<E> {
|
||||
union {
|
||||
char mAutoBuf[sizeof(nsTArrayHeader) + N * sizeof(value_type)];
|
||||
// Do the max operation inline to ensure that it is a compile-time constant.
|
||||
mozilla::AlignedElem<(MOZ_ALIGNOF(Header) > MOZ_ALIGNOF(value_type))
|
||||
? MOZ_ALIGNOF(Header)
|
||||
: MOZ_ALIGNOF(value_type)>
|
||||
mozilla::AlignedElem<(alignof(Header) > alignof(value_type))
|
||||
? alignof(Header)
|
||||
: alignof(value_type)>
|
||||
mAlign;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -113,7 +113,7 @@ static_assert(offsetof(nsXPTCVariant, val) == offsetof(nsXPTCVariant, ext),
|
||||
#define XPT_CHECK_SIZEOF(xpt, type) \
|
||||
static_assert(sizeof(nsXPTCVariant::ExtendedVal) >= sizeof(type), \
|
||||
"nsXPTCVariant::ext not big enough for " #xpt " (" #type ")"); \
|
||||
static_assert(MOZ_ALIGNOF(nsXPTCVariant::ExtendedVal) >= MOZ_ALIGNOF(type), \
|
||||
static_assert(alignof(nsXPTCVariant::ExtendedVal) >= alignof(type), \
|
||||
"nsXPTCVariant::ext not aligned enough for " #xpt " (" #type \
|
||||
")");
|
||||
XPT_FOR_EACH_TYPE(XPT_CHECK_SIZEOF)
|
||||
|
||||
Reference in New Issue
Block a user