From: Eric Botcazou Date: Fri, 30 Aug 2019 15:32:51 +0000 (+0000) Subject: decl.c (maybe_saturate_size): New function. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=875bdbe2f6d2d54f0ccefd27cea3a533fef834eb;p=gcc.git decl.c (maybe_saturate_size): New function. * gcc-interface/decl.c (maybe_saturate_size): New function. (gnat_to_gnu_entity): Invoke it on the Esize of types before sending it for back-annotations. * gcc-interface/trans.c: Fix typo. From-SVN: r275200 --- diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index bb43565467d..410828ed37a 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,10 @@ +2019-08-30 Eric Botcazou + + * gcc-interface/decl.c (maybe_saturate_size): New function. + (gnat_to_gnu_entity): Invoke it on the Esize of types before sending + it for back-annotations. + * gcc-interface/trans.c: Fix typo. + 2019-08-30 Eric Botcazou * gcc-interface/ada-tree.h (DECL_FORCED_BY_REF_P): New macro. diff --git a/gcc/ada/gcc-interface/decl.c b/gcc/ada/gcc-interface/decl.c index 85a5e76724f..d1082ee1a40 100644 --- a/gcc/ada/gcc-interface/decl.c +++ b/gcc/ada/gcc-interface/decl.c @@ -232,6 +232,7 @@ static tree build_position_list (tree, bool, tree, tree, unsigned int, tree); static vec build_subst_list (Entity_Id, Entity_Id, bool); static vec build_variant_list (tree, vec, vec); +static tree maybe_saturate_size (tree); static tree validate_size (Uint, tree, Entity_Id, enum tree_code, bool, bool); static void set_rm_size (Uint, tree, Entity_Id); static unsigned int validate_alignment (Uint, Entity_Id, unsigned int); @@ -4327,9 +4328,10 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition) { tree gnu_size = TYPE_SIZE (gnu_type); - /* If the size is self-referential, annotate the maximum value. */ + /* 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 = max_size (gnu_size, true); + gnu_size = maybe_saturate_size (max_size (gnu_size, true)); /* 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 @@ -4365,7 +4367,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition) gnu_size = size_binop (PLUS_EXPR, gnu_size, offset); } - gnu_size = round_up (gnu_size, align); + gnu_size = maybe_saturate_size (round_up (gnu_size, align)); Set_Esize (gnat_entity, annotate_value (gnu_size)); /* Tagged types are Strict_Alignment so RM_Size = Esize. */ @@ -8723,6 +8725,19 @@ build_variant_list (tree qual_union_type, vec subst_list, return gnu_list; } +/* If SIZE has overflowed, return the maximum valid size, which is the upper + bound of the signed sizetype in bits; otherwise return SIZE unmodified. */ + +static tree +maybe_saturate_size (tree size) +{ + 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)); + return size; +} + /* UINT_SIZE is a Uint giving the specified size for an object of GNU_TYPE corresponding to GNAT_OBJECT. If the size is valid, return an INTEGER_CST corresponding to its value. Otherwise, return NULL_TREE. KIND is set to @@ -10137,7 +10152,7 @@ concat_name (tree gnu_name, const char *suffix) return get_identifier_with_length (new_name, len); } -/* Initialize data structures of the decl.c module. */ +/* Initialize the data structures of the decl.c module. */ void init_gnat_decl (void) @@ -10149,7 +10164,7 @@ init_gnat_decl (void) dummy_to_subprog_map = hash_table::create_ggc (512); } -/* Destroy data structures of the decl.c module. */ +/* Destroy the data structures of the decl.c module. */ void destroy_gnat_decl (void) diff --git a/gcc/ada/gcc-interface/trans.c b/gcc/ada/gcc-interface/trans.c index 4d2fa93ffce..fe02dc4d64f 100644 --- a/gcc/ada/gcc-interface/trans.c +++ b/gcc/ada/gcc-interface/trans.c @@ -8790,7 +8790,7 @@ gnat_to_gnu (Node_Id gnat_node) 5. If this is a reference to an unconstrained array which is used as the prefix of an attribute reference that requires an lvalue, return the - result unmodified because we want return the original bounds. + result unmodified because we want to return the original bounds. 6. Finally, if the type of the result is already correct. */