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] Specifying Address clause on controlled objects


This patch removes the restriction on attribute definition clause 'Address
which prevented it from being used with controlled objects. The restriction
was a legacy left over from the previous controlled type implementation where
each controlled type had hidden components that should not be overlayed.

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

--  types.ads

with Ada.Finalization; use Ada.Finalization;

package Types is
   type Ctrl is new Controlled with record
      Comp_1 : Integer;
   end record;

   type Rec is record
      Comp_1 : Ctrl;
      Comp_2 : Integer;
   end record;

   type Tag_Typ is tagged record
      Comp_1 : Integer;
      Comp_2 : Integer;
      Comp_3 : Integer;
   end record;
end Types;

--  main.adb

with Ada.Text_IO;             use Ada.Text_IO;
with System;                  use System;
with System.Storage_Elements; use System.Storage_Elements;
with Types;                   use Types;

procedure Main is
   Obj_1      : constant Integer := 1;
   Obj_1_Addr : constant Address := Obj_1'Address;

   --  The objects are declared in one order, but their address clauses order
   --  them in reverse declarative order.

   Obj_4_Addr : constant Address := Obj_1_Addr + Integer'Size;
   Obj_3_Addr : constant Address := Obj_4_Addr + Tag_Typ'Size;
   Obj_2_Addr : constant Address := Obj_3_Addr + Ctrl'Size;

   Obj_2 : Ctrl;
   for Obj_2'Address use Obj_2_Addr;

   Obj_3 : Rec;
   for Obj_3'Address use Obj_3_Addr;

   Obj_4 : Tag_Typ;
   for Obj_4'Address use Obj_4_Addr;

begin
   if Obj_2'Address /= Obj_2_Addr then
      Put_Line ("ERROR: Obj_2 is in the wrong place");
   end if;

   if Obj_3'Address /= Obj_3_Addr then
      Put_Line ("ERROR: Obj_3 is in the wrong place");
   end if;

   if Obj_4'Address /= Obj_4_Addr then
      Put_Line ("ERROR: Obj_4 is in the wrong place");
   end if;
end Main;

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

$ gnatmake -q -gnatws main.adb
$ ./main

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

2017-04-25  Hristian Kirtchev  <kirtchev@adacore.com>

	* sem_ch13.adb (Analyze_Attribute_Definition_Clause): Remove the
	restriction converning the use of 'Address where the prefix is
	of a controlled 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]