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] Handling of object declarations with aggregates and specified alignment.


When an object declaration for an array object includes an aggregate
expression and the aspect Alignment is specified for the object, the object
must be initialized with an explicit assignment at the point the object is
frozen. Such special processing was developed for address clauses, but it
must apply to other aspects that may affect object layout, and that have to
be delayed in Ada 2012 because they may contain forward references.

The following must compile quietly:

with A;
procedure Main is

   type Rec is
      record
         C: Duration;
      end record;

   package TestA_Pkg is new A (Rec);

   package TestB_Pkg is new TestA_Pkg.B;

   D: aliased Rec := (C => 1.0);

begin
   TestB_Pkg.P (D'Access);
end Main;
---
generic
   type T is private;
package A is
   generic
   package B is

      procedure P (Item: access T);

   end B;
end A;
---
package body A is
   package body B is
         subtype Buff_Type is String (1 .. T'Size);

      procedure P (Item: access T) is
         Buff  : Buff_Type
             := (others => ' ')
          with Alignment => Standard'Maximum_Alignment;
         
         Item2 : aliased T with Alignment => 8, Address => Buff'Address;
         Align : constant := Standard'Maximum_alignment;
         Temp  : T;
      begin
         Temp := Item2'Access.all;
      end P;
   end B;
end A;

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

2015-05-12  Ed Schonberg  <schonberg@adacore.com>

	* sem_ch3.adb (Analyze_Object_Declaration): New function
	Has_Delayed_Aspect, used to defer resolution of an aggregate
	expression when the object declaration carries aspects Address
	and/or Alignment.
	* freeze.adb (Freeze_Object_Declaration): New subsidiary procedure
	to Freeze_Entity.  In addition to the previous processing steps
	at the freeze point of an object, this procedure also handles
	aggregates in object declarations, when the declaration carries
	delayed aspects that require that the initialization of the
	object be attached to its freeze actions.

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]