From c207972af64cc1f4247c0b2f75715307c1ff2209 Mon Sep 17 00:00:00 2001 From: Alastair Robertson Date: Thu, 2 Nov 2023 06:22:57 -0700 Subject: [PATCH] TypeGraph: Calculate alignment before identifying containers Not all containers have 8-byte alignment, so if we want to avoid lots of manual logic for calculating container alignment on a case-by-case basis, we must calculate alignment from the member variables before the Class nodes have been replaced by Container nodes. --- oi/CodeGen.cpp | 6 ++---- oi/OITraceCode.cpp | 5 +++++ oi/type_graph/Types.h | 15 +-------------- test/test_codegen.cpp | 12 ++++++------ 4 files changed, 14 insertions(+), 24 deletions(-) diff --git a/oi/CodeGen.cpp b/oi/CodeGen.cpp index 2d0c0eb..3fa0374 100644 --- a/oi/CodeGen.cpp +++ b/oi/CodeGen.cpp @@ -1168,6 +1168,7 @@ void CodeGen::transform(TypeGraph& typeGraph) { // Simplify the type graph first so there is less work for later passes pm.addPass(RemoveTopLevelPointer::createPass()); pm.addPass(Flattener::createPass()); + pm.addPass(AlignmentCalc::createPass()); pm.addPass(IdentifyContainers::createPass(containerInfos_)); pm.addPass(TypeIdentifier::createPass(config_.passThroughTypes)); if (config_.features[Feature::PruneTypeGraph]) @@ -1183,16 +1184,13 @@ void CodeGen::transform(TypeGraph& typeGraph) { // Re-run passes over newly added children pm.addPass(Flattener::createPass()); + pm.addPass(AlignmentCalc::createPass()); pm.addPass(IdentifyContainers::createPass(containerInfos_)); pm.addPass(TypeIdentifier::createPass(config_.passThroughTypes)); if (config_.features[Feature::PruneTypeGraph]) pm.addPass(Prune::createPass()); } - // Calculate alignment before removing members, as those members may have an - // influence on the class' overall alignment. - pm.addPass(AlignmentCalc::createPass()); - pm.addPass(RemoveMembers::createPass(config_.membersToStub)); if (!config_.features[Feature::TreeBuilderV2]) pm.addPass(EnforceCompatibility::createPass()); diff --git a/oi/OITraceCode.cpp b/oi/OITraceCode.cpp index 47e98d7..fa0beda 100644 --- a/oi/OITraceCode.cpp +++ b/oi/OITraceCode.cpp @@ -101,6 +101,8 @@ struct alignas(align) DummySizedOperator { // container if an empty class is passed. template struct DummySizedOperator<0, 0, Id> {}; +template +struct DummySizedOperator<0, 1, Id> {}; template