Use the target pointer size as lower bound for the alignment of LL globals

This is apparently assumed by a std.conv unittest.

Using DtoAlignment() here instead of checking for an explicit
vd->alignment != STRUCTALIGN_DEFAULT is not only nice for consistency,
but also leads to a `struct S { align(16) int a; }` global being correctly
aligned on a 16-bytes boundary. The struct itself has no explicit
alignment, but alignsize() is 16; so the upstream code doesn't set any
explicit alignment for the global.
This commit is contained in:
Martin 2015-10-19 23:16:38 +02:00
parent 310ad102d7
commit a39997d326

View file

@ -892,10 +892,9 @@ void DtoResolveVariable(VarDeclaration* vd)
vd->isThreadlocal());
getIrGlobal(vd)->value = gvar;
// Set the alignment (it is important not to use type->alignsize because
// VarDeclarations can have an align() attribute independent of the type
// as well).
gvar->setAlignment(DtoAlignment(vd));
// Set the alignment and use the target pointer size as lower bound.
unsigned alignment = std::max(DtoAlignment(vd), gDataLayout->getPointerSize());
gvar->setAlignment(alignment);
IF_LOG Logger::cout() << *gvar << '\n';
}