mirror of
https://github.com/JakeHillion/object-introspection.git
synced 2024-11-09 21:24:14 +00:00
Correct packing calculation (#485)
Summary: Correct identification of packing. Tests were modified to reflect the new behaviour. One test was removed as it was bogus - the flattener pass runs before the alignmentcalc pass and therefore the layout in the test could never happen (i.e. it has a hierarchy). Reviewed By: JakeHillion Differential Revision: D53815661
This commit is contained in:
parent
bfafe2eeae
commit
34a35cd418
@ -70,7 +70,7 @@ void AlignmentCalc::visit(Class& c) {
|
|||||||
c.setAlign(alignment);
|
c.setAlign(alignment);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c.size() % c.align() != 0) {
|
if (c.align() == 1 || c.size() % c.align() != 0) {
|
||||||
// Mark as packed if there is no tail padding
|
// Mark as packed if there is no tail padding
|
||||||
c.setPacked();
|
c.setPacked();
|
||||||
}
|
}
|
||||||
|
@ -330,6 +330,7 @@ void ClangTypeParser::enumerateClassMembers(const clang::RecordType& ty,
|
|||||||
|
|
||||||
auto& mtype = enumerateType(*qualType);
|
auto& mtype = enumerateType(*qualType);
|
||||||
Member m{mtype, std::move(member_name), offset_in_bits, size_in_bits};
|
Member m{mtype, std::move(member_name), offset_in_bits, size_in_bits};
|
||||||
|
m.align = field->getMaxAlignment() / 8;
|
||||||
members.push_back(m);
|
members.push_back(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ TEST(AlignmentCalcTest, RecurseClassParam) {
|
|||||||
Primitive: int64_t
|
Primitive: int64_t
|
||||||
)",
|
)",
|
||||||
R"(
|
R"(
|
||||||
[0] Class: MyClass (size: 0, align: 1)
|
[0] Class: MyClass (size: 0, align: 1, packed)
|
||||||
Param
|
Param
|
||||||
[1] Class: ClassA (size: 16, align: 8)
|
[1] Class: ClassA (size: 16, align: 8)
|
||||||
Member: a (offset: 0, align: 1)
|
Member: a (offset: 0, align: 1)
|
||||||
@ -141,28 +141,6 @@ TEST(AlignmentCalcTest, RecurseClassParam) {
|
|||||||
)");
|
)");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(AlignmentCalcTest, RecurseClassParent) {
|
|
||||||
test(AlignmentCalc::createPass(),
|
|
||||||
R"(
|
|
||||||
[0] Class: MyClass (size: 0)
|
|
||||||
Parent (offset: 0)
|
|
||||||
[1] Class: ClassA (size: 16)
|
|
||||||
Member: a (offset: 0)
|
|
||||||
Primitive: int8_t
|
|
||||||
Member: b (offset: 8)
|
|
||||||
Primitive: int64_t
|
|
||||||
)",
|
|
||||||
R"(
|
|
||||||
[0] Class: MyClass (size: 0, align: 1)
|
|
||||||
Parent (offset: 0)
|
|
||||||
[1] Class: ClassA (size: 16, align: 8)
|
|
||||||
Member: a (offset: 0, align: 1)
|
|
||||||
Primitive: int8_t
|
|
||||||
Member: b (offset: 8, align: 8)
|
|
||||||
Primitive: int64_t
|
|
||||||
)");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(AlignmentCalcTest, RecurseClassMember) {
|
TEST(AlignmentCalcTest, RecurseClassMember) {
|
||||||
test(AlignmentCalc::createPass(),
|
test(AlignmentCalc::createPass(),
|
||||||
R"(
|
R"(
|
||||||
@ -197,7 +175,7 @@ TEST(AlignmentCalcTest, RecurseClassChild) {
|
|||||||
Primitive: int64_t
|
Primitive: int64_t
|
||||||
)",
|
)",
|
||||||
R"(
|
R"(
|
||||||
[0] Class: MyClass (size: 0, align: 1)
|
[0] Class: MyClass (size: 0, align: 1, packed)
|
||||||
Child
|
Child
|
||||||
[1] Class: ClassA (size: 16, align: 8)
|
[1] Class: ClassA (size: 16, align: 8)
|
||||||
Member: a (offset: 0, align: 1)
|
Member: a (offset: 0, align: 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user