[cfe-commits] r51676 - in /cfe/trunk: lib/CodeGen/CodeGenModule.cpp test/CodeGen/var-align.c
Eli Friedman
eli.friedman at gmail.com
Thu May 29 04:10:31 PDT 2008
Author: efriedma
Date: Thu May 29 06:10:27 2008
New Revision: 51676
URL: http://llvm.org/viewvc/llvm-project?rev=51676&view=rev
Log:
Add CodeGen support for alignment on globals, both for unusual natural
alignment and alignment attributes.
Added:
cfe/trunk/test/CodeGen/var-align.c
Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=51676&r1=51675&r2=51676&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Thu May 29 06:10:27 2008
@@ -477,6 +477,12 @@
"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
Added: cfe/trunk/test/CodeGen/var-align.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/var-align.c?rev=51676&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/var-align.c (added)
+++ cfe/trunk/test/CodeGen/var-align.c Thu May 29 06:10:27 2008
@@ -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;
More information about the cfe-commits
mailing list