From: Eric Botcazou <[email protected]>

The return object may be allocated directly on the return or secondary stack
by the front-end, in other words be the renaming of an allocator.

gcc/ada/ChangeLog:

        * gcc-interface/decl.cc (gnat_to_gnu_entity) <E_Variable>: Do not
        give the warning about too large a size here but...
        * gcc-interface/utils2.cc (build_allocator): ...here instead.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/gcc-interface/decl.cc   | 6 ------
 gcc/ada/gcc-interface/utils2.cc | 5 ++++-
 2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/gcc/ada/gcc-interface/decl.cc b/gcc/ada/gcc-interface/decl.cc
index cf6c37f1ca2..50a065d2dea 100644
--- a/gcc/ada/gcc-interface/decl.cc
+++ b/gcc/ada/gcc-interface/decl.cc
@@ -1489,12 +1489,6 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree 
gnu_expr, bool definition)
                             false);
                  }
 
-               /* Give a warning if the size is constant but too large.  */
-               if (TREE_CODE (TYPE_SIZE_UNIT (gnu_alloc_type)) == INTEGER_CST
-                   && !valid_constant_size_p (TYPE_SIZE_UNIT (gnu_alloc_type)))
-                 post_error ("??Storage_Error will be raised at run time!",
-                             gnat_entity);
-
                gnu_expr
                  = build_allocator (gnu_alloc_type, gnu_expr, gnu_type,
                                     Empty, Empty, gnat_entity, mutable_p);
diff --git a/gcc/ada/gcc-interface/utils2.cc b/gcc/ada/gcc-interface/utils2.cc
index 3604d4df761..9de47a70240 100644
--- a/gcc/ada/gcc-interface/utils2.cc
+++ b/gcc/ada/gcc-interface/utils2.cc
@@ -2731,7 +2731,10 @@ build_allocator (tree type, tree init, tree result_type, 
Entity_Id gnat_proc,
 
   /* If the size overflows, pass -1 so Storage_Error will be raised.  */
   if (TREE_CODE (size) == INTEGER_CST && !valid_constant_size_p (size))
-    size = size_int (-1);
+    {
+      post_error ("??Storage_Error will be raised at run time!", gnat_node);
+      size = size_int (-1);
+    }
 
   storage = convert (result_type,
                     build_call_alloc_dealloc (NULL_TREE, size, type,
-- 
2.53.0

Reply via email to