This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Secondary stack leak for call returning limited discriminated object


This change fixes a defect whereby GNAT would fail to generate secondary
stack cleanup code for a scope containing a local object of a limited
discriminated type initialized by a (build-in-place) function call,
thus causing a storage leak.

The following test case must not leak memory for each iteration of the loop:

package Limited_Factory is
   type Lim (D : Integer) is limited private;
   function Create_In_Place return Lim;
private
   type Lim (D : Integer) is limited record
      S : String (1 .. 1024);
   end record;
end Limited_Factory;
package body Limited_Factory is
   function Create_In_Place return Lim is
   begin
      return Lim'(D => 42, S => (others => 'x'));
   end;
end Limited_Factory;
with Limited_Factory; use Limited_Factory;
procedure Sec_Stack_BIP is
   procedure Leak is
      Obj : Lim := Create_In_Place;
   begin
      null;
   end;
begin
   for J in 1 .. 1000 loop
      Leak;
   end loop;
end;

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

2014-07-17  Thomas Quinot  <quinot@adacore.com>

	* exp_ch7.adb (Establish_Transient_Scope.Find_Node_To_Be_Wrapped):
	Start examining the tree at the node passed to
	Establish_Transient_Scope (not its parent).
	* exp_ch6.adb (Make_Build_In_Place_Call_In_Object_Declaration):
	The access type for the variable storing the reference to
	the call must be declared and frozen prior to establishing a
	transient scope.

Attachment: difs
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]