Index: base/lazy_instance_unittest.cc |
diff --git a/base/lazy_instance_unittest.cc b/base/lazy_instance_unittest.cc |
index 1bd3ab4a7a7a57b3087f5173841ac084f5826f02..01ce8e5cd54e6cd98d3e0ec5eb2d859336fb6d2c 100644 |
--- a/base/lazy_instance_unittest.cc |
+++ b/base/lazy_instance_unittest.cc |
@@ -5,6 +5,7 @@ |
#include "base/at_exit.h" |
#include "base/atomic_sequence_num.h" |
#include "base/lazy_instance.h" |
+#include "base/memory/aligned_memory.h" |
#include "base/threading/simple_thread.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -139,3 +140,33 @@ TEST(LazyInstanceTest, LeakyLazyInstance) { |
} |
EXPECT_FALSE(deleted2); |
} |
+ |
+namespace { |
+ |
+template <size_t alignment> |
+class AlignedData { |
+ public: |
+ AlignedData() {} |
+ ~AlignedData() {} |
+ base::AlignedMemory<alignment, alignment> data_; |
+}; |
+ |
+} // anonymous namespace |
+ |
+#define EXPECT_ALIGNED(ptr, align) \ |
+ EXPECT_EQ(0u, reinterpret_cast<uintptr_t>(ptr) & (align - 1)) |
+ |
+TEST(LazyInstanceTest, Alignment) { |
+ using base::LazyInstance; |
+ |
+ // Create some static instances with increasing sizes and alignment |
+ // requirements. By ordering this way, the linker will need to do some work to |
+ // ensure proper alignment of the static data. |
+ static LazyInstance<AlignedData<4> > align4 = LAZY_INSTANCE_INITIALIZER; |
+ static LazyInstance<AlignedData<32> > align32 = LAZY_INSTANCE_INITIALIZER; |
+ static LazyInstance<AlignedData<4096> > align4096 = LAZY_INSTANCE_INITIALIZER; |
+ |
+ EXPECT_ALIGNED(align4.Pointer(), 4); |
+ EXPECT_ALIGNED(align32.Pointer(), 32); |
+ EXPECT_ALIGNED(align4096.Pointer(), 4096); |
+} |