summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPiotr Trojanek <trojanek@adacore.com>2025-11-05 20:14:33 +0100
committerMarc Poulhiès <dkm@gcc.gnu.org>2025-11-21 09:29:37 +0100
commit57d3933a8705bcea91d8a7189d7d5d5edce14524 (patch)
tree7bb8d161ffb3f9520ba959d29fd1f86c1a3dae6d
parentc9aeb782c7899c616ed122a68119b12c04e3c82c (diff)
ada: Sort cross-reference table using heap and not stack
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.
-rw-r--r--gcc/ada/lib-xref.adb14
1 files changed, 13 insertions, 1 deletions
diff --git a/gcc/ada/lib-xref.adb b/gcc/ada/lib-xref.adb
index aa9ae57f60e..d7dc7178daa 100644
--- a/gcc/ada/lib-xref.adb
+++ b/gcc/ada/lib-xref.adb
@@ -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;