]> granicus.if.org Git - clang/commitdiff
Fix alignment on alloca's for parameters using ABIArgInfo::Expand.
authorEli Friedman <eli.friedman@gmail.com>
Thu, 3 Nov 2011 21:39:02 +0000 (21:39 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Thu, 3 Nov 2011 21:39:02 +0000 (21:39 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143658 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGCall.cpp
test/CodeGen/align-param.c

index 6e3b70cef8576ecba4770fcef0f55cf5bded9296..92ac5ae560e2869465befa5b78e48940911bbceb 100644 (file)
@@ -1058,10 +1058,11 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
       // If this structure was expanded into multiple arguments then
       // we need to create a temporary and reconstruct it from the
       // arguments.
-      llvm::Value *Temp = CreateMemTemp(Ty, Arg->getName() + ".addr");
-      llvm::Function::arg_iterator End =
-        ExpandTypeFromArgs(Ty, MakeAddrLValue(Temp, Ty), AI);
-      EmitParmDecl(*Arg, Temp, ArgNo);
+      llvm::AllocaInst *Alloca = CreateMemTemp(Ty);
+      Alloca->setAlignment(getContext().getDeclAlign(Arg).getQuantity());
+      LValue LV = MakeAddrLValue(Alloca, Ty, Alloca->getAlignment());
+      llvm::Function::arg_iterator End = ExpandTypeFromArgs(Ty, LV, AI);
+      EmitParmDecl(*Arg, Alloca, ArgNo);
 
       // Name the arguments used in expansion and increment AI.
       unsigned Index = 0;
index 15a8c2a79a3c0afabcee42af6e3d91dd33f7dfa1..8907f66409a101b18c2d5ac34be680cc530a302b 100644 (file)
@@ -7,3 +7,12 @@ int test (long long x) {
 }
 // CHECK: define i32 @test
 // CHECK: alloca i64, align 8
+
+
+// Make sure we honor the aligned attribute.
+struct X { int x,y,z,a; };
+int test2(struct X x __attribute((aligned(16)))) {
+  return x.z;
+}
+// CHECK: define i32 @test2
+// CHECK: alloca %struct.X, align 16