This is the mail archive of the 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] Finalization of controlled object in instance

This patch corrects the mechanism which determines whether a construct appears
at the library level. This in turn allows for proper detection of cases where
a Finalize_Storage_Only object appears in a nested scope and requires

-- Source --

--  main.adb

with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;

procedure Main is
   package Memory_File is
      File     : Unbounded_String;
      procedure Add_String (S : String);
      procedure Add_New_Line;
   end Memory_File;

   package body Memory_File is
      procedure Add_String (S : String) is
         Append (File, S);
      end Add_String;
      procedure Add_New_Line is
         Add_String (ASCII.CR & ASCII.LF);
      end Add_New_Line;
   end Memory_File;

   function Leak return String is
      package Mem is new Memory_File;
      use Mem;
      Add_String ("This is a test");
      return To_String (File);
   end Leak;

   for Index in 1 .. 100 loop
         Result : String := Leak;
         pragma Warnings (Off, Result);
   end loop;
end Main;

-- Compilation and output --

$ gnatmake -q main.adb -largs -lgmem
$ ./main
$ gnatmem ./main
$ Global information
$ ------------------
$    Total number of allocations        : 100
$    Total number of deallocations      : 100
$    Final Water Mark (non freed mem)   :   0 Bytes
$    High Water Mark                    :  48 Bytes

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

2012-04-26  Hristian Kirtchev  <>

	* exp_ch7.adb (Expand_Cleanup_Actions): Update the call to
	* exp_util.adb (Requires_Cleanup_Actions (List_Id; Boolean;
	Boolean)): Rename formal parameter For_Package to Lib_Level to
	better reflect its purpose. Update the related comment and all
	occurrences of For_Package in the body.
	(Node_Id; Boolean)): Add new formal parameter Lib_Level. Add
	local constant At_Lib_Level to keep monitor whether the path
	taken from the top-most context to the current construct involves
	package constructs. Update all calls to Requires_Cleanup_Actions.
	* (Requires_Cleanup_Actions): Add new formal
	parameter Lib_Level and associated comment.

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]