mirror of
https://github.com/JakeHillion/object-introspection.git
synced 2024-11-12 21:56:54 +00:00
AddPadding: Pad unions when necessary
This commit is contained in:
parent
a0acaaea65
commit
ec9f98f0e1
@ -61,7 +61,14 @@ void AddPadding::visit(Class& c) {
|
||||
}
|
||||
|
||||
if (c.kind() == Class::Kind::Union) {
|
||||
// Don't pad unions
|
||||
// Only apply padding to the full size of the union, not between members
|
||||
for (const auto& member : c.members) {
|
||||
if (member.bitsize == c.size() * 8 || member.type().size() == c.size())
|
||||
return; // Don't add padding to unions which don't need it
|
||||
}
|
||||
// This union's members aren't big enough to make up its size, so add a
|
||||
// single padding member
|
||||
addPadding(0, c.size() * 8, c.members);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -85,6 +85,9 @@ TEST(AddPaddingTest, UnionAtEnd) {
|
||||
Primitive: int64_t
|
||||
Member: n2 (offset: 0)
|
||||
Primitive: int8_t
|
||||
Member: __oi_padding (offset: 0)
|
||||
[1] Array: (length: 16)
|
||||
Primitive: int8_t
|
||||
)");
|
||||
}
|
||||
|
||||
@ -188,6 +191,9 @@ TEST(AddPaddingTest, MemberlessUnion) {
|
||||
)",
|
||||
R"(
|
||||
[0] Union: MyUnion (size: 16)
|
||||
Member: __oi_padding (offset: 0)
|
||||
[1] Array: (length: 16)
|
||||
Primitive: int8_t
|
||||
)");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user