[Ada] Secondary stack leak with access-to-subprogram

Pierre-Marie de Rodat derodat@adacore.com
Tue Jul 31 09:57:00 GMT 2018


This patch modifies call resolution to recognize when the designated type of
an access-to-subprogram requires secondary stack management, and establish
the proper transient block.

------------
-- Source --
------------

--  leak7.adb

procedure Leak7 is
   Max_Iterations : constant := 10_000;

   function Func return String is
   begin
      return "Will this leak? Or will it dry?";
   end Func;

   type Func_Ptr is access function return String;

   procedure Anonymous_Leak (Func : access function return String) is
   begin
      for Iteration in 1 .. Max_Iterations loop
         declare
            Val : constant String := Func.all;
         begin null; end;
      end loop;
   end Anonymous_Leak;

   procedure Named_Leak (Func : Func_Ptr) is
   begin
      for Iteration in 1 .. Max_Iterations loop
         declare
            Val : constant String := Func.all;
         begin null; end;
      end loop;
   end Named_Leak;

begin
   Anonymous_Leak (Func'Access);
   Named_Leak     (Func'Access);
end Leak7;

----------------------------
-- Compilation and output --
----------------------------

$ gnatmake -q leak7.adb
$ valgrind ./leak7 >& leak7.txt
$ grep -c "still reachable" leak7.txt
0

Tested on x86_64-pc-linux-gnu, committed on trunk

2018-07-31  Hristian Kirtchev  <kirtchev@adacore.com>

gcc/ada/

	* sem_res.adb (Resolve_Call): Establish a transient scope to
	manage the secondary stack when the designated type of an
	access-to-subprogram requires it.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.diff
Type: text/x-diff
Size: 385 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20180731/6c433ac0/attachment.bin>


More information about the Gcc-patches mailing list