| Index: src/lazy-instance.h
|
| diff --git a/src/lazy-instance.h b/src/lazy-instance.h
|
| index 4beb55c0a291b05cf91bde23ffd8af03f1be9f6a..d0893e560470ee345adbd1af45cd295b998fc610 100644
|
| --- a/src/lazy-instance.h
|
| +++ b/src/lazy-instance.h
|
| @@ -107,9 +107,17 @@ struct LeakyInstanceTrait {
|
|
|
| // Traits that define how an instance is allocated and accessed.
|
|
|
| +// TODO(kalmard): __alignof__ is only defined for GCC > 4.2. Fix alignment issue
|
| +// on MIPS with other compilers.
|
| +#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 2))
|
| +#define LAZY_ALIGN(x) __attribute__((aligned(__alignof__(x))))
|
| +#else
|
| +#define LAZY_ALIGN(x)
|
| +#endif
|
| +
|
| template <typename T>
|
| struct StaticallyAllocatedInstanceTrait {
|
| - typedef char StorageType[sizeof(T)];
|
| + typedef char StorageType[sizeof(T)] LAZY_ALIGN(T);
|
|
|
| static T* MutableInstance(StorageType* storage) {
|
| return reinterpret_cast<T*>(storage);
|
| @@ -121,6 +129,8 @@ struct StaticallyAllocatedInstanceTrait {
|
| }
|
| };
|
|
|
| +#undef LAZY_ALIGN
|
| +
|
|
|
| template <typename T>
|
| struct DynamicallyAllocatedInstanceTrait {
|
| @@ -208,7 +218,8 @@ struct LazyInstanceImpl {
|
|
|
| mutable OnceType once_;
|
| // Note that the previous field, OnceType, is an AtomicWord which guarantees
|
| - // the correct alignment of the storage field below.
|
| + // 4-byte alignment of the storage field below. If compiling with GCC (>4.2),
|
| + // the LAZY_ALIGN macro above will guarantee correctness for any alignment.
|
| mutable StorageType storage_;
|
| };
|
|
|
|
|