Make GlobalValue alignment consistent with load, store, and alloca
authorDan Gohman <gohman@apple.com>
Wed, 28 Jul 2010 20:56:48 +0000 (20:56 +0000)
committerDan Gohman <gohman@apple.com>
Wed, 28 Jul 2010 20:56:48 +0000 (20:56 +0000)
alignment, fixing silent truncation of alignment values.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@109653 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/GlobalValue.h
lib/VMCore/Globals.cpp
test/Assembler/align-inst.ll

index d175080a667427d9271b257b7498232b9ba3438b..f4bee85b45f001f160de8b11b212c6a9a1766b28 100644 (file)
@@ -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; }
index b758eb8702aeafecd0c2574017f119cb7e0a588d..96716eeb349b9434264d325af7ca89d3c445458d 100644 (file)
@@ -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
 //===----------------------------------------------------------------------===//
index 7bf0b6493b69e0eb53a8140d9fc563855970abf6..6f7100e065d331848b0c64e6cdaa1fb007302757 100644 (file)
@@ -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