diff --git a/gen/declarations.cpp b/gen/declarations.cpp index 84c11e8c..3711d1ec 100644 --- a/gen/declarations.cpp +++ b/gen/declarations.cpp @@ -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'; diff --git a/ir/irstruct.cpp b/ir/irstruct.cpp index ef531a47..6178b41a 100644 --- a/ir/irstruct.cpp +++ b/ir/irstruct.cpp @@ -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; }