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
This commit is contained in:
Dan Gohman 2010-07-28 20:56:48 +00:00
parent 4c010ec851
commit 6bbe671e1c
3 changed files with 13 additions and 5 deletions

View File

@ -74,11 +74,10 @@ public:
removeDeadConstantUsers(); // remove any dead constants using this. removeDeadConstantUsers(); // remove any dead constants using this.
} }
unsigned getAlignment() const { return Alignment; } unsigned getAlignment() const {
void setAlignment(unsigned Align) { return (1u << Alignment) >> 1;
assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
Alignment = Align;
} }
void setAlignment(unsigned Align);
VisibilityTypes getVisibility() const { return VisibilityTypes(Visibility); } VisibilityTypes getVisibility() const { return VisibilityTypes(Visibility); }
bool hasDefaultVisibility() const { return Visibility == DefaultVisibility; } bool hasDefaultVisibility() const { return Visibility == DefaultVisibility; }

View File

@ -102,7 +102,14 @@ void GlobalValue::copyAttributesFrom(const GlobalValue *Src) {
setVisibility(Src->getVisibility()); 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 // GlobalVariable Implementation
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//

View File

@ -1,5 +1,7 @@
; RUN: llvm-as %s -o /dev/null ; RUN: llvm-as %s -o /dev/null
@A = global i1 0, align 536870912
define void @foo() { define void @foo() {
%p = alloca i1, align 536870912 %p = alloca i1, align 536870912
load i1* %p, align 536870912 load i1* %p, align 536870912