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] fix bug in handling of aggregates


Tested under i686-linux, commited on mainline.

Given the following declarations:

  type Index_Type is range 0 .. 4;
  type Unconstrained_Array_Type is array (Index_Type range <>) of Integer;
  subtype Array_Type is Unconstrained_Array_Type (2..4);

  Target : array (1 .. 1) of Array_Type;

The following assignment is legal:

  Target := (1 => (1 => 20, 2 => 30, 3 => 40));

and is equivalent to:
  Target (1) := (1 => 20, 2=> 30, 3=> 40);

Which requires the array on the RHS to be assigned first to a temporary,
and then that temporary to be assigned to Target (1).  This ensures that
indices 2..4 of Target (1) receive values. Previously GNAT decomposed this
into individual assignments to Target (1)(1), etc. improperly retaining
the values of the indices in the component associations of the aggregate.

Test case, must compile and execute quietly:
--
with Ada.Text_IO; use Ada.Text_IO;
procedure T is
   type Index_Type is range 0 .. 4; -- does not fail if lower bound is 1
   type Unconstrained_Array_Type is array (Index_Type range <>) of Integer;
   subtype Array_Type is Unconstrained_Array_Type (2..4);
   Target : array (1 .. 1) of Array_Type;
   procedure Check (Index : Index_Type; Value : Integer) is
   begin
      if Target (1) (Index) /= Value then
         Put_Line ("Expected " & Integer'Image (Value) & ", found " &
                                 Integer'Image (Target (1) (Index)));
      end if;
   end Check;
begin
   Target := (1 => (1 => 20, 2 => 30, 3 => 40)); -- assignment requires sliding
   Check (2, 20);
   Check (3, 30);
   Check (4, 40);
end;
--

2005-02-09  Ed Schonberg  <schonberg@adacore.com>

	* exp_aggr.adb (Gen_Assign): If the expression is an aggregate for a
	component of an array of arrays in an assignment context, and the
	aggregate has component associations that require sliding on
	assignment, force reanalysis of the aggregate to generate a temporary
	before the assignment.
	(Must_Slide): Make global to the package, for use in Gen_Assign.

Attachment: difs.8
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]