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 bit packaed array


Tested on i686-linux, committed on trunk

In order to expand an indexed component whose prefix is a bit packed array,
we need to construct, analyze and resolve an indexed component with the
underlying packed array as prefix. (We then combine this indexed component
with a shift and bit mask to extract the proper value). For the analysis
of the newly constructed indexed component to succeed, we need to ensure
that the type of its prefix is not changed back to the original (unpacked)
array type. This change ensures that for the case where the prefix is a
dereference (this case was previously missing from the relevant circuit).
Test case: the following program must be accepted by the compiler, and
the resulting executable must display three consistent columns of bits,
with 0 values everywhere except at positions 7, 12, and 29.
with Ada.Text_IO;
use Ada.Text_IO;
procedure P4 is

   procedure Show_Bit (B : in Boolean) is
      Bit_Value : constant array (Boolean) of Character :=
                    (False => '0', True => '1');
   begin
      Put (' ');
      Put (Bit_Value (B));
   end;

   type My_Int is new Integer;
   type Bitmap_Type is array (My_Int range <>) of Boolean;
   pragma Pack (Bitmap_Type);

   type Bitmap_Access is access Bitmap_Type;

   subtype Bit32_Type is Bitmap_Type (0 .. 31);

   Flip32 : Bit32_Type;
   Bit : Boolean;
   Ptr : Bitmap_Access := new Bitmap_Type'(Flip32);

begin
   Ptr.all := (others => False);
   Ptr (7)  := True;
   Ptr (12) := True;
   Ptr (29) := True;

   for I in Ptr.all'Range loop
      Put (My_Int'Image (I));
      if I < 10 then
         Put (' ');
      end if;
      Put (" - ");
      Bit := Ptr.all (I);
      Show_Bit (Bit);
      Show_Bit (Ptr (I));
      Show_Bit (Ptr.all (I));
      New_Line;
   end loop;
end;

2006-02-13  Thomas Quinot  <quinot@adacore.com>

	* exp_pakd.ads: Fix typos in comments.

	* exp_pakd.adb (Convert_To_PAT_Type): For the case of a bit packed
	array reference that is an explicit dereference, mark the converted
	(packed) array reference as analyzed to prevent a forthcoming
	reanalysis from resetting its type to the original (non-packed) array
	type.

Attachment: difs.49
Description: Text document


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