[cfe-commits] r82868 - in /cfe/trunk: lib/CodeGen/CGDecl.cpp test/CodeGen/PR5060-align.c
Anders Carlsson
andersca at mac.com
Sat Sep 26 11:16:06 PDT 2009
Author: andersca
Date: Sat Sep 26 13:16:06 2009
New Revision: 82868
URL: http://llvm.org/viewvc/llvm-project?rev=82868&view=rev
Log:
Set alignment on static function level decls and VLAs. Fixes PR5060.
Added:
cfe/trunk/test/CodeGen/PR5060-align.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=82868&r1=82867&r2=82868&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Sat Sep 26 13:16:06 2009
@@ -103,10 +103,13 @@
}
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 @@
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");
}
Added: cfe/trunk/test/CodeGen/PR5060-align.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/PR5060-align.c?rev=82868&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/PR5060-align.c (added)
+++ cfe/trunk/test/CodeGen/PR5060-align.c Sat Sep 26 13:16:06 2009
@@ -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)));
+}
+
More information about the cfe-commits
mailing list