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] Static aggregates of a limited type


This patch optimizes the handling of aggregates with static components, and
allows more complex nested aggregates to be handled by the backend without any
elaboration code. This applies in particular to aggregates of a limited type,
which previously were always expanded into assignments.

The following must compile quietly:

---
pragma Restrictions (No_Elaboration_Code);
package Elab is
   pragma Preelaborate;

   procedure Test;
   function Probe (X : Integer) return Boolean;
end Elab;
---
pragma Restrictions (No_Elaboration_Code);
with Fair_Locks;

package body Elab is

   use Fair_Locks;

   Lock : Fair_Lock := (Spinning => (others => False));

   Complex : Tagged_Lock := (Contents => (others => False));

   procedure Test is
   begin
      if not Lock.Spinning (3) then
         Lock.Spinning (2) := True;
      end if;
   end Test;

   function Probe (X : Integer) return Boolean is
   begin
      return Lock.Spinning (X);
   end Probe;
end Elab;
---
package Fair_Locks is
   pragma Preelaborate;

   type Spinning_Array is array (1 .. 16) of Boolean;

   type Fair_Lock is limited record
      Spinning : Spinning_Array := (others => False);
   end record;

   type Tagged_Lock is tagged limited record
      Contents : Spinning_Array := (others => False);
   end record;

end Fair_Locks;

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

2010-10-08  Ed Schonberg  <schonberg@adacore.com>

	* sem_aggr.adb (Resolve_Array_Aggregate): If the expression in an
	others choice is a literal analyze it now to enable later optimizations.
	* exp_aggr.adb (Expand_Record_Aggregate): An aggregate with static size
	and components can be handled by the backend even if it is of a limited
	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]