diff options
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 6 | ||||
-rw-r--r-- | clang/test/CodeGen/var-align.c | 4 |
2 files changed, 10 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 0b7d30ac500..e5bd15e8566 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/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<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 diff --git a/clang/test/CodeGen/var-align.c b/clang/test/CodeGen/var-align.c new file mode 100644 index 00000000000..be585c052e8 --- /dev/null +++ b/clang/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; |