[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.
From-SVN: r262774