[Ada] Saturate the sizes for the target in -gnatR output

Message ID 1849424.VE4vyoWEjc@arcturus.home
State New
Headers show
  • [Ada] Saturate the sizes for the target in -gnatR output
Related show

Commit Message

Eric Botcazou Aug. 30, 2019, 3:33 p.m.
This changes the saturation from the host to the target for the large sizes 
displayed in the the -gnatR output.

Tested on x86_64-suse-linux, applied on the mainline.

2019-08-30  Eric Botcazou  <ebotcazou@adacore.com>

	* 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.

Eric Botcazou


Index: gcc-interface/decl.c
--- gcc-interface/decl.c	(revision 275198)
+++ gcc-interface/decl.c	(working copy)
@@ -232,6 +232,7 @@  static tree build_position_list (tree, bool, tree,
 static vec<subst_pair> build_subst_list (Entity_Id, Entity_Id, bool);
 static vec<variant_desc> build_variant_list (tree, vec<subst_pair>,
+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 gn
 	  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 gn
 		  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<subs
   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.  */
 init_gnat_decl (void)
@@ -10149,7 +10164,7 @@  init_gnat_decl (void)
   dummy_to_subprog_map = hash_table<dummy_type_hasher>::create_ggc (512);
-/* Destroy data structures of the decl.c module.  */
+/* Destroy the data structures of the decl.c module.  */
 destroy_gnat_decl (void)
Index: gcc-interface/trans.c
--- gcc-interface/trans.c	(revision 275198)
+++ gcc-interface/trans.c	(working copy)
@@ -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.  */