From 8dc65b6e6d423750c05dbe4e241556febf84dcca Mon Sep 17 00:00:00 2001 From: Mark Mitchell Date: Mon, 23 Dec 2002 16:39:36 +0000 Subject: stor-layout.c (update_alignment_for_field): Correct handling of unnamed bitfields on PCC_BITFIELD_TYPE_MATTERS machines. * stor-layout.c (update_alignment_for_field): Correct handling of unnamed bitfields on PCC_BITFIELD_TYPE_MATTERS machines. * doc/tm.texi (PCC_BITFIELD_TYPE_MATTERS): Note that an unnamed bitfield does not affect alignment. * testsuite/gcc.dg/i386-bitfield3.c: New test. From-SVN: r60439 --- gcc/stor-layout.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'gcc/stor-layout.c') diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c index c4fdaee..6c81924 100644 --- a/gcc/stor-layout.c +++ b/gcc/stor-layout.c @@ -715,13 +715,9 @@ update_alignment_for_field (rli, field, known_align) && DECL_BIT_FIELD_TYPE (field) && ! integer_zerop (TYPE_SIZE (type))) { - /* For these machines, a zero-length field does not - affect the alignment of the structure as a whole. - It does, however, affect the alignment of the next field - within the structure. */ - if (! integer_zerop (DECL_SIZE (field))) - rli->record_align = MAX (rli->record_align, desired_align); - else if (! DECL_PACKED (field)) + /* A zero-length bit-field affects the alignment of the next + field. */ + if (!DECL_PACKED (field) && integer_zerop (DECL_SIZE (field))) { desired_align = TYPE_ALIGN (type); #ifdef ADJUST_FIELD_ALIGN @@ -729,8 +725,8 @@ update_alignment_for_field (rli, field, known_align) #endif } - /* A named bit field of declared type `int' - forces the entire structure to have `int' alignment. */ + /* Named bit-fields cause the entire structure to have the + alignment implied by their type. */ if (DECL_NAME (field) != 0) { unsigned int type_align = TYPE_ALIGN (type); @@ -745,7 +741,14 @@ update_alignment_for_field (rli, field, known_align) else if (DECL_PACKED (field)) type_align = MIN (type_align, BITS_PER_UNIT); + /* The alignment of the record is increased to the maximum + of the current alignment, the alignment indicated on the + field (i.e., the alignment specified by an __aligned__ + attribute), and the alignment indicated by the type of + the field. */ + rli->record_align = MAX (rli->record_align, desired_align); rli->record_align = MAX (rli->record_align, type_align); + rli->unpadded_align = MAX (rli->unpadded_align, DECL_ALIGN (field)); if (warn_packed) rli->unpacked_align = MAX (rli->unpacked_align, TYPE_ALIGN (type)); -- cgit v1.1