Commit 78d55cc8 by Jason Merrill

stor-layout.c (do_type_align): New fn, split out from...

        * stor-layout.c (do_type_align): New fn, split out from...
        (layout_decl): ...here.  Do all alignment calculations for
        FIELD_DECLs here.
        (update_alignment_for_field): Not here.
        (start_record_layout, debug_rli): Remove unpadded_align.
        * tree.h (struct record_layout_info_s): Remove unpadded_align.
        * c-decl.c (finish_enum): Don't set DECL_SIZE, DECL_ALIGN
        or DECL_MODE on the CONST_DECLs.
        (finish_struct): Don't mess with DECL_ALIGN.
        * cp/class.c (build_vtable): Set DECL_ALIGN here.
        (get_vtable_decl): Not here.
        (layout_vtable_decl): Or here.
        (create_vtable_ptr): Or here.
        (layout_class_type): Or here.
        (check_bitfield_decl): Don't mess with field alignment.
        * ada/misc.c (gnat_adjust_rli): #if 0.

From-SVN: r65207
parent d10f5ecf
2003-04-03 Jason Merrill <jason@redhat.com>
* stor-layout.c (do_type_align): New fn, split out from...
(layout_decl): ...here. Do all alignment calculations for
FIELD_DECLs here.
(update_alignment_for_field): Not here.
(start_record_layout, debug_rli): Remove unpadded_align.
* tree.h (struct record_layout_info_s): Remove unpadded_align.
* c-decl.c (finish_enum): Don't set DECL_SIZE, DECL_ALIGN
or DECL_MODE on the CONST_DECLs.
(finish_struct): Don't mess with DECL_ALIGN.
Thu Apr 3 18:57:19 CEST 2003 Jan Hubicka <jh@suse.cz> Thu Apr 3 18:57:19 CEST 2003 Jan Hubicka <jh@suse.cz>
* i386.c (print_operand): Do not bypass output_addr_const at flag_pic. * i386.c (print_operand): Do not bypass output_addr_const at flag_pic.
......
2003-04-03 Jason Merrill <jason@redhat.com>
* misc.c (gnat_adjust_rli): #if 0.
2003-03-31 Geert Bosch <bosch@gnat.com> 2003-03-31 Geert Bosch <bosch@gnat.com>
PR ada/10020 PR ada/10020
...@@ -19,8 +23,8 @@ ...@@ -19,8 +23,8 @@
2003-03-05 Olivier Hainque <hainque@gnat.com> 2003-03-05 Olivier Hainque <hainque@gnat.com>
ada/9961 ada/9961
* raise.c (__gnat_Unwind_RaiseException): Add prototype to avoid * raise.c (__gnat_Unwind_RaiseException): Add prototype to avoid
warning, and fix return type for the IN_RTS && !SJLJ case. warning, and fix return type for the IN_RTS && !SJLJ case.
2003-03-04 Tom Tromey <tromey@redhat.com> 2003-03-04 Tom Tromey <tromey@redhat.com>
......
...@@ -563,8 +563,11 @@ gnat_expand_expr (exp, target, tmode, modifier) ...@@ -563,8 +563,11 @@ gnat_expand_expr (exp, target, tmode, modifier)
static void static void
gnat_adjust_rli (rli) gnat_adjust_rli (rli)
record_layout_info rli; record_layout_info rli ATTRIBUTE_UNUSED;
{ {
#if 0
/* This code seems to have no actual effect; record_align should already
reflect the largest alignment desired by a field. jason 2003-04-01 */
unsigned int record_align = rli->unpadded_align; unsigned int record_align = rli->unpadded_align;
tree field; tree field;
...@@ -576,6 +579,7 @@ gnat_adjust_rli (rli) ...@@ -576,6 +579,7 @@ gnat_adjust_rli (rli)
if (TYPE_PACKED (rli->t)) if (TYPE_PACKED (rli->t))
rli->record_align = record_align; rli->record_align = record_align;
#endif
} }
/* Make a TRANSFORM_EXPR to later expand GNAT_NODE into code. */ /* Make a TRANSFORM_EXPR to later expand GNAT_NODE into code. */
......
...@@ -5250,23 +5250,6 @@ finish_struct (t, fieldlist, attributes) ...@@ -5250,23 +5250,6 @@ finish_struct (t, fieldlist, attributes)
DECL_SIZE (x) = bitsize_int (width); DECL_SIZE (x) = bitsize_int (width);
DECL_BIT_FIELD (x) = 1; DECL_BIT_FIELD (x) = 1;
SET_DECL_C_BIT_FIELD (x); SET_DECL_C_BIT_FIELD (x);
if (width == 0
&& ! (* targetm.ms_bitfield_layout_p) (t))
{
/* field size 0 => force desired amount of alignment. */
#ifdef EMPTY_FIELD_BOUNDARY
DECL_ALIGN (x) = MAX (DECL_ALIGN (x), EMPTY_FIELD_BOUNDARY);
#endif
#ifdef PCC_BITFIELD_TYPE_MATTERS
if (PCC_BITFIELD_TYPE_MATTERS)
{
DECL_ALIGN (x) = MAX (DECL_ALIGN (x),
TYPE_ALIGN (TREE_TYPE (x)));
DECL_USER_ALIGN (x) |= TYPE_USER_ALIGN (TREE_TYPE (x));
}
#endif
}
} }
} }
...@@ -5564,11 +5547,6 @@ finish_enum (enumtype, values, attributes) ...@@ -5564,11 +5547,6 @@ finish_enum (enumtype, values, attributes)
tree enu = TREE_PURPOSE (pair); tree enu = TREE_PURPOSE (pair);
TREE_TYPE (enu) = enumtype; TREE_TYPE (enu) = enumtype;
DECL_SIZE (enu) = TYPE_SIZE (enumtype);
DECL_SIZE_UNIT (enu) = TYPE_SIZE_UNIT (enumtype);
DECL_ALIGN (enu) = TYPE_ALIGN (enumtype);
DECL_USER_ALIGN (enu) = TYPE_USER_ALIGN (enumtype);
DECL_MODE (enu) = TYPE_MODE (enumtype);
/* The ISO C Standard mandates enumerators to have type int, /* The ISO C Standard mandates enumerators to have type int,
even though the underlying type of an enum type is even though the underlying type of an enum type is
......
2003-04-03 Jason Merrill <jason@redhat.com>
* class.c (build_vtable): Set DECL_ALIGN here.
(get_vtable_decl): Not here.
(layout_vtable_decl): Or here.
(create_vtable_ptr): Or here.
(layout_class_type): Or here.
(check_bitfield_decl): Don't mess with field alignment.
2003-04-03 Kaveh R. Ghazi <ghazi@caip.rutgers.edu> 2003-04-03 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* operators.def (DEF_SIMPLE_OPERATOR, DEF_ASSN_OPERATOR, * operators.def (DEF_SIMPLE_OPERATOR, DEF_ASSN_OPERATOR,
......
...@@ -531,6 +531,11 @@ build_vtable (tree class_type, tree name, tree vtable_type) ...@@ -531,6 +531,11 @@ build_vtable (tree class_type, tree name, tree vtable_type)
DECL_VIRTUAL_P (decl) = 1; DECL_VIRTUAL_P (decl) = 1;
DECL_ALIGN (decl) = TARGET_VTABLE_ENTRY_ALIGN; DECL_ALIGN (decl) = TARGET_VTABLE_ENTRY_ALIGN;
/* At one time the vtable info was grabbed 2 words at a time. This
fails on sparc unless you have 8-byte alignment. (tiemann) */
DECL_ALIGN (decl) = MAX (TYPE_ALIGN (double_type_node),
DECL_ALIGN (decl));
import_export_vtable (decl, class_type, 0); import_export_vtable (decl, class_type, 0);
return decl; return decl;
...@@ -553,11 +558,6 @@ get_vtable_decl (tree type, int complete) ...@@ -553,11 +558,6 @@ get_vtable_decl (tree type, int complete)
decl = build_vtable (type, get_vtable_name (type), vtbl_type_node); decl = build_vtable (type, get_vtable_name (type), vtbl_type_node);
CLASSTYPE_VTABLES (type) = decl; CLASSTYPE_VTABLES (type) = decl;
/* At one time the vtable info was grabbed 2 words at a time. This
fails on sparc unless you have 8-byte alignment. (tiemann) */
DECL_ALIGN (decl) = MAX (TYPE_ALIGN (double_type_node),
DECL_ALIGN (decl));
if (complete) if (complete)
{ {
DECL_EXTERNAL (decl) = 1; DECL_EXTERNAL (decl) = 1;
...@@ -2017,11 +2017,6 @@ layout_vtable_decl (tree binfo, int n) ...@@ -2017,11 +2017,6 @@ layout_vtable_decl (tree binfo, int n)
TREE_TYPE (vtable) = atype; TREE_TYPE (vtable) = atype;
DECL_SIZE (vtable) = DECL_SIZE_UNIT (vtable) = NULL_TREE; DECL_SIZE (vtable) = DECL_SIZE_UNIT (vtable) = NULL_TREE;
layout_decl (vtable, 0); layout_decl (vtable, 0);
/* At one time the vtable info was grabbed 2 words at a time. This
fails on SPARC unless you have 8-byte alignment. */
DECL_ALIGN (vtable) = MAX (TYPE_ALIGN (double_type_node),
DECL_ALIGN (vtable));
} }
} }
...@@ -2952,31 +2947,12 @@ check_bitfield_decl (tree field) ...@@ -2952,31 +2947,12 @@ check_bitfield_decl (tree field)
{ {
DECL_SIZE (field) = convert (bitsizetype, w); DECL_SIZE (field) = convert (bitsizetype, w);
DECL_BIT_FIELD (field) = 1; DECL_BIT_FIELD (field) = 1;
if (integer_zerop (w)
&& ! (* targetm.ms_bitfield_layout_p) (DECL_FIELD_CONTEXT (field)))
{
#ifdef EMPTY_FIELD_BOUNDARY
DECL_ALIGN (field) = MAX (DECL_ALIGN (field),
EMPTY_FIELD_BOUNDARY);
#endif
#ifdef PCC_BITFIELD_TYPE_MATTERS
if (PCC_BITFIELD_TYPE_MATTERS)
{
DECL_ALIGN (field) = MAX (DECL_ALIGN (field),
TYPE_ALIGN (type));
DECL_USER_ALIGN (field) |= TYPE_USER_ALIGN (type);
}
#endif
}
} }
else else
{ {
/* Non-bit-fields are aligned for their type. */ /* Non-bit-fields are aligned for their type. */
DECL_BIT_FIELD (field) = 0; DECL_BIT_FIELD (field) = 0;
CLEAR_DECL_C_BIT_FIELD (field); CLEAR_DECL_C_BIT_FIELD (field);
DECL_ALIGN (field) = MAX (DECL_ALIGN (field), TYPE_ALIGN (type));
DECL_USER_ALIGN (field) |= TYPE_USER_ALIGN (type);
} }
} }
...@@ -4428,8 +4404,6 @@ create_vtable_ptr (tree t, tree* virtuals_p) ...@@ -4428,8 +4404,6 @@ create_vtable_ptr (tree t, tree* virtuals_p)
DECL_ARTIFICIAL (field) = 1; DECL_ARTIFICIAL (field) = 1;
DECL_FIELD_CONTEXT (field) = t; DECL_FIELD_CONTEXT (field) = t;
DECL_FCONTEXT (field) = t; DECL_FCONTEXT (field) = t;
DECL_ALIGN (field) = TYPE_ALIGN (vtbl_ptr_type_node);
DECL_USER_ALIGN (field) = TYPE_USER_ALIGN (vtbl_ptr_type_node);
TYPE_VFIELD (t) = field; TYPE_VFIELD (t) = field;
...@@ -4950,8 +4924,6 @@ layout_class_type (tree t, tree *virtuals_p) ...@@ -4950,8 +4924,6 @@ layout_class_type (tree t, tree *virtuals_p)
char_type_node); char_type_node);
DECL_BIT_FIELD (padding_field) = 1; DECL_BIT_FIELD (padding_field) = 1;
DECL_SIZE (padding_field) = padding; DECL_SIZE (padding_field) = padding;
DECL_ALIGN (padding_field) = 1;
DECL_USER_ALIGN (padding_field) = 0;
layout_nonempty_base_or_field (rli, padding_field, layout_nonempty_base_or_field (rli, padding_field,
NULL_TREE, NULL_TREE,
empty_base_offsets); empty_base_offsets);
......
...@@ -1160,8 +1160,7 @@ make it all fit in fewer cache lines. ...@@ -1160,8 +1160,7 @@ make it all fit in fewer cache lines.
Alignment in bits to be given to a structure bit-field that follows an Alignment in bits to be given to a structure bit-field that follows an
empty field such as @code{int : 0;}. empty field such as @code{int : 0;}.
Note that @code{PCC_BITFIELD_TYPE_MATTERS} also affects the alignment If @code{PCC_BITFIELD_TYPE_MATTERS} is true, it overrides this macro.
that results from an empty field.
@findex STRUCTURE_SIZE_BOUNDARY @findex STRUCTURE_SIZE_BOUNDARY
@item STRUCTURE_SIZE_BOUNDARY @item STRUCTURE_SIZE_BOUNDARY
......
...@@ -357,6 +357,19 @@ round_down (value, divisor) ...@@ -357,6 +357,19 @@ round_down (value, divisor)
return size_binop (MULT_EXPR, size_binop (FLOOR_DIV_EXPR, value, arg), arg); return size_binop (MULT_EXPR, size_binop (FLOOR_DIV_EXPR, value, arg), arg);
} }
/* Subroutine of layout_decl: Force alignment required for the data type.
But if the decl itself wants greater alignment, don't override that. */
static inline void
do_type_align (tree type, tree decl)
{
if (TYPE_ALIGN (type) > DECL_ALIGN (decl))
{
DECL_ALIGN (decl) = TYPE_ALIGN (type);
DECL_USER_ALIGN (decl) = TYPE_USER_ALIGN (type);
}
}
/* Set the size, mode and alignment of a ..._DECL node. /* Set the size, mode and alignment of a ..._DECL node.
TYPE_DECL does need this for C++. TYPE_DECL does need this for C++.
Note that LABEL_DECL and CONST_DECL nodes do not need this, Note that LABEL_DECL and CONST_DECL nodes do not need this,
...@@ -411,67 +424,96 @@ layout_decl (decl, known_align) ...@@ -411,67 +424,96 @@ layout_decl (decl, known_align)
= convert (sizetype, size_binop (CEIL_DIV_EXPR, DECL_SIZE (decl), = convert (sizetype, size_binop (CEIL_DIV_EXPR, DECL_SIZE (decl),
bitsize_unit_node)); bitsize_unit_node));
/* Force alignment required for the data type. if (code != FIELD_DECL)
But if the decl itself wants greater alignment, don't override that. /* For non-fields, update the alignment from the type. */
Likewise, if the decl is packed, don't override it. */ do_type_align (type, decl);
if (! (code == FIELD_DECL && DECL_BIT_FIELD (decl)) else
&& (DECL_ALIGN (decl) == 0 /* For fields, it's a bit more complicated... */
|| (! (code == FIELD_DECL && DECL_PACKED (decl))
&& TYPE_ALIGN (type) > DECL_ALIGN (decl))))
{ {
DECL_ALIGN (decl) = TYPE_ALIGN (type); if (DECL_BIT_FIELD (decl))
DECL_USER_ALIGN (decl) = 0; {
} DECL_BIT_FIELD_TYPE (decl) = type;
/* For fields, set the bit field type and update the alignment. */ /* A zero-length bit-field affects the alignment of the next
if (code == FIELD_DECL) field. */
{ if (integer_zerop (DECL_SIZE (decl))
DECL_BIT_FIELD_TYPE (decl) = DECL_BIT_FIELD (decl) ? type : 0; && ! DECL_PACKED (decl)
if (maximum_field_alignment != 0) && ! (*targetm.ms_bitfield_layout_p) (DECL_FIELD_CONTEXT (decl)))
DECL_ALIGN (decl) = MIN (DECL_ALIGN (decl), maximum_field_alignment); {
#ifdef PCC_BITFIELD_TYPE_MATTERS
if (PCC_BITFIELD_TYPE_MATTERS)
do_type_align (type, decl);
else
#endif
#ifdef EMPTY_FIELD_BOUNDARY
if (EMPTY_FIELD_BOUNDARY > DECL_ALIGN (decl))
{
DECL_ALIGN (decl) = EMPTY_FIELD_BOUNDARY;
DECL_USER_ALIGN (decl) = 0;
}
#endif
}
/* See if we can use an ordinary integer mode for a bit-field.
Conditions are: a fixed size that is correct for another mode
and occupying a complete byte or bytes on proper boundary. */
if (TYPE_SIZE (type) != 0
&& TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
&& GET_MODE_CLASS (TYPE_MODE (type)) == MODE_INT)
{
enum machine_mode xmode
= mode_for_size_tree (DECL_SIZE (decl), MODE_INT, 1);
if (xmode != BLKmode && known_align >= GET_MODE_ALIGNMENT (xmode))
{
DECL_ALIGN (decl) = MAX (GET_MODE_ALIGNMENT (xmode),
DECL_ALIGN (decl));
DECL_MODE (decl) = xmode;
DECL_BIT_FIELD (decl) = 0;
}
}
/* Turn off DECL_BIT_FIELD if we won't need it set. */
if (TYPE_MODE (type) == BLKmode && DECL_MODE (decl) == BLKmode
&& known_align >= TYPE_ALIGN (type)
&& DECL_ALIGN (decl) >= TYPE_ALIGN (type))
DECL_BIT_FIELD (decl) = 0;
}
else if (DECL_PACKED (decl) && DECL_USER_ALIGN (decl))
/* Don't touch DECL_ALIGN. For other packed fields, go ahead and
round up; we'll reduce it again below. */;
else
do_type_align (type, decl);
/* If the field is of variable size, we can't misalign it since we /* If the field is of variable size, we can't misalign it since we
have no way to make a temporary to align the result. But this have no way to make a temporary to align the result. But this
isn't an issue if the decl is not addressable. Likewise if it isn't an issue if the decl is not addressable. Likewise if it
is of unknown size. */ is of unknown size. */
else if (DECL_PACKED (decl) if (DECL_PACKED (decl)
&& (DECL_NONADDRESSABLE_P (decl) && !DECL_USER_ALIGN (decl)
|| DECL_SIZE_UNIT (decl) == 0 && (DECL_NONADDRESSABLE_P (decl)
|| TREE_CODE (DECL_SIZE_UNIT (decl)) == INTEGER_CST)) || DECL_SIZE_UNIT (decl) == 0
{ || TREE_CODE (DECL_SIZE_UNIT (decl)) == INTEGER_CST))
DECL_ALIGN (decl) = MIN (DECL_ALIGN (decl), BITS_PER_UNIT); DECL_ALIGN (decl) = MIN (DECL_ALIGN (decl), BITS_PER_UNIT);
DECL_USER_ALIGN (decl) = 0;
} /* Should this be controlled by DECL_USER_ALIGN, too? */
} if (maximum_field_alignment != 0)
DECL_ALIGN (decl) = MIN (DECL_ALIGN (decl), maximum_field_alignment);
/* See if we can use an ordinary integer mode for a bit-field. if (! DECL_USER_ALIGN (decl))
Conditions are: a fixed size that is correct for another mode
and occupying a complete byte or bytes on proper boundary. */
if (code == FIELD_DECL && DECL_BIT_FIELD (decl)
&& TYPE_SIZE (type) != 0
&& TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
&& GET_MODE_CLASS (TYPE_MODE (type)) == MODE_INT)
{
enum machine_mode xmode
= mode_for_size_tree (DECL_SIZE (decl), MODE_INT, 1);
if (xmode != BLKmode && known_align >= GET_MODE_ALIGNMENT (xmode))
{ {
DECL_ALIGN (decl) = MAX (GET_MODE_ALIGNMENT (xmode), /* Some targets (i.e. i386, VMS) limit struct field alignment
DECL_ALIGN (decl)); to a lower boundary than alignment of variables unless
DECL_MODE (decl) = xmode; it was overridden by attribute aligned. */
DECL_BIT_FIELD (decl) = 0; #ifdef BIGGEST_FIELD_ALIGNMENT
DECL_ALIGN (decl)
= MIN (DECL_ALIGN (decl), (unsigned) BIGGEST_FIELD_ALIGNMENT);
#endif
#ifdef ADJUST_FIELD_ALIGN
DECL_ALIGN (decl) = ADJUST_FIELD_ALIGN (decl, DECL_ALIGN (decl));
#endif
} }
} }
/* Turn off DECL_BIT_FIELD if we won't need it set. */
if (code == FIELD_DECL && DECL_BIT_FIELD (decl)
&& TYPE_MODE (type) == BLKmode && DECL_MODE (decl) == BLKmode
&& known_align >= TYPE_ALIGN (type)
&& DECL_ALIGN (decl) >= TYPE_ALIGN (type)
&& DECL_SIZE_UNIT (decl) != 0)
DECL_BIT_FIELD (decl) = 0;
/* Evaluate nonconstant size only once, either now or as soon as safe. */ /* Evaluate nonconstant size only once, either now or as soon as safe. */
if (DECL_SIZE (decl) != 0 && TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST) if (DECL_SIZE (decl) != 0 && TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
DECL_SIZE (decl) = variable_size (DECL_SIZE (decl)); DECL_SIZE (decl) = variable_size (DECL_SIZE (decl));
...@@ -532,7 +574,7 @@ start_record_layout (t) ...@@ -532,7 +574,7 @@ start_record_layout (t)
declaration, for example) use it -- otherwise, start with a declaration, for example) use it -- otherwise, start with a
one-byte alignment. */ one-byte alignment. */
rli->record_align = MAX (BITS_PER_UNIT, TYPE_ALIGN (t)); rli->record_align = MAX (BITS_PER_UNIT, TYPE_ALIGN (t));
rli->unpacked_align = rli->unpadded_align = rli->record_align; rli->unpacked_align = rli->record_align;
rli->offset_align = MAX (rli->record_align, BIGGEST_ALIGNMENT); rli->offset_align = MAX (rli->record_align, BIGGEST_ALIGNMENT);
#ifdef STRUCTURE_SIZE_BOUNDARY #ifdef STRUCTURE_SIZE_BOUNDARY
...@@ -621,8 +663,8 @@ debug_rli (rli) ...@@ -621,8 +663,8 @@ debug_rli (rli)
print_node_brief (stderr, "\noffset", rli->offset, 0); print_node_brief (stderr, "\noffset", rli->offset, 0);
print_node_brief (stderr, " bitpos", rli->bitpos, 0); print_node_brief (stderr, " bitpos", rli->bitpos, 0);
fprintf (stderr, "\naligns: rec = %u, unpack = %u, unpad = %u, off = %u\n", fprintf (stderr, "\naligns: rec = %u, unpack = %u, off = %u\n",
rli->record_align, rli->unpacked_align, rli->unpadded_align, rli->record_align, rli->unpacked_align,
rli->offset_align); rli->offset_align);
if (rli->packed_maybe_necessary) if (rli->packed_maybe_necessary)
fprintf (stderr, "packed may be necessary\n"); fprintf (stderr, "packed may be necessary\n");
...@@ -679,40 +721,21 @@ update_alignment_for_field (rli, field, known_align) ...@@ -679,40 +721,21 @@ update_alignment_for_field (rli, field, known_align)
tree type = TREE_TYPE (field); tree type = TREE_TYPE (field);
/* True if the field was explicitly aligned by the user. */ /* True if the field was explicitly aligned by the user. */
bool user_align; bool user_align;
bool is_bitfield;
/* Lay out the field so we know what alignment it needs. For a /* Lay out the field so we know what alignment it needs. */
packed field, use the alignment as specified, disregarding what layout_decl (field, known_align);
the type would want. */
desired_align = DECL_ALIGN (field); desired_align = DECL_ALIGN (field);
user_align = DECL_USER_ALIGN (field); user_align = DECL_USER_ALIGN (field);
layout_decl (field, known_align);
if (! DECL_PACKED (field))
{
desired_align = DECL_ALIGN (field);
user_align = DECL_USER_ALIGN (field);
}
/* Some targets (i.e. i386, VMS) limit struct field alignment
to a lower boundary than alignment of variables unless
it was overridden by attribute aligned. */
#ifdef BIGGEST_FIELD_ALIGNMENT
if (!user_align)
desired_align
= MIN (desired_align, (unsigned) BIGGEST_FIELD_ALIGNMENT);
#endif
#ifdef ADJUST_FIELD_ALIGN is_bitfield = (type != error_mark_node
if (!user_align) && DECL_BIT_FIELD_TYPE (field)
desired_align = ADJUST_FIELD_ALIGN (field, desired_align); && ! integer_zerop (TYPE_SIZE (type)));
#endif
/* Record must have at least as much alignment as any field. /* Record must have at least as much alignment as any field.
Otherwise, the alignment of the field within the record is Otherwise, the alignment of the field within the record is
meaningless. */ meaningless. */
if ((* targetm.ms_bitfield_layout_p) (rli->t) if (is_bitfield && (* targetm.ms_bitfield_layout_p) (rli->t))
&& type != error_mark_node
&& DECL_BIT_FIELD_TYPE (field)
&& ! integer_zerop (TYPE_SIZE (type)))
{ {
/* Here, the alignment of the underlying type of a bitfield can /* Here, the alignment of the underlying type of a bitfield can
affect the alignment of a record; even a zero-sized field affect the alignment of a record; even a zero-sized field
...@@ -732,29 +755,11 @@ update_alignment_for_field (rli, field, known_align) ...@@ -732,29 +755,11 @@ update_alignment_for_field (rli, field, known_align)
type_align = MIN (type_align, maximum_field_alignment); type_align = MIN (type_align, maximum_field_alignment);
rli->record_align = MAX (rli->record_align, type_align); rli->record_align = MAX (rli->record_align, type_align);
rli->unpacked_align = MAX (rli->unpacked_align, TYPE_ALIGN (type)); rli->unpacked_align = MAX (rli->unpacked_align, TYPE_ALIGN (type));
rli->unpadded_align = MAX (rli->unpadded_align, DECL_ALIGN (field));
} }
else
desired_align = 1;
} }
else
#ifdef PCC_BITFIELD_TYPE_MATTERS #ifdef PCC_BITFIELD_TYPE_MATTERS
if (PCC_BITFIELD_TYPE_MATTERS && type != error_mark_node else if (is_bitfield && PCC_BITFIELD_TYPE_MATTERS)
&& ! (* targetm.ms_bitfield_layout_p) (rli->t)
&& DECL_BIT_FIELD_TYPE (field)
&& ! integer_zerop (TYPE_SIZE (type)))
{ {
/* A zero-length bit-field affects the alignment of the next
field. */
if (!DECL_PACKED (field) && !user_align
&& integer_zerop (DECL_SIZE (field)))
{
desired_align = TYPE_ALIGN (type);
#ifdef ADJUST_FIELD_ALIGN
desired_align = ADJUST_FIELD_ALIGN (field, desired_align);
#endif
}
/* Named bit-fields cause the entire structure to have the /* Named bit-fields cause the entire structure to have the
alignment implied by their type. */ alignment implied by their type. */
if (DECL_NAME (field) != 0) if (DECL_NAME (field) != 0)
...@@ -779,18 +784,16 @@ update_alignment_for_field (rli, field, known_align) ...@@ -779,18 +784,16 @@ update_alignment_for_field (rli, field, known_align)
rli->record_align = MAX (rli->record_align, desired_align); rli->record_align = MAX (rli->record_align, desired_align);
rli->record_align = MAX (rli->record_align, type_align); rli->record_align = MAX (rli->record_align, type_align);
rli->unpadded_align = MAX (rli->unpadded_align, DECL_ALIGN (field));
if (warn_packed) if (warn_packed)
rli->unpacked_align = MAX (rli->unpacked_align, TYPE_ALIGN (type)); rli->unpacked_align = MAX (rli->unpacked_align, TYPE_ALIGN (type));
user_align |= TYPE_USER_ALIGN (type); user_align |= TYPE_USER_ALIGN (type);
} }
} }
else
#endif #endif
else
{ {
rli->record_align = MAX (rli->record_align, desired_align); rli->record_align = MAX (rli->record_align, desired_align);
rli->unpacked_align = MAX (rli->unpacked_align, TYPE_ALIGN (type)); rli->unpacked_align = MAX (rli->unpacked_align, TYPE_ALIGN (type));
rli->unpadded_align = MAX (rli->unpadded_align, DECL_ALIGN (field));
} }
TYPE_USER_ALIGN (rli->t) |= user_align; TYPE_USER_ALIGN (rli->t) |= user_align;
...@@ -905,7 +908,7 @@ place_field (rli, field) ...@@ -905,7 +908,7 @@ place_field (rli, field)
if (warn_packed && DECL_PACKED (field)) if (warn_packed && DECL_PACKED (field))
{ {
if (known_align > TYPE_ALIGN (type)) if (known_align >= TYPE_ALIGN (type))
{ {
if (TYPE_ALIGN (type) > desired_align) if (TYPE_ALIGN (type) > desired_align)
{ {
......
...@@ -2452,11 +2452,9 @@ typedef struct record_layout_info_s ...@@ -2452,11 +2452,9 @@ typedef struct record_layout_info_s
tree bitpos; tree bitpos;
/* The alignment of the record so far, in bits. */ /* The alignment of the record so far, in bits. */
unsigned int record_align; unsigned int record_align;
/* The alignment of the record so far, not including padding, in bits. */ /* The alignment of the record so far, ignoring #pragma pack and
__attribute__ ((packed)), in bits. */
unsigned int unpacked_align; unsigned int unpacked_align;
/* The alignment of the record so far, allowing for the record to be
padded only at the end, in bits. */
unsigned int unpadded_align;
/* The previous field layed out. */ /* The previous field layed out. */
tree prev_field; tree prev_field;
/* The static variables (i.e., class variables, as opposed to /* The static variables (i.e., class variables, as opposed to
...@@ -2464,6 +2462,8 @@ typedef struct record_layout_info_s ...@@ -2464,6 +2462,8 @@ typedef struct record_layout_info_s
tree pending_statics; tree pending_statics;
/* Bits remaining in the current alignment group */ /* Bits remaining in the current alignment group */
int remaining_in_alignment; int remaining_in_alignment;
/* True if we've seen a packed field that didn't have normal
alignment anyway. */
int packed_maybe_necessary; int packed_maybe_necessary;
} *record_layout_info; } *record_layout_info;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment