This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
RFA: BIB: small cleanup in stor-layout.c
- From: Joern Rennecke <joern dot rennecke at superh dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 07 Nov 2002 20:30:57 +0000
- Subject: RFA: BIB: small cleanup in stor-layout.c
- Organization: SuperH UK Ltd.
The PCC_BITFIELD_TYPE_MATTERS / BITFIELD_NBYTES_LIMITED tests
to check if alignment requires that we advance to the next unit
have gone out of sync (as is also noted in the comment at the
BITFIELD_NBYTES_LIMITED code).
The best way to make sure the code is in sync and stays in sync
is to use a new function.
--
--------------------------
SuperH (UK) Ltd.
2410 Aztec West / Almondsbury / BRISTOL / BS32 4QX
T:+44 1454 465658
Thu Nov 7 20:21:12 2002 J"orn Rennecke <joern.rennecke@superh.com>
* stor-layout.c (excess_unit_span): New function.
(place_field): Use it.
Index: stor-layout.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/stor-layout.c,v
retrieving revision 1.128.4.7
diff -p -r1.128.4.7 stor-layout.c
*** stor-layout.c 15 Oct 2002 22:14:03 -0000 1.128.4.7
--- stor-layout.c 7 Nov 2002 20:20:58 -0000
*************** static int reference_types_internal = 0;
*** 60,65 ****
--- 60,68 ----
static void finalize_record_size PARAMS ((record_layout_info));
static void finalize_type_size PARAMS ((tree));
static void place_union_field PARAMS ((record_layout_info, tree));
+ static int excess_unit_span PARAMS ((HOST_WIDE_INT, HOST_WIDE_INT,
+ HOST_WIDE_INT, HOST_WIDE_INT,
+ tree));
static unsigned int update_alignment_for_field
PARAMS ((record_layout_info, tree,
unsigned int));
*************** place_union_field (rli, field)
*** 778,783 ****
--- 781,804 ----
DECL_SIZE_UNIT (field), rli->offset));
}
+ /* A bitfield of SIZE with a required access alignment of ALIGN is allocated
+ at BYTE_OFFSET / BIT_OFFSET. Return non-zero if the field would span more
+ units of alignment than the underlying TYPE. */
+ static int
+ excess_unit_span (byte_offset, bit_offset, size, align, type)
+ HOST_WIDE_INT byte_offset, bit_offset, size, align;
+ tree type;
+ {
+ /* Note that the calculation of OFFSET might overflow; we calculate it so
+ that we still get the right result as long as ALIGN is a power of two. */
+ unsigned HOST_WIDE_INT offset = byte_offset * BITS_PER_UNIT + bit_offset;
+
+ offset = offset % align;
+ return ((offset + size + align - 1) / align
+ > ((unsigned HOST_WIDE_INT) tree_low_cst (TYPE_SIZE (type), 1)
+ / align));
+ }
+
/* RLI contains information about the layout of a RECORD_TYPE. FIELD
is a FIELD_DECL to be added after those fields already present in
T. (FIELD is not actually added to the TYPE_FIELDS list here;
*************** place_field (rli, field)
*** 916,926 ****
/* A bit field may not span more units of alignment of its type
than its type itself. Advance to next boundary if necessary. */
! if ((((offset * BITS_PER_UNIT + bit_offset + field_size +
! type_align - 1)
! / type_align)
! - (offset * BITS_PER_UNIT + bit_offset) / type_align)
! > tree_low_cst (TYPE_SIZE (type), 1) / type_align)
rli->bitpos = round_up (rli->bitpos, type_align);
TYPE_USER_ALIGN (rli->t) |= TYPE_USER_ALIGN (type);
--- 937,943 ----
/* A bit field may not span more units of alignment of its type
than its type itself. Advance to next boundary if necessary. */
! if (excess_unit_span (offset, bit_offset, field_size, type_align, type))
rli->bitpos = round_up (rli->bitpos, type_align);
TYPE_USER_ALIGN (rli->t) |= TYPE_USER_ALIGN (type);
*************** place_field (rli, field)
*** 959,969 ****
/* A bit field may not span the unit of alignment of its type.
Advance to next boundary if necessary. */
! /* ??? This code should match the code above for the
! PCC_BITFIELD_TYPE_MATTERS case. */
! if ((offset * BITS_PER_UNIT + bit_offset) / type_align
! != ((offset * BITS_PER_UNIT + bit_offset + field_size - 1)
! / type_align))
rli->bitpos = round_up (rli->bitpos, type_align);
TYPE_USER_ALIGN (rli->t) |= TYPE_USER_ALIGN (type);
--- 976,982 ----
/* A bit field may not span the unit of alignment of its type.
Advance to next boundary if necessary. */
! if (excess_unit_span (offset, bit_offset, field_size, type_align, type))
rli->bitpos = round_up (rli->bitpos, type_align);
TYPE_USER_ALIGN (rli->t) |= TYPE_USER_ALIGN (type);