r262774 - in /trunk/gcc/ada: ChangeLog sem_ch5.adb

pmderodat@gcc.gnu.org pmderodat@gcc.gnu.org
Tue Jul 17 08:06:00 GMT 2018


Author: pmderodat
Date: Tue Jul 17 08:06:09 2018
New Revision: 262774

URL: https://gcc.gnu.org/viewcvs?rev=262774&root=gcc&view=rev
Log:
[Ada] Secondary stack leak in loop iterator

When the evaluation of the loop iterator invokes a function whose
result relies on the secondary stack the compiler does not generate
code to release the consumed memory as soon as the loop terminates.

After this patch the following test works fine.

with Text_IO; use Text_IO;
pragma Warnings (Off);
with System.Secondary_Stack;
pragma Warnings (On);
procedure Sec_Stack_Leak is
   function F (X : String) return Integer is
   begin
      return 10;
   end F;

   function G (X : Integer) return String is
   begin
      return (1 .. X => 'x');
   end G;

   procedure Info is new System.Secondary_Stack.Ss_Info (Put_Line);

   procedure Nest is
   begin
      for I in Integer range 1 .. 100 loop
         for J in Integer range 1 .. F (G (10_000)) loop
            null;
         end loop;
         Info;
      end loop;
      Info;
   end Nest;

begin
   Info;
   Nest;
   Info;
end Sec_Stack_Leak;

Commands:
  gnatmake -q sec_stack_leak.adb
  sec_stack_leak | grep "Current allocated space :" | uniq
Output:
  Current allocated space :  0 bytes

2018-07-17  Javier Miranda  <miranda@adacore.com>

gcc/ada/

	* sem_ch5.adb (Has_Call_Using_Secondary_Stack): Moved to library level
	to reuse it.
	(Analyze_Loop_Statement): Wrap the loop in a block when the evaluation
	of the loop iterator relies on the secondary stack.

Modified:
    trunk/gcc/ada/ChangeLog
    trunk/gcc/ada/sem_ch5.adb



More information about the Gcc-cvs mailing list