Bug 1391103 - Align Maybe::mStorage like when the type is in a struct. r=froydnj

MozReview-Commit-ID: 6ArNhZA4Wdf

--HG--
extra : rebase_source : f69ae80c146f2acb308a6c9707aac7ee22f5d992
This commit is contained in:
Xidorn Quan 2017-08-17 09:49:19 +10:00
parent 91f1f19054
commit 667a3cb5a4
2 changed files with 21 additions and 1 deletions

View File

@ -34,6 +34,26 @@ public:
#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.
*

View File

@ -85,7 +85,7 @@ struct Nothing { };
template<class T>
class MOZ_NON_PARAM MOZ_INHERIT_TYPE_ANNOTATIONS_FROM_TEMPLATE_ARGS Maybe
{
alignas(T) unsigned char mStorage[sizeof(T)];
MOZ_ALIGNAS_IN_STRUCT(T) unsigned char mStorage[sizeof(T)];
char mIsSome; // not bool -- guarantees minimal space consumption
// GCC fails due to -Werror=strict-aliasing if |mStorage| is directly cast to