mirror of
https://github.com/JakeHillion/object-introspection.git
synced 2024-11-09 21:24:14 +00:00
type_graph: avoid overwriting explicitly set alignment
Previously AlignmentCalc calculates the alignment and sets packing for every type except a member with explicit alignment. Change this to check whether an alignment has been previously set for a type before calculating it. Use this in ClangTypeParser where the full alignment of the type is available. Remove explicitly aligning members by the type because that was previously reserved for members with explicit alignment. AlignmentCalc will correctly align a member to the underlying type without this. Explicit member alignment is still missing, as before this change. Test plan: - CI - Too little. Gets further into a production type than without this change.
This commit is contained in:
parent
31ba8659f0
commit
7eebee2bf7
@ -50,6 +50,7 @@ void AlignmentCalc::accept(Type& type) {
|
|||||||
void AlignmentCalc::visit(Class& c) {
|
void AlignmentCalc::visit(Class& c) {
|
||||||
RecursiveVisitor::visit(c);
|
RecursiveVisitor::visit(c);
|
||||||
|
|
||||||
|
if (c.align() == 0) {
|
||||||
uint64_t alignment = 1;
|
uint64_t alignment = 1;
|
||||||
for (auto& member : c.members) {
|
for (auto& member : c.members) {
|
||||||
if (member.align == 0) {
|
if (member.align == 0) {
|
||||||
@ -67,6 +68,7 @@ void AlignmentCalc::visit(Class& c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
c.setAlign(alignment);
|
c.setAlign(alignment);
|
||||||
|
}
|
||||||
|
|
||||||
if (c.size() % c.align() != 0) {
|
if (c.size() % c.align() != 0) {
|
||||||
// Mark as packed if there is no tail padding
|
// Mark as packed if there is no tail padding
|
||||||
|
@ -178,7 +178,7 @@ Type& ClangTypeParser::enumerateClass(const clang::RecordType& ty) {
|
|||||||
if (auto* info = getContainerInfo(fqName)) {
|
if (auto* info = getContainerInfo(fqName)) {
|
||||||
auto& c = makeType<Container>(ty, *info, size, nullptr);
|
auto& c = makeType<Container>(ty, *info, size, nullptr);
|
||||||
enumerateClassTemplateParams(ty, c.templateParams);
|
enumerateClassTemplateParams(ty, c.templateParams);
|
||||||
c.setAlign(ast->getTypeAlign(clang::QualType(&ty, 0)));
|
c.setAlign(ast->getTypeAlign(clang::QualType(&ty, 0)) / 8);
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,6 +197,7 @@ Type& ClangTypeParser::enumerateClass(const clang::RecordType& ty) {
|
|||||||
|
|
||||||
auto& c = makeType<Class>(
|
auto& c = makeType<Class>(
|
||||||
ty, kind, std::move(name), std::move(fqName), size, virtuality);
|
ty, kind, std::move(name), std::move(fqName), size, virtuality);
|
||||||
|
c.setAlign(ast->getTypeAlign(clang::QualType(&ty, 0)) / 8);
|
||||||
|
|
||||||
enumerateClassTemplateParams(ty, c.templateParams);
|
enumerateClassTemplateParams(ty, c.templateParams);
|
||||||
// enumerateClassParents(type, c.parents);
|
// enumerateClassParents(type, c.parents);
|
||||||
@ -317,7 +318,6 @@ 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 = decl->getASTContext().getTypeAlign(qualType) / 8;
|
|
||||||
members.push_back(m);
|
members.push_back(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user