Bug N - Replace MOZ_ALIGNOF with alignof
authorBirunthan Mohanathas <birunthan@mohanathas.com>
Thu, 02 Jun 2016 10:59:05 +0300
changeset 774789 ca40601a5a58b3f4df37e1c29c3074d89ec58efb
parent 774136 22047a4eea784c15026c77911c0bd6ea1b70fa68
child 774790 8c8aeaf77fb93670237868ba0fd57d8a15c83e74
push id128077
push userbirunthan@mohanathas.com
push dateThu, 02 Jun 2016 08:32:21 +0000
treeherdertry@a2504e1cce5b [default view] [failures only]
milestone49.0a1
Bug N - Replace MOZ_ALIGNOF with alignof
dom/media/webaudio/AlignedTArray.h
js/src/builtin/TypedObject.cpp
js/src/vm/TypedArrayObject.cpp
mfbt/Alignment.h
mfbt/ArrayUtils.h
mfbt/SegmentedVector.h
xpcom/glue/nsTArray-inl.h
xpcom/glue/nsTArray.h
--- a/dom/media/webaudio/AlignedTArray.h
+++ b/dom/media/webaudio/AlignedTArray.h
@@ -48,17 +48,17 @@ public:
 
   using base_type::ShallowSizeOfExcludingThis;
   using base_type::ShallowSizeOfIncludingThis;
 
 private:
   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>
   static U* getAligned(U* p)
   {
     return reinterpret_cast<U*>(((uintptr_t)p + N - 1) & ~(N-1));
   }
 };
--- a/js/src/builtin/TypedObject.cpp
+++ b/js/src/builtin/TypedObject.cpp
@@ -2602,17 +2602,17 @@ js::StoreScalar##T::Func(JSContext*, uns
     MOZ_ASSERT(args[0].isObject() && args[0].toObject().is<TypedObject>());     \
     MOZ_ASSERT(args[1].isInt32());                                              \
     MOZ_ASSERT(args[2].isNumber());                                             \
                                                                                 \
     TypedObject& typedObj = args[0].toObject().as<TypedObject>();               \
     int32_t offset = args[1].toInt32();                                         \
                                                                                 \
     /* Should be guaranteed by the typed objects API: */                        \
-    MOZ_ASSERT(offset % MOZ_ALIGNOF(T) == 0);                                   \
+    MOZ_ASSERT(offset % alignof(T) == 0);                                   \
                                                                                 \
     T* target = reinterpret_cast<T*>(typedObj.typedMem(offset));                \
     double d = args[2].toNumber();                                              \
     *target = ConvertScalar<T>(d);                                              \
     args.rval().setUndefined();                                                 \
     return true;                                                                \
 }
 
@@ -2629,17 +2629,17 @@ js::StoreReference##_name::Func(JSContex
     TypedObject& typedObj = args[0].toObject().as<TypedObject>();               \
     int32_t offset = args[1].toInt32();                                         \
                                                                                 \
     jsid id = args[2].isString()                                                \
               ? IdToTypeId(AtomToId(&args[2].toString()->asAtom()))             \
               : JSID_VOID;                                                      \
                                                                                 \
     /* Should be guaranteed by the typed objects API: */                        \
-    MOZ_ASSERT(offset % MOZ_ALIGNOF(T) == 0);                                   \
+    MOZ_ASSERT(offset % alignof(T) == 0);                                   \
                                                                                 \
     T* target = reinterpret_cast<T*>(typedObj.typedMem(offset));                \
     if (!store(cx, target, args[3], &typedObj, id))                             \
         return false;                                                           \
     args.rval().setUndefined();                                                 \
     return true;                                                                \
 }
 
@@ -2651,17 +2651,17 @@ js::LoadScalar##T::Func(JSContext*, unsi
     MOZ_ASSERT(args.length() == 2);                                                     \
     MOZ_ASSERT(args[0].isObject() && args[0].toObject().is<TypedObject>());             \
     MOZ_ASSERT(args[1].isInt32());                                                      \
                                                                                         \
     TypedObject& typedObj = args[0].toObject().as<TypedObject>();                       \
     int32_t offset = args[1].toInt32();                                                 \
                                                                                         \
     /* Should be guaranteed by the typed objects API: */                                \
-    MOZ_ASSERT(offset % MOZ_ALIGNOF(T) == 0);                                           \
+    MOZ_ASSERT(offset % alignof(T) == 0);                                           \
                                                                                         \
     T* target = reinterpret_cast<T*>(typedObj.typedMem(offset));                        \
     args.rval().setNumber((double) *target);                                            \
     return true;                                                                        \
 }
 
 #define JS_LOAD_REFERENCE_CLASS_IMPL(_constant, T, _name)                       \
 bool                                                                            \
@@ -2671,17 +2671,17 @@ js::LoadReference##_name::Func(JSContext
     MOZ_ASSERT(args.length() == 2);                                             \
     MOZ_ASSERT(args[0].isObject() && args[0].toObject().is<TypedObject>());     \
     MOZ_ASSERT(args[1].isInt32());                                              \
                                                                                 \
     TypedObject& typedObj = args[0].toObject().as<TypedObject>();               \
     int32_t offset = args[1].toInt32();                                         \
                                                                                 \
     /* Should be guaranteed by the typed objects API: */                        \
-    MOZ_ASSERT(offset % MOZ_ALIGNOF(T) == 0);                                   \
+    MOZ_ASSERT(offset % alignof(T) == 0);                                   \
                                                                                 \
     T* target = reinterpret_cast<T*>(typedObj.typedMem(offset));                \
     load(target, args.rval());                                                  \
     return true;                                                                \
 }
 
 // Because the precise syntax for storing values/objects/strings
 // differs, we abstract it away using specialized variants of the
--- a/js/src/vm/TypedArrayObject.cpp
+++ b/js/src/vm/TypedArrayObject.cpp
@@ -1560,27 +1560,27 @@ template <> struct DataToRepType<double>
 
 template <typename DataType>
 struct DataViewIO
 {
     typedef typename DataToRepType<DataType>::result ReadWriteType;
 
     static void fromBuffer(DataType* dest, const uint8_t* unalignedBuffer, bool wantSwap)
     {
-        MOZ_ASSERT((reinterpret_cast<uintptr_t>(dest) & (Min<size_t>(MOZ_ALIGNOF(void*), sizeof(DataType)) - 1)) == 0);
+        MOZ_ASSERT((reinterpret_cast<uintptr_t>(dest) & (Min<size_t>(alignof(void*), sizeof(DataType)) - 1)) == 0);
         memcpy((void*) dest, unalignedBuffer, sizeof(ReadWriteType));
         if (wantSwap) {
             ReadWriteType* rwDest = reinterpret_cast<ReadWriteType*>(dest);
             *rwDest = swapBytes(*rwDest);
         }
     }
 
     static void toBuffer(uint8_t* unalignedBuffer, const DataType* src, bool wantSwap)
     {
-        MOZ_ASSERT((reinterpret_cast<uintptr_t>(src) & (Min<size_t>(MOZ_ALIGNOF(void*), sizeof(DataType)) - 1)) == 0);
+        MOZ_ASSERT((reinterpret_cast<uintptr_t>(src) & (Min<size_t>(alignof(void*), sizeof(DataType)) - 1)) == 0);
         ReadWriteType temp = *reinterpret_cast<const ReadWriteType*>(src);
         if (wantSwap)
             temp = swapBytes(temp);
         memcpy(unalignedBuffer, (void*) &temp, sizeof(ReadWriteType));
     }
 };
 
 template<typename NativeType>
--- a/mfbt/Alignment.h
+++ b/mfbt/Alignment.h
@@ -11,35 +11,16 @@
 
 #include "mozilla/Attributes.h"
 #include <stddef.h>
 #include <stdint.h>
 
 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;
-  };
-
-public:
-  static const size_t alignment = sizeof(Aligner) - sizeof(T);
-};
-
-#define MOZ_ALIGNOF(T) mozilla::AlignmentFinder<T>::alignment
-
-/*
  * Declare the MOZ_ALIGNED_DECL macro for declaring aligned types.
  *
  * For instance,
  *
  *   MOZ_ALIGNED_DECL(char arr[2], 8);
  *
  * will declare a two-character array |arr| aligned to 8 bytes.
  */
--- a/mfbt/ArrayUtils.h
+++ b/mfbt/ArrayUtils.h
@@ -102,17 +102,17 @@ namespace detail {
 
 template<typename AlignType, typename Pointee,
          typename = EnableIf<!IsVoid<AlignType>::value>>
 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");
   }
 };
 
 template<typename AlignType, typename Pointee>
 struct AlignedChecker<AlignType, Pointee>
 {
   static void
--- a/mfbt/SegmentedVector.h
+++ b/mfbt/SegmentedVector.h
@@ -100,20 +100,20 @@ class SegmentedVector : private AllocPol
     }
 
     uint32_t mLength;
 
     // The union ensures that the elements are appropriately aligned.
     union Storage
     {
       char mBuf[sizeof(T) * SegmentCapacity];
-      mozilla::AlignedElem<MOZ_ALIGNOF(T)> mAlign;
+      mozilla::AlignedElem<alignof(T)> mAlign;
     } mStorage;
 
-    static_assert(MOZ_ALIGNOF(T) == MOZ_ALIGNOF(Storage),
+    static_assert(alignof(T) == alignof(Storage),
                   "SegmentedVector provides incorrect alignment");
   };
 
   // See how many we elements we can fit in a segment of IdealSegmentSize. If
   // IdealSegmentSize is too small, it'll be just one. The +1 is because
   // kSingleElementSegmentSize already accounts for one element.
   static const size_t kSingleElementSegmentSize = sizeof(SegmentImpl<1>);
   static const size_t kSegmentCapacity =
--- a/xpcom/glue/nsTArray-inl.h
+++ b/xpcom/glue/nsTArray-inl.h
@@ -33,17 +33,17 @@ nsTArray_base<Alloc, Copy>::GetAutoArray
 
   const void* autoBuf =
     &reinterpret_cast<const AutoTArray<nsTArray<uint32_t>, 1>*>(this)->mAutoBuf;
 
   // If we're on a 32-bit system and aElemAlign is 8, we need to adjust our
   // pointer to take into account the extra alignment in the auto array.
 
   static_assert(sizeof(void*) != 4 ||
-                (MOZ_ALIGNOF(mozilla::AlignedElem<8>) == 8 &&
+                (alignof(mozilla::AlignedElem<8>) == 8 &&
                  sizeof(AutoTArray<mozilla::AlignedElem<8>, 1>) ==
                    sizeof(void*) + sizeof(nsTArrayHeader) +
                    4 + sizeof(mozilla::AlignedElem<8>)),
                 "auto array padding wasn't what we expected");
 
   // We don't support alignments greater than 8 bytes.
   MOZ_ASSERT(aElemAlign <= 4 || aElemAlign == 8,
              "unsupported alignment.");
--- a/xpcom/glue/nsTArray.h
+++ b/xpcom/glue/nsTArray.h
@@ -1265,17 +1265,17 @@ protected:
     // Adjust memory allocation up-front to catch errors.
     if (!ActualAlloc::Successful(this->template EnsureCapacity<ActualAlloc>(
           Length() + aArrayLen - aCount, sizeof(elem_type)))) {
       return nullptr;
     }
     DestructRange(aStart, aCount);
     this->template ShiftData<ActualAlloc>(aStart, aCount, aArrayLen,
                                           sizeof(elem_type),
-                                          MOZ_ALIGNOF(elem_type));
+                                          alignof(elem_type));
     AssignRange(aStart, aArrayLen, aArray);
     return Elements() + aStart;
   }
 public:
 
   template<class Item>
   MOZ_MUST_USE
   elem_type* ReplaceElementsAt(index_type aStart, size_type aCount,
@@ -1376,17 +1376,17 @@ protected:
   template<typename ActualAlloc = Alloc>
   elem_type* InsertElementAt(index_type aIndex)
   {
     if (!ActualAlloc::Successful(this->template EnsureCapacity<ActualAlloc>(
           Length() + 1, sizeof(elem_type)))) {
       return nullptr;
     }
     this->template ShiftData<ActualAlloc>(aIndex, 0, 1, sizeof(elem_type),
-                                          MOZ_ALIGNOF(elem_type));
+                                          alignof(elem_type));
     elem_type* elem = Elements() + aIndex;
     elem_traits::Construct(elem);
     return elem;
   }
 public:
 
   MOZ_MUST_USE
   elem_type* InsertElementAt(index_type aIndex, const mozilla::fallible_t&)
@@ -1399,17 +1399,17 @@ protected:
   template<class Item, typename ActualAlloc = Alloc>
   elem_type* InsertElementAt(index_type aIndex, Item&& aItem)
   {
     if (!ActualAlloc::Successful(this->template EnsureCapacity<ActualAlloc>(
           Length() + 1, sizeof(elem_type)))) {
       return nullptr;
     }
     this->template ShiftData<ActualAlloc>(aIndex, 0, 1, sizeof(elem_type),
-                                          MOZ_ALIGNOF(elem_type));
+                                          alignof(elem_type));
     elem_type* elem = Elements() + aIndex;
     elem_traits::Construct(elem, mozilla::Forward<Item>(aItem));
     return elem;
   }
 public:
 
   template<class Item>
   MOZ_MUST_USE
@@ -1558,17 +1558,17 @@ protected:
     if (!Alloc::Successful(this->template EnsureCapacity<Alloc>(
           len + otherLen, sizeof(elem_type)))) {
       return nullptr;
     }
     copy_type::CopyElements(Elements() + len, aArray.Elements(), otherLen,
                             sizeof(elem_type));
     this->IncrementLength(otherLen);
     aArray.template ShiftData<Alloc>(0, otherLen, 0, sizeof(elem_type),
-                                     MOZ_ALIGNOF(elem_type));
+                                     alignof(elem_type));
     return Elements() + len;
   }
 public:
 
   template<class Item, class Allocator, typename ActualAlloc = Alloc>
   /* MOZ_MUST_USE */
   elem_type* AppendElements(nsTArray_Impl<Item, Allocator>&& aArray,
                             const mozilla::fallible_t&)
@@ -1651,17 +1651,17 @@ public:
   {
     MOZ_ASSERT(aCount == 0 || aStart < Length(), "Invalid aStart index");
     MOZ_ASSERT(aStart + aCount <= Length(), "Invalid length");
     // Check that the previous assert didn't overflow
     MOZ_ASSERT(aStart <= aStart + aCount, "Start index plus length overflows");
     DestructRange(aStart, aCount);
     this->template ShiftData<InfallibleAlloc>(aStart, aCount, 0,
                                               sizeof(elem_type),
-                                              MOZ_ALIGNOF(elem_type));
+                                              alignof(elem_type));
   }
 
   // A variation on the RemoveElementsAt method defined above.
   void RemoveElementAt(index_type aIndex) { RemoveElementsAt(aIndex, 1); }
 
   // A variation on the RemoveElementsAt method defined above.
   void Clear() { RemoveElementsAt(0, Length()); }
 
@@ -1715,17 +1715,17 @@ public:
   }
 
   // This method causes the elements contained in this array and the given
   // array to be swapped.
   template<class Allocator>
   typename Alloc::ResultType SwapElements(nsTArray_Impl<E, Allocator>& aOther)
   {
     return Alloc::Result(this->template SwapArrayElements<Alloc>(
-      aOther, sizeof(elem_type), MOZ_ALIGNOF(elem_type)));
+      aOther, sizeof(elem_type), alignof(elem_type)));
   }
 
   //
   // Allocation
   //
 
   // This method may increase the capacity of this array object by the
   // specified amount.  This method may be called in advance of several
@@ -1822,17 +1822,17 @@ public:
   //               greater than the current length of the array.
   // @param aCount the number of elements to insert
 protected:
   template<typename ActualAlloc = Alloc>
   elem_type* InsertElementsAt(index_type aIndex, size_type aCount)
   {
     if (!base_type::template InsertSlotsAt<ActualAlloc>(aIndex, aCount,
                                                         sizeof(elem_type),
-                                                        MOZ_ALIGNOF(elem_type))) {
+                                                        alignof(elem_type))) {
       return nullptr;
     }
 
     // Initialize the extra array elements
     elem_type* iter = Elements() + aIndex;
     elem_type* iend = iter + aCount;
     for (; iter != iend; ++iter) {
       elem_traits::Construct(iter);
@@ -1858,17 +1858,17 @@ public:
   // @param aItem the value to use when constructing the new elements.
 protected:
   template<class Item, typename ActualAlloc = Alloc>
   elem_type* InsertElementsAt(index_type aIndex, size_type aCount,
                               const Item& aItem)
   {
     if (!base_type::template InsertSlotsAt<ActualAlloc>(aIndex, aCount,
                                                         sizeof(elem_type),
-                                                        MOZ_ALIGNOF(elem_type))) {
+                                                        alignof(elem_type))) {
       return nullptr;
     }
 
     // Initialize the extra array elements
     elem_type* iter = Elements() + aIndex;
     elem_type* iend = iter + aCount;
     for (; iter != iend; ++iter) {
       elem_traits::Construct(iter, aItem);
@@ -1884,17 +1884,17 @@ public:
                               const Item& aItem, const mozilla::fallible_t&)
   {
     return InsertElementsAt<Item, FallibleAlloc>(aIndex, aCount, aItem);
   }
 
   // This method may be called to minimize the memory used by this array.
   void Compact()
   {
-    ShrinkCapacity(sizeof(elem_type), MOZ_ALIGNOF(elem_type));
+    ShrinkCapacity(sizeof(elem_type), alignof(elem_type));
   }
 
   //
   // Sorting
   //
 
   // This function is meant to be used with the NS_QuickSort function.  It
   // maps the callback API expected by NS_QuickSort to the Comparator API
@@ -1948,17 +1948,17 @@ public:
 
   // Adds an element to the heap
   // @param aItem The item to add
   // @param aComp The Comparator used to sift-up the item
   template<class Item, class Comparator>
   elem_type* PushHeap(const Item& aItem, const Comparator& aComp)
   {
     if (!base_type::template InsertSlotsAt<Alloc>(Length(), 1, sizeof(elem_type),
-                                                  MOZ_ALIGNOF(elem_type))) {
+                                                  alignof(elem_type))) {
       return nullptr;
     }
     // Sift up the new node
     elem_type* elem = Elements();
     index_type index = Length() - 1;
     index_type parent_index = (index - 1) / 2;
     while (index && aComp.LessThan(elem[parent_index], aItem)) {
       elem[index] = elem[parent_index];
@@ -2257,41 +2257,41 @@ public:
 private:
   // nsTArray_base casts itself as an nsAutoArrayBase in order to get a pointer
   // to mAutoBuf.
   template<class Allocator, class Copier>
   friend class nsTArray_base;
 
   void Init()
   {
-    static_assert(MOZ_ALIGNOF(elem_type) <= 8,
+    static_assert(alignof(elem_type) <= 8,
                   "can't handle alignments greater than 8, "
                   "see nsTArray_base::UsesAutoArrayBuffer()");
     // Temporary work around for VS2012 RC compiler crash
     Header** phdr = base_type::PtrToHdr();
     *phdr = reinterpret_cast<Header*>(&mAutoBuf);
     (*phdr)->mLength = 0;
     (*phdr)->mCapacity = N;
     (*phdr)->mIsAutoArray = 1;
 
-    MOZ_ASSERT(base_type::GetAutoArrayBuffer(MOZ_ALIGNOF(elem_type)) ==
+    MOZ_ASSERT(base_type::GetAutoArrayBuffer(alignof(elem_type)) ==
                reinterpret_cast<Header*>(&mAutoBuf),
                "GetAutoArrayBuffer needs to be fixed");
   }
 
   // Declare mAutoBuf aligned to the maximum of the header's alignment and
   // elem_type's alignment.  We need to use a union rather than
   // MOZ_ALIGNED_DECL because GCC is picky about what goes into
   // __attribute__((aligned(foo))).
   union
   {
     char mAutoBuf[sizeof(nsTArrayHeader) + N * sizeof(elem_type)];
     // Do the max operation inline to ensure that it is a compile-time constant.
-    mozilla::AlignedElem<(MOZ_ALIGNOF(Header) > MOZ_ALIGNOF(elem_type)) ?
-                         MOZ_ALIGNOF(Header) : MOZ_ALIGNOF(elem_type)> mAlign;
+    mozilla::AlignedElem<(alignof(Header) > alignof(elem_type)) ?
+                         alignof(Header) : alignof(elem_type)> mAlign;
   };
 };
 
 //
 // Specialization of AutoTArray<E, N> for the case where N == 0.
 // AutoTArray<E, 0> behaves exactly like nsTArray<E>, but without this
 // specialization, it stores a useless inline header.
 //