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] Intermediate build-in-place result not finalized


This patch ensures that intermediate results of limited controlled function
calls are finalized after their respective master is left. Example:

with Ada.Finalization; use Ada.Finalization;
with Ada.Text_IO;      use Ada.Text_IO;

procedure Test1 is
   type Lim_Rec is new Limited_Controlled with record
      Component : Natural := 123;
   end record;

   procedure Finalize (Obj : in out Lim_Rec) is
   begin
      Put_Line ("Component =" & Obj.Component'Img);
   end Finalize;

   function New_Lim_Rec return Lim_Rec is
   begin
      return Result : Lim_Rec do
         Result.Component := 456;
      end return;
   end New_Lim_Rec;

   Value : Natural;

begin
   Put_Line ("Before master");
   Value := New_Lim_Rec.Component;
   Put_Line ("After master");

end Test1;

Compilation and execution:

gnatmake -gnat05 test1.adb
./test1.adb
Before master
Component = 456
After master

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

2010-09-10  Hristian Kirtchev  <kirtchev@adacore.com>

	* exp_ch7.adb, exp_ch6.adb (Expand_Call): Establish a transient scope
	for a controlled build-in-place function call which appears in an
	anonymous context. The transient scope ensures that the intermediate
	function result is cleaned up after the master is left.
	(Make_Build_In_Place_Call_In_Anonymous_Context): Remove the creation
	of the transient scope. This is now done in Exand_Call which covers
	additional cases other than secondary stack release.

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]