public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Fix internal error on function returning dynamically-sized type
@ 2023-11-16 17:36 Eric Botcazou
  0 siblings, 0 replies; only message in thread
From: Eric Botcazou @ 2023-11-16 17:36 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 625 bytes --]

This is PR ada/109881, 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.

Tested on x86-64/Linux, applied on mainline, 13 and 12 branches.


2023-11-16  Eric Botcazou  <ebotcazou@adacore.com>

	PR ada/109881
	* gcc-interface/decl.cc (gnat_to_gnu_subprog_type): Also create a
	TYPE_DECL for the return type built for the CI/CO mechanism.


2023-11-16  Eric Botcazou  <ebotcazou@adacore.com>

	* gnat.dg/varsize4.ads, gnat.dg/varsize4.adb: New test.
	* gnat.dg/varsize4_pkg.ads: New helper.

-- 
Eric Botcazou

[-- Attachment #2: p.diff --]
[-- Type: text/x-patch, Size: 689 bytes --]

diff --git a/gcc/ada/gcc-interface/decl.cc b/gcc/ada/gcc-interface/decl.cc
index 95fa508c559..9c7f6840e21 100644
--- a/gcc/ada/gcc-interface/decl.cc
+++ b/gcc/ada/gcc-interface/decl.cc
@@ -6329,6 +6329,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;

[-- Attachment #3: varsize4.adb --]
[-- Type: text/x-adasrc, Size: 336 bytes --]

-- { 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;

[-- Attachment #4: varsize4.ads --]
[-- Type: text/x-adasrc, Size: 144 bytes --]

with Varsize4_Pkg;

package Varsize4 is

   type Arr is array (1 .. Varsize4_Pkg.F) of Boolean;

   function Get return Natural;

end Varsize4;

[-- Attachment #5: varsize4_pkg.ads --]
[-- Type: text/x-adasrc, Size: 74 bytes --]

package Varsize4_Pkg is

   function F return Natural;

end Varsize4_Pkg;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-11-16 17:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-16 17:36 [Ada] Fix internal error on function returning dynamically-sized type Eric Botcazou

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).