mirror of
https://github.com/intel/llvm.git
synced 2026-01-25 19:44:38 +08:00
Add CodeGen support for alignment on globals, both for unusual natural
alignment and alignment attributes. llvm-svn: 51676
This commit is contained in:
@@ -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
|
||||
|
||||
4
clang/test/CodeGen/var-align.c
Normal file
4
clang/test/CodeGen/var-align.c
Normal 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;
|
||||
Reference in New Issue
Block a user