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] | |
Tested on i686-linux, committed on trunk
In Ada2005, when an actual for an access parameter is a controlled object, we
create a local block around the call to finalize the object after return. The
expansion of the allocator produces a declaration for a temporary, expansion
of the aggregate into component assignments to the temporary, and attachment
statements that place the object on the finalization list of the transient
block. Code for all of these must be placed in the tree using Insert_Actions
rather than a mixture of Insert_Actions and Insert_Actions_After, because in
the presence of a transient block Insert_Actions_After will produce out-of-
order references.
gnat.dg/controlled4.adb must compile quietly.
--
Finally, add finalization support for dynamic objects allocated through
anonymous access types.
Source:
with Ada.Finalization; use Ada.Finalization;
with Ada.Text_IO; use Ada.Text_IO;
procedure Test1 is
type Rec is new Controlled with record
Id : Integer;
end record;
procedure Finalize (Obj : in out Rec);
procedure Initialize (Obj : in out Rec);
procedure Finalize (Obj : in out Rec) is
begin
Put_Line ("Finalize");
end Finalize;
procedure Initialize (Obj : in out Rec) is
begin
Put_Line ("Initialize");
end Initialize;
procedure P;
procedure P is
Obj_Ptr : access Rec;
begin
Obj_Ptr := new Rec'(Controlled with 1);
end P;
begin
P;
end Test1;
Compilation:
gnatmake -q test1.adb
Output:
Finalize
2007-08-14 Ed Schonberg <schonberg@adacore.com>
Gary Dismukes <dismukes@adacore.com>
* exp_aggr.ads,
exp_aggr.adb (Convert_Aggr_In_Allocator): Use Insert_Actions to place
expanded aggregate code before allocator, and ahead of declaration for
temporary, to prevent access before elaboration when the allocator is
an actual for an access parameter.
(Is_Static_Dispatch_Table_Aggregate): Handle aggregates initializing
the TSD and the table of interfaces.
(Convert_To_Assignments): Augment the test for delaying aggregate
expansion for limited return statements to include the case of extended
returns, to prevent creation of an unwanted transient scope.
(Is_Static_Dispatch_Table_Aggregate): New subprogram.
(Expand_Array_Aggregate): Handle aggregates associated with
statically allocated dispatch tables.
(Expand_Record_Aggregate): Handle aggregates associated with
statically allocated dispatch tables.
(Gen_Ctrl_Actions_For_Aggr): Generate a finalization list for allocators
of anonymous access type.
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] |