mirror of
https://github.com/JakeHillion/object-introspection.git
synced 2024-12-23 05:43:07 +00:00
AddPadding: Insert padding at the beginning of structs if necessary
This is sometimes needed now that we're removing members before adding padding.
This commit is contained in:
parent
d7cfcca30d
commit
7bb6791af9
@ -71,7 +71,9 @@ void AddPadding::visit(Class& c) {
|
|||||||
std::vector<Member> paddedMembers;
|
std::vector<Member> paddedMembers;
|
||||||
paddedMembers.reserve(c.members.size());
|
paddedMembers.reserve(c.members.size());
|
||||||
for (size_t i = 0; i < c.members.size(); i++) {
|
for (size_t i = 0; i < c.members.size(); i++) {
|
||||||
if (i >= 1) {
|
if (i == 0) {
|
||||||
|
addPadding(0, c.members[0].bitOffset, paddedMembers);
|
||||||
|
} else {
|
||||||
addPadding(c.members[i - 1], c.members[i].bitOffset, paddedMembers);
|
addPadding(c.members[i - 1], c.members[i].bitOffset, paddedMembers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,22 @@ TEST(AddPaddingTest, BetweenMembers) {
|
|||||||
)");
|
)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(AddPaddingTest, AtBeginning) {
|
||||||
|
test(AddPadding::createPass(), R"(
|
||||||
|
[0] Struct: MyStruct (size: 16)
|
||||||
|
Member: n1 (offset: 8)
|
||||||
|
Primitive: int64_t
|
||||||
|
)",
|
||||||
|
R"(
|
||||||
|
[0] Struct: MyStruct (size: 16)
|
||||||
|
Member: __oi_padding (offset: 0)
|
||||||
|
[1] Array: (length: 8)
|
||||||
|
Primitive: int8_t
|
||||||
|
Member: n1 (offset: 8)
|
||||||
|
Primitive: int64_t
|
||||||
|
)");
|
||||||
|
}
|
||||||
|
|
||||||
TEST(AddPaddingTest, AtEnd) {
|
TEST(AddPaddingTest, AtEnd) {
|
||||||
auto myclass = Class{0, Class::Kind::Struct, "MyStruct", 16};
|
auto myclass = Class{0, Class::Kind::Struct, "MyStruct", 16};
|
||||||
auto myint8 = Primitive{Primitive::Kind::Int8};
|
auto myint8 = Primitive{Primitive::Kind::Int8};
|
||||||
|
Loading…
Reference in New Issue
Block a user