diff options
author | Dan Gohman <gohman@apple.com> | 2010-07-28 20:56:48 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2010-07-28 20:56:48 +0000 |
commit | 6bbe671e1c58dd58fcf0165c1127dda5037ad3e2 (patch) | |
tree | 0b758a76465b6fad8e13cce392747a1ac73556a5 | |
parent | 4c010ec85185e2f1d671ac17a387b55228199d5b (diff) | |
download | llvm-6bbe671e1c58dd58fcf0165c1127dda5037ad3e2.tar.gz llvm-6bbe671e1c58dd58fcf0165c1127dda5037ad3e2.tar.bz2 llvm-6bbe671e1c58dd58fcf0165c1127dda5037ad3e2.tar.xz |
Make GlobalValue alignment consistent with load, store, and alloca
alignment, fixing silent truncation of alignment values.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@109653 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/GlobalValue.h | 7 | ||||
-rw-r--r-- | lib/VMCore/Globals.cpp | 9 | ||||
-rw-r--r-- | test/Assembler/align-inst.ll | 2 |
3 files changed, 13 insertions, 5 deletions
diff --git a/include/llvm/GlobalValue.h b/include/llvm/GlobalValue.h index d175080a66..f4bee85b45 100644 --- a/include/llvm/GlobalValue.h +++ b/include/llvm/GlobalValue.h @@ -74,11 +74,10 @@ public: removeDeadConstantUsers(); // remove any dead constants using this. } - unsigned getAlignment() const { return Alignment; } - void setAlignment(unsigned Align) { - assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!"); - Alignment = Align; + unsigned getAlignment() const { + return (1u << Alignment) >> 1; } + void setAlignment(unsigned Align); VisibilityTypes getVisibility() const { return VisibilityTypes(Visibility); } bool hasDefaultVisibility() const { return Visibility == DefaultVisibility; } diff --git a/lib/VMCore/Globals.cpp b/lib/VMCore/Globals.cpp index b758eb8702..96716eeb34 100644 --- a/lib/VMCore/Globals.cpp +++ b/lib/VMCore/Globals.cpp @@ -102,7 +102,14 @@ void GlobalValue::copyAttributesFrom(const GlobalValue *Src) { setVisibility(Src->getVisibility()); } - +void GlobalValue::setAlignment(unsigned Align) { + assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!"); + assert(Align <= MaximumAlignment && + "Alignment is greater than MaximumAlignment!"); + Alignment = Log2_32(Align) + 1; + assert(getAlignment() == Align && "Alignment representation error!"); +} + //===----------------------------------------------------------------------===// // GlobalVariable Implementation //===----------------------------------------------------------------------===// diff --git a/test/Assembler/align-inst.ll b/test/Assembler/align-inst.ll index 7bf0b6493b..6f7100e065 100644 --- a/test/Assembler/align-inst.ll +++ b/test/Assembler/align-inst.ll @@ -1,5 +1,7 @@ ; RUN: llvm-as %s -o /dev/null +@A = global i1 0, align 536870912 + define void @foo() { %p = alloca i1, align 536870912 load i1* %p, align 536870912 |