It turns out that "align 1" and unaligned are different. Add a bias to the
authorNick Lewycky <nicholas@mxc.ca>
Mon, 15 Dec 2008 07:29:55 +0000 (07:29 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Mon, 15 Dec 2008 07:29:55 +0000 (07:29 +0000)
alignment attribute such that 0 means unaligned.

This will probably require a rebuild of llvm-gcc because of the change to
Attributes.h. If you see many test failures on "make check", please rebuild
your llvm-gcc.

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

include/llvm/Attributes.h
lib/AsmParser/llvmAsmParser.y
lib/Bitcode/Writer/BitcodeWriter.cpp
lib/VMCore/Attributes.cpp

index 5cb581ae9631eb60e49032217a0f31576134f363..2b70596b33d22d27f35f71c10f6992238a857e45 100644 (file)
@@ -51,7 +51,8 @@ const Attributes OptimizeForSize = 1<<13; ///< opt_size
 const Attributes StackProtect    = 1<<14; ///< Stack protection.
 const Attributes StackProtectReq = 1<<15; ///< Stack protection required.
 const Attributes Alignment = 31<<16; ///< Alignment of parameter (5 bits)
-                                     // stored as log2 of alignment.
+                                     // stored as log2 of alignment with +1 bias
+                                     // 0 means unaligned different from align 1
 const Attributes NoCapture = 1<<21; ///< Function creates no aliases of pointer
 
 /// @brief Attributes that only apply to function parameters.
@@ -79,7 +80,8 @@ Attributes typeIncompatible(const Type *Ty);
 /// form used internally in Attributes.
 inline Attributes constructAlignmentFromInt(unsigned i) {
   assert(isPowerOf2_32(i) && "Alignment must be a power of two.");
-  return Log2_32(i) << 16;
+  assert(i <= 0x40000000 && "Alignment too large.");
+  return (Log2_32(i)+1) << 16;
 }
 
 /// The set of Attributes set in Attributes is converted to a
@@ -178,7 +180,7 @@ public:
   /// getParamAlignment - Return the alignment for the specified function
   /// parameter.
   unsigned getParamAlignment(unsigned Idx) const {
-    return (getAttributes(Idx) & Attribute::Alignment) >> 16;
+    return 1ull << (((getAttributes(Idx) & Attribute::Alignment) >> 16) - 1);
   }
   
   /// hasAttrSomewhere - Return true if the specified attribute is set for at
index 350584f432a1f5855cea3ecb28a1471102ff5be3..7028ea3fe0d2564a69ced084bc41219a5da50e98 100644 (file)
@@ -1332,6 +1332,8 @@ OptAlign : /*empty*/        { $$ = 0; } |
   $$ = $2;
   if ($$ != 0 && !isPowerOf2_32($$))
     GEN_ERROR("Alignment must be a power of two");
+  if ($$ > 0x40000000)
+    GEN_ERROR("Alignment too large");
   CHECK_FOR_ERROR
 };
 OptCAlign : /*empty*/            { $$ = 0; } |
@@ -1339,6 +1341,8 @@ OptCAlign : /*empty*/            { $$ = 0; } |
   $$ = $3;
   if ($$ != 0 && !isPowerOf2_32($$))
     GEN_ERROR("Alignment must be a power of two");
+  if ($$ > 0x40000000)
+    GEN_ERROR("Alignment too large");
   CHECK_FOR_ERROR
 };
 
@@ -1368,6 +1372,8 @@ GlobalVarAttribute : SectionString {
   | ALIGN EUINT64VAL {
     if ($2 != 0 && !isPowerOf2_32($2))
       GEN_ERROR("Alignment must be a power of two");
+    if ($2 > 0x40000000)
+      GEN_ERROR("Alignment too large");
     CurGV->setAlignment($2);
     CHECK_FOR_ERROR
   };
index 0555ed90f64279f9f0d5afc61483d02a68c2d55d..adf49a524a38d83552036fbaac81a029b007785e 100644 (file)
@@ -128,7 +128,8 @@ static void WriteAttributeTable(const ValueEnumerator &VE,
       // 5-bit log2 encoded value. Shift the bits above the alignment up by
       // 11 bits.
       uint64_t FauxAttr = PAWI.Attrs & 0xffff;
-      FauxAttr |= (1ull<<16)<<((PAWI.Attrs & Attribute::Alignment) >> 16);
+      if (PAWI.Attrs & Attribute::Alignment)
+        FauxAttr |= (1ull<<16)<<(((PAWI.Attrs & Attribute::Alignment)-1) >> 16);
       FauxAttr |= (PAWI.Attrs & (0x3FFull << 21)) << 11;
 
       Record.push_back(FauxAttr);
index 0a0d0a842d0dbc36aa39cbe3a301757092511687..dd47814d97ad971cecd4be5c751aa85870a93aaf 100644 (file)
@@ -61,7 +61,7 @@ std::string Attribute::getAsString(Attributes Attrs) {
     Result += "sspreq ";
   if (Attrs & Attribute::Alignment) {
     Result += "align ";
-    Result += utostr(1ull << ((Attrs & Attribute::Alignment)>>16));
+    Result += utostr(1ull << (((Attrs & Attribute::Alignment)>>16) - 1));
     Result += " ";
   }
   // Trim the trailing space.