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 =
--- /dev/null
+// 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)));
+}