summaryrefslogtreecommitdiff
path: root/gcc/stor-layout.c
diff options
context:
space:
mode:
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2000-06-14 05:30:09 +0000
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2000-06-14 05:30:09 +0000
commitaca14577e8d8624fdcde19eafacac16617b6b02e (patch)
tree48e491d0a3752df2f9332542b6e3fd795956e7c0 /gcc/stor-layout.c
parent59420fa783ac122c63a0d4bc98c42ef0e62206a5 (diff)
downloadgcc-aca14577e8d8624fdcde19eafacac16617b6b02e.tar.gz
* tree.h (TYPE_USER_ALIGN, DECL_USER_ALIGN): Define.
(struct tree_type, struct tree_decl): Add user_align member. * stor-layout.c (layout_decl): Set DECL_USER_ALIGN. (place_union_field): If BIGGEST_FIELD_ALIGNMENT is defined and DECL_USER_ALIGN 0, cap alignment to this value. (place_field): Likewise. (finalize_type_size): Set TYPE_USER_ALIGN. (layout_type): Likewise. (initialize_sizetypes): Likewise. * c-common.c (decl_attributes): Set TYPE_USER_ALIGN resp. DECL_USER_ALIGN to 1. * c-decl.c (duplicate_decls): Set DECL_USER_ALIGN. (xfer_tag): Set TYPE_USER_ALIGN. (finish_struct): Set DECL_USER_ALIGN resp. TYPE_USER_ALIGN. (finish_enum): Likewise. * stmt.c (expand_decl): Set DECL_USER_ALIGN. (expand_anon_union_decl): Likewise. * tree.c (make_node): Set DECL_USER_ALIGN resp. TYPE_USER_ALIGN. (build_index_type): Set TYPE_USER_ALIGN. (build_range_type): Likewise. (build_common_tree_nodes_2): Likewise. * tm.texi (BIGGEST_FIELD_ALIGNMENT): Document the changed meaning. ch/: * decl.c (init_decl_processing): Set TYPE_USER_ALIGN. (layout_enum): Set DECL_USER_ALIGN resp. TYPE_USER_ALIGN. * typeck.c (layout_chill_range_type): Set TYPE_USER_ALIGN. (apply_chill_field_layout): Set DECL_USER_ALIGN. (layout_chill_struct_type): Set TYPE_USER_ALIGN. cp/: * class.c (build_secondary_vtable): Set DECL_USER_ALIGN. (check_bitfield_decl, check_field_decl): Likewise. (build_vtbl_or_vbase_field, build_base_field): Likewise. (layout_class_type): Set DECL_USER_ALIGN resp. CLASSTYPE_USER_ALIGN. * decl.c (record_unknown_type): Set TYPE_USER_ALIGN. (xfer_tag, finish_enum): Likewise. * decl2.c (finish_builtin_type): Likewise. * init.c (init_init_processing): Likewise. * pt.c (instantiate_class_template): Likewise. * rtti.c (get_tinfo_decl, synthesize_tinfo_fn): Set DECL_USER_ALIGN. * cp-tree.h (struct lang_type): Add user_align member. (CLASSTYPE_USER_ALIGN): Define. f/: * com.c (ffecom_transform_common_): Set DECL_USER_ALIGN. (ffecom_transform_equiv_, ffecom_decl_field): Likewise. (ffecom_init_0): Set DECL_USER_ALIGN resp. TYPE_USER_ALIGN. (duplicate_decls): Set DECL_USER_ALIGN. java/: * typeck.c (build_java_array_type): Set TYPE_USER_ALIGN. * parse.y (java_complete_class): Set DECL_USER_ALIGN. * parse.c: Rebuilt. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@34541 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/stor-layout.c')
-rw-r--r--gcc/stor-layout.c53
1 files changed, 45 insertions, 8 deletions
diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c
index b28432bd848..65ac15b12bc 100644
--- a/gcc/stor-layout.c
+++ b/gcc/stor-layout.c
@@ -330,7 +330,10 @@ layout_decl (decl, known_align)
&& (DECL_ALIGN (decl) == 0
|| (! (code == FIELD_DECL && DECL_PACKED (decl))
&& TYPE_ALIGN (type) > DECL_ALIGN (decl))))
- DECL_ALIGN (decl) = TYPE_ALIGN (type);
+ {
+ DECL_ALIGN (decl) = TYPE_ALIGN (type);
+ DECL_USER_ALIGN (decl) = TYPE_USER_ALIGN (type);
+ }
/* For fields, set the bit field type and update the alignment. */
if (code == FIELD_DECL)
@@ -339,7 +342,10 @@ layout_decl (decl, known_align)
if (maximum_field_alignment != 0)
DECL_ALIGN (decl) = MIN (DECL_ALIGN (decl), maximum_field_alignment);
else if (DECL_PACKED (decl))
- 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;
+ }
}
/* See if we can use an ordinary integer mode for a bit-field.
@@ -572,14 +578,27 @@ place_union_field (rli, field)
record_layout_info rli;
tree field;
{
+ unsigned int desired_align;
+
layout_decl (field, 0);
DECL_FIELD_OFFSET (field) = size_zero_node;
DECL_FIELD_BIT_OFFSET (field) = bitsize_zero_node;
DECL_OFFSET_ALIGN (field) = BIGGEST_ALIGNMENT;
+ desired_align = DECL_ALIGN (field);
+
+#ifdef BIGGEST_FIELD_ALIGNMENT
+ /* Some targets (i.e. i386) limit union field alignment
+ to a lower boundary than alignment of variables unless
+ it was overridden by attribute aligned. */
+ if (! DECL_USER_ALIGN (field))
+ desired_align =
+ MIN (desired_align, (unsigned) BIGGEST_FIELD_ALIGNMENT);
+#endif
+
/* Union must be at least as aligned as any field requires. */
- rli->record_align = MAX (rli->record_align, DECL_ALIGN (field));
+ rli->record_align = MAX (rli->record_align, desired_align);
#ifdef PCC_BITFIELD_TYPE_MATTERS
/* On the m88000, a bit field of declare type `int' forces the
@@ -615,6 +634,7 @@ place_field (rli, field)
record as it presently stands. */
unsigned int known_align;
unsigned int actual_align;
+ unsigned int user_align;
/* The type of this field. */
tree type = TREE_TYPE (field);
@@ -660,14 +680,21 @@ place_field (rli, field)
packed field, use the alignment as specified, disregarding what
the type would want. */
desired_align = DECL_ALIGN (field);
+ user_align = DECL_USER_ALIGN (field);
layout_decl (field, known_align);
if (! DECL_PACKED (field))
- desired_align = DECL_ALIGN (field);
+ {
+ desired_align = DECL_ALIGN (field);
+ user_align = DECL_USER_ALIGN (field);
+ }
- /* Some targets (i.e. VMS) limit struct field alignment
- to a lower boundary than alignment of variables. */
#ifdef BIGGEST_FIELD_ALIGNMENT
- desired_align = MIN (desired_align, (unsigned) BIGGEST_FIELD_ALIGNMENT);
+ /* 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. */
+ if (! user_align)
+ desired_align =
+ MIN (desired_align, (unsigned) BIGGEST_FIELD_ALIGNMENT);
#endif
#ifdef ADJUST_FIELD_ALIGN
desired_align = ADJUST_FIELD_ALIGN (field, desired_align);
@@ -902,6 +929,7 @@ finalize_record_size (rli)
#else
TYPE_ALIGN (rli->t) = MAX (TYPE_ALIGN (rli->t), rli->record_align);
#endif
+ TYPE_USER_ALIGN (rli->t) = 1;
/* Compute the size so far. Be sure to allow for extra bits in the
size in bytes. We have guaranteed above that it will be no more
@@ -1083,7 +1111,10 @@ finalize_type_size (type)
|| (TREE_CODE (type) != RECORD_TYPE && TREE_CODE (type) != UNION_TYPE
&& TREE_CODE (type) != QUAL_UNION_TYPE
&& TREE_CODE (type) != ARRAY_TYPE)))
- TYPE_ALIGN (type) = GET_MODE_ALIGNMENT (TYPE_MODE (type));
+ {
+ TYPE_ALIGN (type) = GET_MODE_ALIGNMENT (TYPE_MODE (type));
+ TYPE_USER_ALIGN (type) = 0;
+ }
/* Do machine-dependent extra alignment. */
#ifdef ROUND_TYPE_ALIGN
@@ -1133,6 +1164,7 @@ finalize_type_size (type)
tree size = TYPE_SIZE (type);
tree size_unit = TYPE_SIZE_UNIT (type);
unsigned int align = TYPE_ALIGN (type);
+ unsigned int user_align = TYPE_USER_ALIGN (type);
enum machine_mode mode = TYPE_MODE (type);
/* Copy it into all variants. */
@@ -1143,6 +1175,7 @@ finalize_type_size (type)
TYPE_SIZE (variant) = size;
TYPE_SIZE_UNIT (variant) = size_unit;
TYPE_ALIGN (variant) = align;
+ TYPE_USER_ALIGN (variant) = user_align;
TYPE_MODE (variant) = mode;
}
}
@@ -1256,6 +1289,7 @@ layout_type (type)
case VOID_TYPE:
/* This is an incomplete type and so doesn't have a size. */
TYPE_ALIGN (type) = 1;
+ TYPE_USER_ALIGN (type) = 0;
TYPE_MODE (type) = VOIDmode;
break;
@@ -1460,6 +1494,7 @@ layout_type (type)
TYPE_SIZE (type) = bitsize_int (rounded_size);
TYPE_SIZE_UNIT (type) = size_int (rounded_size / BITS_PER_UNIT);
TYPE_ALIGN (type) = alignment;
+ TYPE_USER_ALIGN (type) = 0;
TYPE_PRECISION (type) = size_in_bits;
}
break;
@@ -1468,6 +1503,7 @@ layout_type (type)
/* The size may vary in different languages, so the language front end
should fill in the size. */
TYPE_ALIGN (type) = BIGGEST_ALIGNMENT;
+ TYPE_USER_ALIGN (type) = 0;
TYPE_MODE (type) = BLKmode;
break;
@@ -1534,6 +1570,7 @@ initialize_sizetypes ()
TYPE_MODE (t) = SImode;
TYPE_ALIGN (t) = GET_MODE_ALIGNMENT (SImode);
+ TYPE_USER_ALIGN (t) = 0;
TYPE_SIZE (t) = build_int_2 (GET_MODE_BITSIZE (SImode), 0);
TYPE_SIZE_UNIT (t) = build_int_2 (GET_MODE_SIZE (SImode), 0);
TREE_UNSIGNED (t) = 1;