https://gcc.gnu.org/g:1698af5364d3e789492c439e1b825f6da8608ec8
commit r17-1215-g1698af5364d3e789492c439e1b825f6da8608ec8 Author: Eric Botcazou <[email protected]> Date: Mon Apr 6 13:00:50 2026 +0200 ada: Add warning for too large return object in extended return statement 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. Diff: --- 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 cf6c37f1ca23..50a065d2dea6 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 3604d4df761c..9de47a70240c 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,
