diff options
author | Michael Matz <matz@suse.de> | 2006-02-14 16:12:56 +0000 |
---|---|---|
committer | Michael Matz <matz@suse.de> | 2006-02-14 16:12:56 +0000 |
commit | 340a17a0aa5b587c16a6417f1151f18b09ae1957 (patch) | |
tree | 6ee67219b753f5cb350ee57fbba65c960cb048f4 | |
parent | 7639fcf0a3970c0120b4a3d3cb0532e034c2a3b8 (diff) |
PR middle-end/22275
* stor-layout.c (layout_decl): Zero-width bitfields aren't
influenced by maximum_field_alignment or DECL_PACKED.
(update_alignment_for_field): Ditto.
(place_field): Ditto.
* doc/extend.texi (<#pragma pack>, <Type Attributes>): Document
this behaviour.
git-svn-id: https://gcc.gnu.org/svn/gcc/branches/gcc-4_1-branch@110982 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/ChangeLog | 11 | ||||
-rw-r--r-- | gcc/doc/extend.texi | 15 | ||||
-rw-r--r-- | gcc/stor-layout.c | 34 |
3 files changed, 46 insertions, 14 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index ccbf4fadeb3..37dcec22d69 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,16 @@ 2006-02-14 Michael Matz <matz@suse.de> + PR middle-end/22275 + + * stor-layout.c (layout_decl): Zero-width bitfields aren't + influenced by maximum_field_alignment or DECL_PACKED. + (update_alignment_for_field): Ditto. + (place_field): Ditto. + * doc/extend.texi (<#pragma pack>, <Type Attributes>): Document + this behaviour. + +2006-02-14 Michael Matz <matz@suse.de> + * tree-ssa-structalias.c: Include <params.h>. * Makefile.in (tree-ssa-structalias.o): Adjust dependencies. diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index a796da62685..28370bf42fc 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -3288,9 +3288,10 @@ alignment. See your linker documentation for further information. @item packed This attribute, attached to @code{struct} or @code{union} type -definition, specifies that each member of the structure or union is -placed to minimize the memory required. When attached to an @code{enum} -definition, it indicates that the smallest integral type should be used. +definition, specifies that each member (other than zero-width bitfields) +of the structure or union is placed to minimize the memory required. When +attached to an @code{enum} definition, it indicates that the smallest +integral type should be used. @opindex fshort-enums Specifying this attribute for @code{struct} and @code{union} types is @@ -9423,10 +9424,10 @@ way of knowing that that happened.) @subsection Structure-Packing Pragmas For compatibility with Win32, GCC supports a set of @code{#pragma} -directives which change the maximum alignment of members of structures, -unions, and classes subsequently defined. The @var{n} value below always -is required to be a small power of two and specifies the new alignment -in bytes. +directives which change the maximum alignment of members of structures +(other than zero-width bitfields), unions, and classes subsequently +defined. The @var{n} value below always is required to be a small power +of two and specifies the new alignment in bytes. @enumerate @item @code{#pragma pack(@var{n})} simply sets the new alignment. diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c index ba70440f030..d6d7d161978 100644 --- a/gcc/stor-layout.c +++ b/gcc/stor-layout.c @@ -337,6 +337,8 @@ layout_decl (tree decl, unsigned int known_align) /* For fields, it's a bit more complicated... */ { bool old_user_align = DECL_USER_ALIGN (decl); + bool zero_bitfield = false; + unsigned int mfa; if (DECL_BIT_FIELD (decl)) { @@ -345,9 +347,9 @@ layout_decl (tree decl, unsigned int known_align) /* A zero-length bit-field affects the alignment of the next field. */ if (integer_zerop (DECL_SIZE (decl)) - && ! DECL_PACKED (decl) && ! targetm.ms_bitfield_layout_p (DECL_FIELD_CONTEXT (decl))) { + zero_bitfield = true; #ifdef PCC_BITFIELD_TYPE_MATTERS if (PCC_BITFIELD_TYPE_MATTERS) do_type_align (type, decl); @@ -408,12 +410,13 @@ layout_decl (tree decl, unsigned int known_align) check old_user_align instead. */ if (DECL_PACKED (decl) && !old_user_align + && !zero_bitfield && (DECL_NONADDRESSABLE_P (decl) || DECL_SIZE_UNIT (decl) == 0 || TREE_CODE (DECL_SIZE_UNIT (decl)) == INTEGER_CST)) DECL_ALIGN (decl) = MIN (DECL_ALIGN (decl), BITS_PER_UNIT); - if (! DECL_USER_ALIGN (decl) && ! DECL_PACKED (decl)) + if (! DECL_USER_ALIGN (decl) && (! DECL_PACKED (decl) || zero_bitfield)) { /* Some targets (i.e. i386, VMS) limit struct field alignment to a lower boundary than alignment of variables unless @@ -427,9 +430,13 @@ layout_decl (tree decl, unsigned int known_align) #endif } + if (zero_bitfield) + mfa = initial_max_fld_align * BITS_PER_UNIT; + else + mfa = maximum_field_alignment; /* Should this be controlled by DECL_USER_ALIGN, too? */ - if (maximum_field_alignment != 0) - DECL_ALIGN (decl) = MIN (DECL_ALIGN (decl), maximum_field_alignment); + if (mfa != 0) + DECL_ALIGN (decl) = MIN (DECL_ALIGN (decl), mfa); } /* Evaluate nonconstant size only once, either now or as soon as safe. */ @@ -713,7 +720,16 @@ update_alignment_for_field (record_layout_info rli, tree field, type_align = ADJUST_FIELD_ALIGN (field, type_align); #endif - if (maximum_field_alignment != 0) + /* Targets might chose to handle unnamed and hence possibly + zero-width bitfield. Those are not influenced by #pragmas + or packed attributes. */ + if (integer_zerop (DECL_SIZE (field))) + { + if (initial_max_fld_align) + type_align = MIN (type_align, + initial_max_fld_align * BITS_PER_UNIT); + } + else if (maximum_field_alignment != 0) type_align = MIN (type_align, maximum_field_alignment); else if (DECL_PACKED (field)) type_align = MIN (type_align, BITS_PER_UNIT); @@ -1175,6 +1191,10 @@ place_field (record_layout_info rli, tree field) if (DECL_BIT_FIELD_TYPE (field)) { unsigned int type_align = TYPE_ALIGN (type); + unsigned int mfa = maximum_field_alignment; + + if (integer_zerop (DECL_SIZE (field))) + mfa = initial_max_fld_align * BITS_PER_UNIT; /* Only the MS bitfields use this. We used to also put any kind of packed bit fields into prev_field, but that makes no sense, because @@ -1183,8 +1203,8 @@ place_field (record_layout_info rli, tree field) are also not fulfilled. There is no sane value to set rli->remaining_in_alignment to when a packed bitfield in prev_field is unaligned. */ - if (maximum_field_alignment != 0) - type_align = MIN (type_align, maximum_field_alignment); + if (mfa != 0) + type_align = MIN (type_align, mfa); gcc_assert (rli->prev_field || actual_align >= type_align || DECL_PACKED (field) || integer_zerop (DECL_SIZE (field)) |