Add CodeGen support for alignment on globals, both for unusual natural

alignment and alignment attributes.

llvm-svn: 51676
This commit is contained in:
Eli Friedman 2008-05-29 11:10:27 +00:00
parent b65ff27f53
commit 174d9c26f1
2 changed files with 10 additions and 0 deletions

View File

@ -477,6 +477,12 @@ void CodeGenModule::EmitGlobalVarInit(const VarDecl *D) {
"Initializer codegen type mismatch!");
GV->setInitializer(Init);
unsigned Align = Context.getTypeAlign(D->getType());
if (const AlignedAttr* AA = D->getAttr<AlignedAttr>()) {
Align = std::max(Align, AA->getAlignment());
}
GV->setAlignment(Align / 8);
if (const VisibilityAttr *attr = D->getAttr<VisibilityAttr>())
setVisibility(GV, attr->getVisibility());
// FIXME: else handle -fvisibility

View File

@ -0,0 +1,4 @@
// RUN: clang -emit-llvm %s -o - | grep "align 16" | count 2
__attribute((aligned(16))) float a[128];
union {int a[4]; __attribute((aligned(16))) float b[4];} u;