[cfe-commits] r51826 - in /cfe/trunk: lib/CodeGen/CGDecl.cpp test/CodeGen/align-local.c
Eli Friedman
eli.friedman at gmail.com
Sat May 31 14:20:42 PDT 2008
Author: efriedma
Date: Sat May 31 16:20:41 2008
New Revision: 51826
URL: http://llvm.org/viewvc/llvm-project?rev=51826&view=rev
Log:
Calculate alignment for local variables.
Added:
cfe/trunk/test/CodeGen/align-local.c
Modified:
cfe/trunk/lib/CodeGen/CGDecl.cpp
Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=51826&r1=51825&r2=51826&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Sat May 31 16:20:41 2008
@@ -129,8 +129,12 @@
if (!Target.useGlobalsForAutomaticVariables()) {
// A normal fixed sized variable becomes an alloca in the entry block.
const llvm::Type *LTy = ConvertType(Ty);
- // TODO: Alignment
- DeclPtr = CreateTempAlloca(LTy, D.getName());
+ llvm::AllocaInst * Alloc = CreateTempAlloca(LTy, D.getName());
+ unsigned align = getContext().getTypeAlign(Ty);
+ if (const AlignedAttr* AA = D.getAttr<AlignedAttr>())
+ align = std::max(align, AA->getAlignment());
+ Alloc->setAlignment(align >> 3);
+ DeclPtr = Alloc;
} else {
// Targets that don't support recursion emit locals as globals.
const char *Class =
Added: cfe/trunk/test/CodeGen/align-local.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/align-local.c?rev=51826&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/align-local.c (added)
+++ cfe/trunk/test/CodeGen/align-local.c Sat May 31 16:20:41 2008
@@ -0,0 +1,8 @@
+// RUN: clang -emit-llvm < %s | grep "align 16" | count 2
+
+typedef struct __attribute((aligned(16))) {int x[4];} ff;
+
+int a() {
+ ff a;
+ struct {int x[4];} b __attribute((aligned(16)));
+}
More information about the cfe-commits
mailing list