diff options
author | Eric Botcazou <ebotcazou@adacore.com> | 2007-02-12 20:52:37 +0000 |
---|---|---|
committer | Eric Botcazou <ebotcazou@gcc.gnu.org> | 2007-02-12 20:52:37 +0000 |
commit | d996473d67640a8bae9576749d70c53667e515ae (patch) | |
tree | 8a4a7fc6e1537501b30e5b819c28bc1552cee7fb /gcc/dwarf2out.c | |
parent | ffcce7bcd8e288e0608ef8af05c501a5cf44a44b (diff) | |
download | gcc-d996473d67640a8bae9576749d70c53667e515ae.zip gcc-d996473d67640a8bae9576749d70c53667e515ae.tar.gz gcc-d996473d67640a8bae9576749d70c53667e515ae.tar.bz2 |
dwarf2out.c (round_up_to_align): New static function.
* dwarf2out.c (round_up_to_align): New static function.
(field_byte_offset): Use it to round the offset.
From-SVN: r121859
Diffstat (limited to 'gcc/dwarf2out.c')
-rw-r--r-- | gcc/dwarf2out.c | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index f77d4f2..92e14e5 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -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; |