make sure to calculate alignment of following modifiers properly

This commit is contained in:
Jan 2021-02-28 23:17:39 +01:00
parent 48d672edbe
commit 226c589bb8
3 changed files with 13 additions and 2 deletions

View File

@ -241,3 +241,13 @@ const IEvaluation* DeclarationModifierComputations::GetDynamicArraySizeEvaluatio
return dynamic_cast<ArrayDeclarationModifier*>(declarationModifier)->m_dynamic_size_evaluation.get(); return dynamic_cast<ArrayDeclarationModifier*>(declarationModifier)->m_dynamic_size_evaluation.get();
} }
int DeclarationModifierComputations::GetAlignment() const
{
const auto following = GetFollowingDeclarationModifiers();
return std::any_of(following.begin(), following.end(), [](const DeclarationModifier* modifier)
{
return modifier->GetType() == DeclarationModifierType::POINTER;
}) ? m_information->m_member->GetAlignment() : m_information->m_member->m_type_declaration->m_type->GetAlignment();
}

View File

@ -31,4 +31,5 @@ public:
_NODISCARD const IEvaluation* GetPointerArrayCountEvaluation() const; _NODISCARD const IEvaluation* GetPointerArrayCountEvaluation() const;
_NODISCARD bool IsDynamicArray() const; _NODISCARD bool IsDynamicArray() const;
_NODISCARD const IEvaluation* GetDynamicArraySizeEvaluation() const; _NODISCARD const IEvaluation* GetDynamicArraySizeEvaluation() const;
_NODISCARD int GetAlignment() const;
}; };

View File

@ -898,7 +898,7 @@ class ZoneLoadTemplate::Internal final : BaseTemplate
const auto typeDecl = MakeTypeDecl(member->m_member->m_type_declaration.get()); const auto typeDecl = MakeTypeDecl(member->m_member->m_type_declaration.get());
const auto followingReferences = MakeFollowingReferences(modifier.GetFollowingDeclarationModifiers()); const auto followingReferences = MakeFollowingReferences(modifier.GetFollowingDeclarationModifiers());
LINE(MakeMemberAccess(info, member, modifier)<<" = m_stream->Alloc<"<<typeDecl<<followingReferences<<">(alignof("<<typeDecl<<followingReferences LINE(MakeMemberAccess(info, member, modifier)<<" = m_stream->Alloc<"<<typeDecl<<followingReferences<<">(alignof("<<typeDecl<<followingReferences
<<")); // " << member->m_member->m_type_declaration->GetAlignment()) <<")); // " << modifier.GetAlignment())
if (computations.IsInTempBlock()) if (computations.IsInTempBlock())
{ {