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
This commit is contained in:
parent
7c02ae17fe
commit
8dc65b6e6d
5 changed files with 61 additions and 19 deletions
|
@ -1,3 +1,10 @@
|
|||
2002-12-23 Mark Mitchell <mark@codesourcery.com>
|
||||
|
||||
* 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.
|
||||
|
||||
2002-12-23 David Edelsohn <edelsohn@gnu.org>
|
||||
|
||||
* expr.c (expand_assignment): Apply special treatment to
|
||||
|
|
|
@ -1181,17 +1181,19 @@ go slower in that case, define this macro as 0.
|
|||
Define this if you wish to imitate the way many other C compilers handle
|
||||
alignment of bit-fields and the structures that contain them.
|
||||
|
||||
The behavior is that the type written for a bit-field (@code{int},
|
||||
@code{short}, or other integer type) imposes an alignment for the
|
||||
entire structure, as if the structure really did contain an ordinary
|
||||
field of that type. In addition, the bit-field is placed within the
|
||||
structure so that it would fit within such a field, not crossing a
|
||||
boundary for it.
|
||||
The behavior is that the type written for a named bit-field (@code{int},
|
||||
@code{short}, or other integer type) imposes an alignment for the entire
|
||||
structure, as if the structure really did contain an ordinary field of
|
||||
that type. In addition, the bit-field is placed within the structure so
|
||||
that it would fit within such a field, not crossing a boundary for it.
|
||||
|
||||
Thus, on most machines, a bit-field whose type is written as @code{int}
|
||||
would not cross a four-byte boundary, and would force four-byte
|
||||
alignment for the whole structure. (The alignment used may not be four
|
||||
bytes; it is controlled by the other alignment parameters.)
|
||||
Thus, on most machines, a named bit-field whose type is written as
|
||||
@code{int} would not cross a four-byte boundary, and would force
|
||||
four-byte alignment for the whole structure. (The alignment used may
|
||||
not be four bytes; it is controlled by the other alignment parameters.)
|
||||
|
||||
An unnamed bit-field will not affect the alignment of the containing
|
||||
structure.
|
||||
|
||||
If the macro is defined, its definition should be a C expression;
|
||||
a nonzero value for the expression enables this behavior.
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
2002-12-23 Mark Mitchell <mark@codesourcery.com>
|
||||
|
||||
* testsuite/gcc.dg/i386-bitfield3.c: New test.
|
||||
|
||||
* testsuite/gcc.dg/i386-bitfield2.c: New test.
|
||||
|
||||
2002-12-22 Nathan Sidwell <nathan@codesourcery.com>
|
||||
|
||||
* g++.dg/parse/conv_op1.C: New test.
|
||||
|
|
24
gcc/testsuite/gcc.dg/i386-bitfield3.c
Normal file
24
gcc/testsuite/gcc.dg/i386-bitfield3.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
// Test for bitfield alignment in structs on IA-32
|
||||
// { dg-do run { target i?86-*-* } }
|
||||
// { dg-options "-O2" }
|
||||
// { dg-options "-mno-align-double -mno-ms-bitfields" { target *-*-interix* } }
|
||||
|
||||
extern void abort (void);
|
||||
extern void exit (int);
|
||||
|
||||
struct X {
|
||||
int : 32;
|
||||
};
|
||||
|
||||
struct Y {
|
||||
int i : 32;
|
||||
};
|
||||
|
||||
int main () {
|
||||
if (__alignof__(struct X) != 1)
|
||||
abort ();
|
||||
if (__alignof__(struct Y) != 4)
|
||||
abort ();
|
||||
|
||||
exit (0);
|
||||
}
|
Loading…
Add table
Reference in a new issue