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] Memory leak on function returning a limited view result


This patch modifies the processing of subprograms to properly frag a function
as returning by reference when the return type is a limited view and the full
view of the type requires the secondary stack.

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

--  pack_1.ads

with Pack_2;

with Ada.Finalization; use Ada.Finalization;

package Pack_1 is
   type Priv_Typ is tagged private;
   Empty : constant Priv_Typ;

private
   type Priv_Typ is new Controlled with null record;
   Empty : constant Priv_Typ := (Controlled with null record);
end Pack_1;

--  pack_2.ads

limited with Pack_1;

package Pack_2 is
   function Leak return Pack_1.Priv_Typ;
end Pack_2;

--  pack_2.adb

with Pack_1;

package body Pack_2 is
   function Leak return Pack_1.Priv_Typ is
   begin
      return Pack_1.Empty;
   end Leak;
end Pack_2;

--  pack_main.adb

with Pack_1;
with Pack_2;

procedure Pack_Main is
   Obj : Pack_1.Priv_Typ;

begin
   Obj := Pack_2.Leak;
end Pack_Main;

-----------------
-- Compilation --
-----------------

$ gnatmake -q pack_main.adb -largs -lgmem
$ ./pack_main
$ [ -f gmem.out ] && echo ERROR

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

2017-01-19  Hristian Kirtchev  <kirtchev@adacore.com>

	* exp_ch6.adb (Expand_N_Subprogram_Body): Mark the spec as
	returning by reference not just for subprogram body stubs,
	but for all subprogram cases.
	* sem_util.adb: Code reformatting.
	(Requires_Transient_Scope): Update the call to Results_Differ.
	(Results_Differ): Update the parameter profile and the associated
	comment on usage.

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]