dwarf2out.c (round_up_to_align): New static function.
authorEric Botcazou <ebotcazou@adacore.com>
Mon, 12 Feb 2007 20:52:37 +0000 (20:52 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Mon, 12 Feb 2007 20:52:37 +0000 (20:52 +0000)
* dwarf2out.c (round_up_to_align): New static function.
(field_byte_offset): Use it to round the offset.

From-SVN: r121859

gcc/ChangeLog
gcc/dwarf2out.c

index f8a1d0b..e7a3bf3 100644 (file)
@@ -1,3 +1,8 @@
+2007-02-12  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * dwarf2out.c (round_up_to_align): New static function.
+       (field_byte_offset): Use it to round the offset.
+
 2007-02-12  Richard Henderson  <rth@redhat.com>
 
        * config/alpha/alpha.md (bswapsi2, bswapdi2): New.
index f77d4f2..92e14e5 100644 (file)
@@ -9626,6 +9626,24 @@ simple_decl_align_in_bits (tree decl)
   return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD;
 }
 
+/* Return the result of rounding T up to ALIGN.  */
+
+static inline HOST_WIDE_INT
+round_up_to_align (HOST_WIDE_INT t, unsigned int align)
+{
+  /* We must be careful if T is negative because HOST_WIDE_INT can be
+     either "above" or "below" unsigned int as per the C promotion
+     rules, depending on the host, thus making the signedness of the
+     direct multiplication and division unpredictable.  */
+  unsigned HOST_WIDE_INT u = (unsigned HOST_WIDE_INT) t;
+
+  u += align - 1;
+  u /= align;
+  u *= align;
+
+  return (HOST_WIDE_INT) u;
+}
+
 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
    lowest addressed byte of the "containing object" for the given FIELD_DECL,
    or return 0 if we are unable to determine what that offset is, either
@@ -9725,9 +9743,8 @@ field_byte_offset (tree decl)
   object_offset_in_bits = deepest_bitpos - type_size_in_bits;
 
   /* Round up to type_align by default.  This works best for bitfields.  */
-  object_offset_in_bits += type_align_in_bits - 1;
-  object_offset_in_bits /= type_align_in_bits;
-  object_offset_in_bits *= type_align_in_bits;
+  object_offset_in_bits
+    = round_up_to_align (object_offset_in_bits, type_align_in_bits);
 
   if (object_offset_in_bits > bitpos_int)
     {
@@ -9735,9 +9752,8 @@ field_byte_offset (tree decl)
       object_offset_in_bits = deepest_bitpos - type_size_in_bits;
 
       /* Round up to decl_align instead.  */
-      object_offset_in_bits += decl_align_in_bits - 1;
-      object_offset_in_bits /= decl_align_in_bits;
-      object_offset_in_bits *= decl_align_in_bits;
+      object_offset_in_bits
+       = round_up_to_align (object_offset_in_bits, decl_align_in_bits);
     }
 
   return object_offset_in_bits / BITS_PER_UNIT;