From 683ccd0568569c67b117e87638782c6d870791b2 Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Sun, 27 Jan 2019 19:14:14 +0000 Subject: 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. : 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. : 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) : Compute a better value by using the extra subtypes on the self-referential bounds. : Rewrite. Deal with "negative value" in unsigned types. : 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 --- gcc/ada/gcc-interface/trans.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'gcc/ada/gcc-interface/trans.c') diff --git a/gcc/ada/gcc-interface/trans.c b/gcc/ada/gcc-interface/trans.c index 3e326b4..3b0093e 100644 --- a/gcc/ada/gcc-interface/trans.c +++ b/gcc/ada/gcc-interface/trans.c @@ -2374,15 +2374,12 @@ Attribute_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, int attribute) else gnu_result = rm_size (gnu_type); - /* Deal with a self-referential size by returning the maximum size for - a type and by qualifying the size with the object otherwise. */ - if (CONTAINS_PLACEHOLDER_P (gnu_result)) - { - if (TREE_CODE (gnu_prefix) == TYPE_DECL) - gnu_result = max_size (gnu_result, true); - else - gnu_result = substitute_placeholder_in_expr (gnu_result, gnu_expr); - } + /* Deal with a self-referential size by qualifying the size with the + object or returning the maximum size for a type. */ + if (TREE_CODE (gnu_prefix) != TYPE_DECL) + gnu_result = SUBSTITUTE_PLACEHOLDER_IN_EXPR (gnu_result, gnu_expr); + else if (CONTAINS_PLACEHOLDER_P (gnu_result)) + gnu_result = max_size (gnu_result, true); /* If the type contains a template, subtract the padded size of the template, except for 'Max_Size_In_Storage_Elements because we need @@ -3227,13 +3224,25 @@ static bool can_be_lower_p (tree val1, tree val2) { if (TREE_CODE (val1) == NOP_EXPR) - val1 = TYPE_MIN_VALUE (TREE_TYPE (TREE_OPERAND (val1, 0))); + { + tree type = TREE_TYPE (TREE_OPERAND (val1, 0)); + if (can_be_lower_p (TYPE_MAX_VALUE (type), TYPE_MIN_VALUE (type))) + return true; + + val1 = TYPE_MIN_VALUE (type); + } if (TREE_CODE (val1) != INTEGER_CST) return true; if (TREE_CODE (val2) == NOP_EXPR) - val2 = TYPE_MAX_VALUE (TREE_TYPE (TREE_OPERAND (val2, 0))); + { + tree type = TREE_TYPE (TREE_OPERAND (val2, 0)); + if (can_be_lower_p (TYPE_MAX_VALUE (type), TYPE_MIN_VALUE (type))) + return true; + + val2 = TYPE_MAX_VALUE (type); + } if (TREE_CODE (val2) != INTEGER_CST) return true; -- cgit v1.1