Calculate alignment for local variables.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51826 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGDecl.cpp b/lib/CodeGen/CGDecl.cpp
index 4541fc4..8723a66 100644
--- a/lib/CodeGen/CGDecl.cpp
+++ b/lib/CodeGen/CGDecl.cpp
@@ -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 =