]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix internal error on function returning dynamically-sized type
authorEric Botcazou <ebotcazou@adacore.com>
Thu, 16 Nov 2023 17:36:44 +0000 (18:36 +0100)
committerEric Botcazou <ebotcazou@adacore.com>
Thu, 16 Nov 2023 17:38:23 +0000 (18:38 +0100)
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.

gcc/ada/gcc-interface/decl.cc
gcc/testsuite/gnat.dg/varsize4.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/varsize4.ads [new file with mode: 0644]
gcc/testsuite/gnat.dg/varsize4_pkg.ads [new file with mode: 0644]

index 95fa508c55986b1d8387b2d71f6710cc831d06fd..9c7f6840e2104abbabdeeea5b0261dd87fd5a5b6 100644 (file)
@@ -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;
diff --git a/gcc/testsuite/gnat.dg/varsize4.adb b/gcc/testsuite/gnat.dg/varsize4.adb
new file mode 100644 (file)
index 0000000..3d0430d
--- /dev/null
@@ -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 (file)
index 0000000..62b673f
--- /dev/null
@@ -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 (file)
index 0000000..e07a6b0
--- /dev/null
@@ -0,0 +1,5 @@
+package Varsize4_Pkg is
+
+   function F return Natural;
+
+end Varsize4_Pkg;