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] Interplay between exception handlers and finalization


This patch corrects the machinery which detects controlled objects inside a
block created for the purposes of avoiding interference of exception handlers
and At_End handlers.

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

--  types.ads

with Ada.Finalization; use Ada.Finalization;

package Types is
   type Ctrl is new Controlled with null record;
   procedure Finalize (Obj : in out Ctrl);
   function Make_Ctrl return Ctrl;

   type Rec is record
      Data : Ctrl;
   end record;
   function Make_Rec return Rec;
end Types;

--  types.adb:

with Ada.Text_IO; use Ada.Text_IO;

package body Types is
   procedure Finalize (Obj : in out Ctrl) is
   begin
      Put_Line ("Finalize");
   end Finalize;

   function Make_Ctrl return Ctrl is
      Result : Ctrl;
   begin
      return Result;
   end Make_Ctrl;

   function Make_Rec return Rec is
   begin
      return Rec'(Data => Make_Ctrl);
   exception
      when others =>
         Put_Line ("BOMB");
         raise Program_Error;
   end Make_Rec;
end Types;

--  main.adb:

with Ada.Text_IO; use Ada.Text_IO;
with Types;       use Types;

procedure Main is
begin
   Put_Line ("Main");
   declare
      Obj : Rec := Make_Rec;
   begin
      null;
   end;
   Put_Line ("End");
end Main;

----------------------------
-- Compilation and output --
----------------------------

$ gnatmake -q main.adb
$ ./main
$ Main
$ Finalize
$ Finalize
$ Finalize
$ Finalize
$ Finalize
$ End

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

2012-06-12  Hristian Kirtchev  <kirtchev@adacore.com>

	* exp_ch7.adb (Process_Declarations): Handle the case where
	the original context has been wrapped in a block to avoid
	interference between exception handlers and At_End handlers.
	(Wrap_HSS_In_Block): Mark the block which contains the original
	statements of the context as being a finalization wrapper.
	* sinfo.adb (Is_Finalization_Wrapper): New routine.
	(Set_Is_Finalization_Wrapper): New routine.

	* sinfo.ads: Add new attribute Is_Finalization_Wrapper applicable
	to block statemnts.
	(Is_Finalization_Wrapper): New routine with corresponding pragma Inline.
	(Set_Is_Finalization_Wrapper): New routine with corresponding pragma
	Inline.

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]