[Ada] Secondary stack leak in statements block located in a loop
When a loop iterator has a block declaration containing statements that invoke
functions whose result is returned on the secondary stack (such as a
string-returning function), the compiler fails to generate code to release the
allocated memory when the loop terminates.
After this patch the following test works fine.
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
pragma Warnings (Off);
with System.Secondary_Stack;
pragma Warnings (On);
procedure Small is
procedure Info is new System.Secondary_Stack.Ss_Info (Put_Line);
US : Unbounded_String;
begin
Info;
for J in 1 .. 100_000 loop
Leaky_Block : declare
begin
if (J mod 20000) = 0 then
Info;
end if;
Ada.Text_IO.Put_Line (To_String (US)); -- Test
if (J mod 20000) = 0 then
Info;
end if;
end Leaky_Block;
end loop;
Info;
end;
Command:
gnatmake small.adb; small | grep "Current allocated space :" | uniq
Output:
Current allocated space : 0 bytes
2018-07-17 Javier Miranda <miranda@adacore.com>
gcc/ada/
* exp_ch7.adb (Make_Transient_Block): When determining whether an
enclosing scope already handles the secondary stack, take into account
transient blocks nested in a block that do not manage the secondary
stack and are located within a loop.
From-SVN: r262779