]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Sort cross-reference table using heap and not stack
authorPiotr Trojanek <trojanek@adacore.com>
Wed, 5 Nov 2025 19:14:33 +0000 (20:14 +0100)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Fri, 21 Nov 2025 08:29:37 +0000 (09:29 +0100)
Cross-references are used by GNATprove for code that is not in SPARK. They are
sorted using an auxiliary array. This array should be allocated on the heap and
not on stack, because it can be arbitrarily large, especially for
auto-generated code.

gcc/ada/ChangeLog:

* lib-xref.adb (Output_References): Put local array object on the heap.

gcc/ada/lib-xref.adb

index aa9ae57f60eb08c2ec25104c57d2ee8938e2ffad..d7dc7178daab35e1b392b1176997c87bf4a911f8 100644 (file)
@@ -23,6 +23,7 @@
 --                                                                          --
 ------------------------------------------------------------------------------
 
+with Ada.Unchecked_Deallocation;
 with Atree;          use Atree;
 with Csets;          use Csets;
 with Einfo;          use Einfo;
@@ -1827,7 +1828,16 @@ package body Lib.Xref is
          Nrefs : constant Nat := Xrefs.Last;
          --  Number of references in table
 
-         Rnums : array (0 .. Nrefs) of Nat;
+         type Refs_Numbers is array (0 .. Nrefs) of Nat;
+         type Refs_Numbers_Ptr is access Refs_Numbers;
+         --  Since the number of references can be large, we need to allocate
+         --  the sorting array on the heap.
+
+         procedure Free is
+           new Ada.Unchecked_Deallocation (Refs_Numbers, Refs_Numbers_Ptr);
+         --  Release memory allocated for the sorting array
+
+         Rnums : Refs_Numbers_Ptr := new Refs_Numbers;
          --  This array contains numbers of references in the Xrefs table.
          --  This list is sorted in output order. The extra 0'th entry is
          --  convenient for the call to sort. When we sort the table, we
@@ -2709,6 +2719,8 @@ package body Lib.Xref is
             null;
          end loop;
 
+         Free (Rnums);
+
          Write_Info_EOL;
       end Output_Refs;
    end Output_References;