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] enhance support for packed arrays


Tested on i686-linux. Committed on mainline.

This patch has to do with what component clauses are allowed in
a record representation clause for a packed array. Prior to this
patch, any packed array with a length longer than 64 bits was
required to start on a byte boundary. The reason for this is that
the System.Pack_nn units (used to handle a packed component size
of nn) depend on this byte alignment.

However, for the (important subset of) cases where the component
size is a power of 2 (notably including 1, the packed bit case),
we don't use a System.Pack_nn unit, but instead generate direct
shift and mask code. This means that the limitation is not needed
in these cases. The actual implementation is to avoid setting the
flag Must_Be_Byte_Aligned in these power-of-2 cases.

The following is a test program which must compile without complaint:

package test1 is
   type BIT_ARRAY is array (Integer range <>) of Boolean;
   pragma pack(BIT_ARRAY);

   type TREC is record
      M1 : BIT_ARRAY(1..68);
      M2 : BIT_ARRAY(1..68);
      M3 : BIT_ARRAY(1..68);
      M4 : BIT_ARRAY(1..68);
      M5 : BIT_ARRAY(1..68);
      M6 : BIT_ARRAY(1..20);
   end record;
   for TREC use record
      M1 at 0  range 0..67;
      M2 at 0  range 68..135;
      M3 at 0  range 136..203;
      M4 at 0  range 204..271;
      M5 at 0  range 272..339;
      M6 at 0  range 340..359;
   end record;
   for TREC'Size use 360;
end test1;

--
PR ada/19900

This is a long-standing latent bug that has not been noticed for a variety
of reasons, most notably because Gigi doesn't verify that Expansion_Delayed
is False.  It is, however, needed in order for the fix for GCC PR 19900
to work.

--
A renaming_as_body generates a body to wrap the call to the renamed
entity, but whenever possible a call to a subprogram declared with
such a renaming is rewritten as a call to the renamed entity. If the
renamed entity is inherited, it is an alias for the parent operation,
and it is the parent operation that must be called, because the back-end
does not see any declaration for the inherited one. The call must then
be expanded anew to insert needed conversions between the derived type
and the parent type.
The following program, compiled as:
--
gnatmake -q -gnatws -gnatn b
must produce the output:
--
enjoy!
--
with C;
procedure B is begin C.Z (C.F);
end;
with D;
package C is
   type U is new D.T;
   procedure Y (S : String; V : U); pragma Inline (Y);
   procedure Z (S : String); pragma Inline (Z);
   function F return String;
end;
package body C is
   procedure Y ( S : String; V : U) renames G;
   procedure Z (S : String) is V : U; begin Y (S, V); end Z;
   function F return String is begin return "enjoy!"; end;
end C;
with text_io; use text_io;
package body D is
   procedure G (S : String; O  : T) is begin put_line (S); end;
end;
package D is
   type T is new Integer;
   procedure G (S : String; O : T);
end;

2005-03-08  Robert Dewar  <dewar@adacore.com>
	    Ed Schonberg  <schonberg@adacore.com>
	    Richard Kenner  <kenner@vlsi1.ultra.nyu.edu>

	* exp_pakd.adb (Create_Packed_Array_Type): Do not set
	Must_Be_Byte_Aligned for cases where we do not need to use a
	System.Pack_nn unit.

	* exp_ch6.adb (Expand_Call): Call Expand_Actuals for functions as well
	as procedures.
	Needed now that we do some processing for IN parameters as well. This
	may well fix some unrelated errors.
	(Expand_Call): Handle case of unaligned objects (in particular those
	that come from packed arrays).
	(Expand_Inlined_Call): If the subprogram is a renaming as body, and the
	renamed entity is an inherited operation, re-expand the call using the
	original operation, which is the one to call.
	Detect attempt to inline parameterless recursive subprogram.
	(Represented_As_Scalar): Fix to work properly with private types
	(Is_Possibly_Unaligned_Object): Major rewrite to get a much more
	accurate estimate. Yields True in far fewer cases than before,
	improving the quality of code that depends on this test.
	(Remove_Side_Effects): Properly test for Expansion_Delayed and handle
	case when it's inside an N_Qualified_Expression.

	* exp_util.adb (Kill_Dead_Code): For a package declaration, iterate
	over both visible and private declarations to remove them from tree,
	and mark subprograms declared in package as eliminated, to prevent
	spurious use in subsequent compilation of generic units in the context.

	* exp_util.ads: Minor cleanup in variable names

	* sem_eval.ads, sem_eval.adb: Minor reformatting
	(Compile_Time_Known_Bounds): New function

Attachment: difs.14
Description: Text document


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