mirror of
https://github.com/chromium/crashpad.git
synced 2024-12-27 07:14:10 +08:00
Use the C++11-standardized alignof instead of ALIGNOF
Use the standard alignas instead of ALIGNAS in cases where this is possible too. It’s not currently possible where ALIGNAS may be mixed with other attributes, although the not-landed https://codereview.chromium.org/2670873002/ suggests that where ALIGNAS is mixed with __attribute__((packed)), it’s viable to write “struct alignas(4) S { /* … */ } __attribute__((packed));”. This includes an update of mini_chromium to 723e840a2f100a525f7feaad2e93df31d701780a, picking up: 723e840a2f10 Remove ALIGNOF This tracks upstream https://codereview.chromium.org/2932053002/. Change-Id: I7ddaf829020ef3be0512f803cecbb7c543294f07 Reviewed-on: https://chromium-review.googlesource.com/533356 Reviewed-by: Scott Graham <scottmg@chromium.org> Commit-Queue: Mark Mentovai <mark@chromium.org>
This commit is contained in:
parent
1c0c305bc9
commit
8c35d92ae4
2
DEPS
2
DEPS
@ -38,7 +38,7 @@ deps = {
|
||||
|
||||
'crashpad/third_party/mini_chromium/mini_chromium':
|
||||
Var('chromium_git') + '/chromium/mini_chromium@' +
|
||||
'606ff8a31ae16f54a9c425880e57b3027f52db0c',
|
||||
'723e840a2f100a525f7feaad2e93df31d701780a',
|
||||
'crashpad/third_party/zlib/zlib':
|
||||
Var('chromium_git') + '/chromium/src/third_party/zlib@' +
|
||||
'13dc246a58e4b72104d35f9b1809af95221ebda7',
|
||||
|
@ -252,7 +252,7 @@ enum MinidumpContextAMD64Flags : uint32_t {
|
||||
//! normally alias `dr6` and `dr7`, respectively. See Intel Software
|
||||
//! Developer’s Manual, Volume 3B: System Programming, Part 2 (253669-052),
|
||||
//! 17.2.2 “Debug Registers DR4 and DR5”.
|
||||
struct ALIGNAS(16) MinidumpContextAMD64 {
|
||||
struct alignas(16) MinidumpContextAMD64 {
|
||||
//! \brief Register parameter home address.
|
||||
//!
|
||||
//! On Windows, this field may contain the “home” address (on-stack, in the
|
||||
|
@ -55,7 +55,7 @@ void AlignedFree(void* pointer);
|
||||
//! This is similar to `std::allocator<T>`, with the addition of an alignment
|
||||
//! guarantee. \a Alignment must be a power of 2. If \a Alignment is not
|
||||
//! specified, the default alignment for type \a T is used.
|
||||
template <class T, size_t Alignment = ALIGNOF(T)>
|
||||
template <class T, size_t Alignment = alignof(T)>
|
||||
struct AlignedAllocator {
|
||||
public:
|
||||
using value_type = T;
|
||||
@ -130,7 +130,7 @@ bool operator!=(const AlignedAllocator<T1, Alignment>& lhs,
|
||||
//! This is similar to `std::vector<T>`, with the addition of an alignment
|
||||
//! guarantee. \a Alignment must be a power of 2. If \a Alignment is not
|
||||
//! specified, the default alignment for type \a T is used.
|
||||
template <typename T, size_t Alignment = ALIGNOF(T)>
|
||||
template <typename T, size_t Alignment = alignof(T)>
|
||||
using AlignedVector = std::vector<T, AlignedAllocator<T, Alignment>>;
|
||||
|
||||
} // namespace crashpad
|
||||
|
@ -40,30 +40,30 @@ TEST(AlignedAllocator, AlignedVector) {
|
||||
AlignedVector<NaturalAlignedStruct> natural_aligned_vector;
|
||||
natural_aligned_vector.push_back(NaturalAlignedStruct());
|
||||
EXPECT_TRUE(
|
||||
IsAligned(&natural_aligned_vector[0], ALIGNOF(NaturalAlignedStruct)));
|
||||
IsAligned(&natural_aligned_vector[0], alignof(NaturalAlignedStruct)));
|
||||
|
||||
natural_aligned_vector.resize(3);
|
||||
EXPECT_TRUE(
|
||||
IsAligned(&natural_aligned_vector[0], ALIGNOF(NaturalAlignedStruct)));
|
||||
IsAligned(&natural_aligned_vector[0], alignof(NaturalAlignedStruct)));
|
||||
EXPECT_TRUE(
|
||||
IsAligned(&natural_aligned_vector[1], ALIGNOF(NaturalAlignedStruct)));
|
||||
IsAligned(&natural_aligned_vector[1], alignof(NaturalAlignedStruct)));
|
||||
EXPECT_TRUE(
|
||||
IsAligned(&natural_aligned_vector[2], ALIGNOF(NaturalAlignedStruct)));
|
||||
IsAligned(&natural_aligned_vector[2], alignof(NaturalAlignedStruct)));
|
||||
|
||||
// Test a structure that declares its own alignment.
|
||||
struct ALIGNAS(32) AlignedStruct {
|
||||
struct alignas(32) AlignedStruct {
|
||||
int i;
|
||||
};
|
||||
ASSERT_EQ(ALIGNOF(AlignedStruct), 32u);
|
||||
ASSERT_EQ(alignof(AlignedStruct), 32u);
|
||||
|
||||
AlignedVector<AlignedStruct> aligned_vector;
|
||||
aligned_vector.push_back(AlignedStruct());
|
||||
EXPECT_TRUE(IsAligned(&aligned_vector[0], ALIGNOF(AlignedStruct)));
|
||||
EXPECT_TRUE(IsAligned(&aligned_vector[0], alignof(AlignedStruct)));
|
||||
|
||||
aligned_vector.resize(3);
|
||||
EXPECT_TRUE(IsAligned(&aligned_vector[0], ALIGNOF(AlignedStruct)));
|
||||
EXPECT_TRUE(IsAligned(&aligned_vector[1], ALIGNOF(AlignedStruct)));
|
||||
EXPECT_TRUE(IsAligned(&aligned_vector[2], ALIGNOF(AlignedStruct)));
|
||||
EXPECT_TRUE(IsAligned(&aligned_vector[0], alignof(AlignedStruct)));
|
||||
EXPECT_TRUE(IsAligned(&aligned_vector[1], alignof(AlignedStruct)));
|
||||
EXPECT_TRUE(IsAligned(&aligned_vector[2], alignof(AlignedStruct)));
|
||||
|
||||
// Try a custom alignment. Since the structure itself doesn’t specify an
|
||||
// alignment constraint, only the base address will be aligned to the
|
||||
@ -73,19 +73,19 @@ TEST(AlignedAllocator, AlignedVector) {
|
||||
EXPECT_TRUE(IsAligned(&custom_aligned_vector[0], 64));
|
||||
|
||||
// Try a structure with a pretty big alignment request.
|
||||
struct ALIGNAS(1024) BigAlignedStruct {
|
||||
struct alignas(1024) BigAlignedStruct {
|
||||
int i;
|
||||
};
|
||||
ASSERT_EQ(ALIGNOF(BigAlignedStruct), 1024u);
|
||||
ASSERT_EQ(alignof(BigAlignedStruct), 1024u);
|
||||
|
||||
AlignedVector<BigAlignedStruct> big_aligned_vector;
|
||||
big_aligned_vector.push_back(BigAlignedStruct());
|
||||
EXPECT_TRUE(IsAligned(&big_aligned_vector[0], ALIGNOF(BigAlignedStruct)));
|
||||
EXPECT_TRUE(IsAligned(&big_aligned_vector[0], alignof(BigAlignedStruct)));
|
||||
|
||||
big_aligned_vector.resize(3);
|
||||
EXPECT_TRUE(IsAligned(&big_aligned_vector[0], ALIGNOF(BigAlignedStruct)));
|
||||
EXPECT_TRUE(IsAligned(&big_aligned_vector[1], ALIGNOF(BigAlignedStruct)));
|
||||
EXPECT_TRUE(IsAligned(&big_aligned_vector[2], ALIGNOF(BigAlignedStruct)));
|
||||
EXPECT_TRUE(IsAligned(&big_aligned_vector[0], alignof(BigAlignedStruct)));
|
||||
EXPECT_TRUE(IsAligned(&big_aligned_vector[1], alignof(BigAlignedStruct)));
|
||||
EXPECT_TRUE(IsAligned(&big_aligned_vector[2], alignof(BigAlignedStruct)));
|
||||
}
|
||||
|
||||
void BadAlignmentTest() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user