From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1285) id 3773F3858C60; Thu, 16 Nov 2023 17:39:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3773F3858C60 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1700156380; bh=3K3VbsFwZSf6PNUCN3iZDJH5zZOm5NuVztvPaumQlds=; h=From:To:Subject:Date:From; b=nV/GSf/4MLusIpDAJUWxU5Y+ECeBQB2N1L7eqBkaSuJNApNFXNA/0BP4Gg1XjlD6E XJRljDNNDFk58BGiy8Jr5Zc4V1aUrGHTCwtozT/AUQzH1k2gm1evg7r1TPyl7AX75d JdBTMkz/+MwJPNbg0QPLATNwXZVcOQhMauTGBj5E= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Eric Botcazou To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-8075] Fix internal error on function returning dynamically-sized type X-Act-Checkin: gcc X-Git-Author: Eric Botcazou X-Git-Refname: refs/heads/releases/gcc-13 X-Git-Oldrev: 2728e2a69a202bd18fc3849e9b73c15b3534aa34 X-Git-Newrev: c5e1cb7e501350ea339db44ca5a33704d817a6fb Message-Id: <20231116173940.3773F3858C60@sourceware.org> Date: Thu, 16 Nov 2023 17:39:40 +0000 (GMT) List-Id: https://gcc.gnu.org/g:c5e1cb7e501350ea339db44ca5a33704d817a6fb commit r13-8075-gc5e1cb7e501350ea339db44ca5a33704d817a6fb Author: Eric Botcazou Date: Thu Nov 16 18:36:44 2023 +0100 Fix internal error on function returning dynamically-sized type This is a tree sharing issue for the internal return type synthesized for a function returning a dynamically-sized type and taking an Out or In/Out parameter passed by copy. gcc/ada/ * gcc-interface/decl.cc (gnat_to_gnu_subprog_type): Also create a TYPE_DECL for the return type built for the CI/CO mechanism. gcc/testsuite/ * gnat.dg/varsize4.ads, gnat.dg/varsize4.adb: New test. * gnat.dg/varsize4_pkg.ads: New helper. Diff: --- gcc/ada/gcc-interface/decl.cc | 6 ++++++ gcc/testsuite/gnat.dg/varsize4.adb | 19 +++++++++++++++++++ gcc/testsuite/gnat.dg/varsize4.ads | 9 +++++++++ gcc/testsuite/gnat.dg/varsize4_pkg.ads | 5 +++++ 4 files changed, 39 insertions(+) diff --git a/gcc/ada/gcc-interface/decl.cc b/gcc/ada/gcc-interface/decl.cc index 00cb3a6cf3b..1c5dd646186 100644 --- a/gcc/ada/gcc-interface/decl.cc +++ b/gcc/ada/gcc-interface/decl.cc @@ -6285,6 +6285,12 @@ gnat_to_gnu_subprog_type (Entity_Id gnat_subprog, bool definition, if (debug_info_p) rest_of_record_type_compilation (gnu_cico_return_type); + + /* Declare it now since it will never be declared otherwise. This + is necessary to ensure that its subtrees are properly marked. */ + create_type_decl (TYPE_NAME (gnu_cico_return_type), + gnu_cico_return_type, + true, debug_info_p, gnat_subprog); } gnu_return_type = gnu_cico_return_type; diff --git a/gcc/testsuite/gnat.dg/varsize4.adb b/gcc/testsuite/gnat.dg/varsize4.adb new file mode 100644 index 00000000000..3d0430de5aa --- /dev/null +++ b/gcc/testsuite/gnat.dg/varsize4.adb @@ -0,0 +1,19 @@ +-- { dg-do compile } + +package body Varsize4 is + + function Func (bytes_read : out Natural) return Arr is + Ret : Arr := (others => False); + begin + return Ret; + end; + + function Get return Natural is + Data : Arr; + Bytes : Natural; + begin + Data := Func (Bytes); + return Bytes; + end; + +end Varsize4; diff --git a/gcc/testsuite/gnat.dg/varsize4.ads b/gcc/testsuite/gnat.dg/varsize4.ads new file mode 100644 index 00000000000..62b673fc16b --- /dev/null +++ b/gcc/testsuite/gnat.dg/varsize4.ads @@ -0,0 +1,9 @@ +with Varsize4_Pkg; + +package Varsize4 is + + type Arr is array (1 .. Varsize4_Pkg.F) of Boolean; + + function Get return Natural; + +end Varsize4; diff --git a/gcc/testsuite/gnat.dg/varsize4_pkg.ads b/gcc/testsuite/gnat.dg/varsize4_pkg.ads new file mode 100644 index 00000000000..e07a6b002dc --- /dev/null +++ b/gcc/testsuite/gnat.dg/varsize4_pkg.ads @@ -0,0 +1,5 @@ +package Varsize4_Pkg is + + function F return Natural; + +end Varsize4_Pkg;