Fix GitHub issue #168 – alignment of globals.

This commit is contained in:
David Nadlinger
2012-09-28 01:46:24 +02:00
parent 4b3662adfd
commit 5f6447e52c
2 changed files with 12 additions and 4 deletions

View File

@@ -171,8 +171,12 @@ void VarDeclaration::codegen(Ir* p)
#endif
this->ir.irGlobal->value = gvar;
// set the alignment
gvar->setAlignment(this->type->alignsize());
// Set the alignment (it is important not to use type->alignsize because
// VarDeclarations can have an align() attribute independent of the type
// as well). FIXME: ~0 is really STRUCTALIGN_DEFAULT, change as soon as
// 1.075 has been merged.
if (alignment != ~0)
gvar->setAlignment(alignment);
if (Logger::enabled())
Logger::cout() << *gvar << '\n';

View File

@@ -60,8 +60,12 @@ LLGlobalVariable * IrStruct::getInitSymbol()
init = new llvm::GlobalVariable(
*gIR->module, init_type, true, _linkage, NULL, initname);
// set alignment
init->setAlignment(type->alignsize());
// set alignment (use of StructDeclaration::alignment analogous to DMD)
// FIXME: ~0 is really STRUCTALIGN_DEFAULT, change as soon as 1.075 has
// been merged.
StructDeclaration *sd = aggrdecl->isStructDeclaration();
if (sd && sd->alignment != ~0)
init->setAlignment(sd->alignment);
return init;
}