aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/gcc-interface/misc.c
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2019-01-27 19:14:14 +0000
committerEric Botcazou <ebotcazou@gcc.gnu.org>2019-01-27 19:14:14 +0000
commit683ccd0568569c67b117e87638782c6d870791b2 (patch)
treed3ad36179e7f2d6037dde651ff566d81ef28ab8a /gcc/ada/gcc-interface/misc.c
parent33731c666114349344848ddd4218f98ef486398e (diff)
downloadgcc-683ccd0568569c67b117e87638782c6d870791b2.zip
gcc-683ccd0568569c67b117e87638782c6d870791b2.tar.gz
gcc-683ccd0568569c67b117e87638782c6d870791b2.tar.bz2
repinfo.adb (List_Component_Layout): Remove superfluous space for zero-sized field.
* repinfo.adb (List_Component_Layout): Remove superfluous space for zero-sized field. * gcc-interface/ada-tree.h (TYPE_IS_EXTRA_SUBTYPE_P): New macro. * gcc-interface/gigi.h (create_extra_subtype): Declare. * gcc-interface/decl.c (TYPE_ARRAY_SIZE_LIMIT): Likewise. (update_n_elem): New function. (gnat_to_gnu_entity): Use create_extra_subtype to create extra subtypes instead of doing it manually. <E_Array_Type>: Use update_n_elem to compute the maximum size. Use the index type instead of base type for the bounds. Set TYPE_ARRAY_MAX_SIZE of the array to the maximum size. <E_Array_Subtype>: Create an extra subtype using the index type of the base array type for self-referential bounds. Use update_n_elem to compute the maximum size. Set TYPE_ARRAY_MAX_SIZE of the array to the maximum size. (gnat_to_gnu_field): Clear DECL_NONADDRESSABLE_P on discriminants. * gcc-interface/misc.c (gnat_get_alias_set): Return the alias set of the base type for an extra subtype. (gnat_type_max_size): Remove obsolete code. * gcc-interface/trans.c (Attribute_to_gnu): Minor tweak. (can_be_lower_p): Deal with pathological types. * gcc-interface/utils.c (create_extra_subtype): New function. (create_field_decl): Minor tweak. (max_size) <tcc_reference>: Compute a better value by using the extra subtypes on the self-referential bounds. <tcc_binary>: Rewrite. Deal with "negative value" in unsigned types. <tcc_expression>: Likewise. * gcc-interface/utils2.c (compare_arrays): Retrieve the original bounds of the arrays upfront. Swap only if the second length is not constant. Use comparisons on the original bounds consistently for the null tests. (build_binary_op): Use TYPE_IS_EXTRA_SUBTYPE_P macro. (build_allocator): Minor tweak. From-SVN: r268318
Diffstat (limited to 'gcc/ada/gcc-interface/misc.c')
-rw-r--r--gcc/ada/gcc-interface/misc.c71
1 files changed, 19 insertions, 52 deletions
diff --git a/gcc/ada/gcc-interface/misc.c b/gcc/ada/gcc-interface/misc.c
index 623c48e..38e33be 100644
--- a/gcc/ada/gcc-interface/misc.c
+++ b/gcc/ada/gcc-interface/misc.c
@@ -727,6 +727,10 @@ gnat_get_alias_set (tree type)
if (TYPE_IS_PADDING_P (type))
return get_alias_set (TREE_TYPE (TYPE_FIELDS (type)));
+ /* If this is an extra subtype, use the base type. */
+ else if (TYPE_IS_EXTRA_SUBTYPE_P (type))
+ return get_alias_set (get_base_type (type));
+
/* If the type is an unconstrained array, use the type of the
self-referential array we make. */
else if (TREE_CODE (type) == UNCONSTRAINED_ARRAY_TYPE)
@@ -753,59 +757,22 @@ gnat_type_max_size (const_tree gnu_type)
elaborated and possibly replaced by a VAR_DECL. */
tree max_size_unit = max_size (TYPE_SIZE_UNIT (gnu_type), true);
- /* If we don't have a constant, try to look at attributes which should have
- stayed untouched. */
- if (!tree_fits_uhwi_p (max_size_unit))
+ /* If we don't have a constant, see what we can get from TYPE_ADA_SIZE,
+ which should stay untouched. */
+ if (!tree_fits_uhwi_p (max_size_unit)
+ && RECORD_OR_UNION_TYPE_P (gnu_type)
+ && !TYPE_FAT_POINTER_P (gnu_type)
+ && TYPE_ADA_SIZE (gnu_type))
{
- /* For record types, see what we can get from TYPE_ADA_SIZE. */
- if (RECORD_OR_UNION_TYPE_P (gnu_type)
- && !TYPE_FAT_POINTER_P (gnu_type)
- && TYPE_ADA_SIZE (gnu_type))
- {
- tree max_ada_size = max_size (TYPE_ADA_SIZE (gnu_type), true);
-
- /* If we have succeeded in finding a constant, round it up to the
- type's alignment and return the result in units. */
- if (tree_fits_uhwi_p (max_ada_size))
- max_size_unit
- = size_binop (CEIL_DIV_EXPR,
- round_up (max_ada_size, TYPE_ALIGN (gnu_type)),
- bitsize_unit_node);
- }
-
- /* For array types, see what we can get from TYPE_INDEX_TYPE. */
- else if (TREE_CODE (gnu_type) == ARRAY_TYPE
- && TYPE_INDEX_TYPE (TYPE_DOMAIN (gnu_type))
- && tree_fits_uhwi_p (TYPE_SIZE_UNIT (TREE_TYPE (gnu_type))))
- {
- tree lb = TYPE_MIN_VALUE (TYPE_INDEX_TYPE (TYPE_DOMAIN (gnu_type)));
- tree hb = TYPE_MAX_VALUE (TYPE_INDEX_TYPE (TYPE_DOMAIN (gnu_type)));
- if (TREE_CODE (lb) != INTEGER_CST
- && TYPE_RM_SIZE (TREE_TYPE (lb))
- && compare_tree_int (TYPE_RM_SIZE (TREE_TYPE (lb)), 16) <= 0)
- lb = TYPE_MIN_VALUE (TREE_TYPE (lb));
- if (TREE_CODE (hb) != INTEGER_CST
- && TYPE_RM_SIZE (TREE_TYPE (hb))
- && compare_tree_int (TYPE_RM_SIZE (TREE_TYPE (hb)), 16) <= 0)
- hb = TYPE_MAX_VALUE (TREE_TYPE (hb));
- if (TREE_CODE (lb) == INTEGER_CST && TREE_CODE (hb) == INTEGER_CST)
- {
- tree ctype = get_base_type (TREE_TYPE (lb));
- lb = fold_convert (ctype, lb);
- hb = fold_convert (ctype, hb);
- if (tree_int_cst_le (lb, hb))
- {
- tree length
- = fold_build2 (PLUS_EXPR, ctype,
- fold_build2 (MINUS_EXPR, ctype, hb, lb),
- build_int_cst (ctype, 1));
- max_size_unit
- = fold_build2 (MULT_EXPR, sizetype,
- fold_convert (sizetype, length),
- TYPE_SIZE_UNIT (TREE_TYPE (gnu_type)));
- }
- }
- }
+ tree max_ada_size = max_size (TYPE_ADA_SIZE (gnu_type), true);
+
+ /* If we have succeeded in finding a constant, round it up to the
+ type's alignment and return the result in units. */
+ if (tree_fits_uhwi_p (max_ada_size))
+ max_size_unit
+ = size_binop (CEIL_DIV_EXPR,
+ round_up (max_ada_size, TYPE_ALIGN (gnu_type)),
+ bitsize_unit_node);
}
return max_size_unit;