static vec<subst_pair> build_subst_list (Entity_Id, Entity_Id, bool);
static vec<variant_desc> build_variant_list (tree, Node_Id, vec<subst_pair>,
vec<variant_desc>);
-static tree maybe_saturate_size (tree);
+static tree maybe_saturate_size (tree, unsigned int align);
static tree validate_size (Uint, tree, Entity_Id, enum tree_code, bool, bool,
const char *, const char *);
static void set_rm_size (Uint, tree, Entity_Id);
/* If the size is self-referential, annotate the maximum value
after saturating it, if need be, to avoid a No_Uint value. */
if (CONTAINS_PLACEHOLDER_P (gnu_size))
- gnu_size = maybe_saturate_size (max_size (gnu_size, true));
+ {
+ const unsigned int align
+ = UI_To_Int (Alignment (gnat_entity)) * BITS_PER_UNIT;
+ gnu_size
+ = maybe_saturate_size (max_size (gnu_size, true), align);
+ }
/* If we are just annotating types and the type is tagged, the tag
and the parent components are not generated by the front-end so
gnu_size = size_binop (PLUS_EXPR, gnu_size, offset);
}
- gnu_size = maybe_saturate_size (round_up (gnu_size, align));
+ gnu_size
+ = maybe_saturate_size (round_up (gnu_size, align), align);
Set_Esize (gnat_entity, annotate_value (gnu_size));
/* Tagged types are Strict_Alignment so RM_Size = Esize. */
}
\f
/* If SIZE has overflowed, return the maximum valid size, which is the upper
- bound of the signed sizetype in bits; otherwise return SIZE unmodified. */
+ bound of the signed sizetype in bits, rounded down to ALIGN. Otherwise
+ return SIZE unmodified. */
static tree
-maybe_saturate_size (tree size)
+maybe_saturate_size (tree size, unsigned int align)
{
if (TREE_CODE (size) == INTEGER_CST && TREE_OVERFLOW (size))
- size = size_binop (MULT_EXPR,
- fold_convert (bitsizetype, TYPE_MAX_VALUE (ssizetype)),
- build_int_cst (bitsizetype, BITS_PER_UNIT));
+ {
+ size
+ = size_binop (MULT_EXPR,
+ fold_convert (bitsizetype, TYPE_MAX_VALUE (ssizetype)),
+ build_int_cst (bitsizetype, BITS_PER_UNIT));
+ size = round_down (size, align);
+ }
+
return size;
}