From: Eli Friedman Date: Thu, 29 May 2008 11:10:27 +0000 (+0000) Subject: Add CodeGen support for alignment on globals, both for unusual natural X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=08d7802a406ee4a7cc18e8fce0c137b8c410ea7c;p=clang Add CodeGen support for alignment on globals, both for unusual natural alignment and alignment attributes. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51676 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 0b7d30ac50..e5bd15e856 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -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()) { + Align = std::max(Align, AA->getAlignment()); + } + GV->setAlignment(Align / 8); + if (const VisibilityAttr *attr = D->getAttr()) setVisibility(GV, attr->getVisibility()); // FIXME: else handle -fvisibility diff --git a/test/CodeGen/var-align.c b/test/CodeGen/var-align.c new file mode 100644 index 0000000000..be585c052e --- /dev/null +++ b/test/CodeGen/var-align.c @@ -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;