]> granicus.if.org Git - clang/commitdiff
Set alignment on static function level decls and VLAs. Fixes PR5060.
authorAnders Carlsson <andersca@mac.com>
Sat, 26 Sep 2009 18:16:06 +0000 (18:16 +0000)
committerAnders Carlsson <andersca@mac.com>
Sat, 26 Sep 2009 18:16:06 +0000 (18:16 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@82868 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGDecl.cpp
test/CodeGen/PR5060-align.c [new file with mode: 0644]

index d1f6b276243a99f70eb025bb4469df3c52991174..73bc0a04a0c654b237bcaf316220d0b0a9655ad8 100644 (file)
@@ -103,10 +103,13 @@ CodeGenFunction::CreateStaticBlockVarDecl(const VarDecl &D,
   }
 
   const llvm::Type *LTy = CGM.getTypes().ConvertTypeForMem(Ty);
-  return new llvm::GlobalVariable(CGM.getModule(), LTy,
-                                  Ty.isConstant(getContext()), Linkage,
-                                  CGM.EmitNullConstant(D.getType()), Name, 0,
-                                  D.isThreadSpecified(), Ty.getAddressSpace());
+  llvm::GlobalVariable *GV =
+    new llvm::GlobalVariable(CGM.getModule(), LTy,
+                             Ty.isConstant(getContext()), Linkage,
+                             CGM.EmitNullConstant(D.getType()), Name, 0,
+                             D.isThreadSpecified(), Ty.getAddressSpace());
+  GV->setAlignment(getContext().getDeclAlignInBytes(&D));
+  return GV;
 }
 
 void CodeGenFunction::EmitStaticBlockVarDecl(const VarDecl &D) {
@@ -375,8 +378,10 @@ void CodeGenFunction::EmitLocalBlockVarDecl(const VarDecl &D) {
                                     false, "tmp");
 
     // Allocate memory for the array.
-    llvm::Value *VLA = Builder.CreateAlloca(llvm::Type::getInt8Ty(VMContext),
-                                            VLASize, "vla");
+    llvm::AllocaInst *VLA = 
+      Builder.CreateAlloca(llvm::Type::getInt8Ty(VMContext), VLASize, "vla");
+    VLA->setAlignment(getContext().getDeclAlignInBytes(&D));
+
     DeclPtr = Builder.CreateBitCast(VLA, LElemPtrTy, "tmp");
   }
 
diff --git a/test/CodeGen/PR5060-align.c b/test/CodeGen/PR5060-align.c
new file mode 100644 (file)
index 0000000..5d86408
--- /dev/null
@@ -0,0 +1,13 @@
+// RUN: clang-cc -emit-llvm %s -o - -verify | FileCheck %s
+
+// CHECK: @foo.p = internal global i8 0, align 32
+char *foo(void) {
+  static char p __attribute__((aligned(32)));
+  return &p;
+}
+
+void bar(long n) {
+  // CHECK: align 32
+  char p[n] __attribute__((aligned(32)));
+}
+