[Ada] Improve array packing for small record component
Eric Botcazou
ebotcazou@adacore.com
Mon May 16 10:14:00 GMT 2016
This change ensures that the packing of array types subject to pragma Pack
and whose component type is a record with a size in the range 33 .. 63 bits
is optimal, in the sense that the 'Component_Size is equal to the 'Size of
the component type.
The following package P must yield the specified output with -gnatR1:
package P is
type R is record
I : Integer;
B : Boolean;
end record;
pragma Pack (R);
type A1 is array (1 .. 8) of R;
pragma Pack (A1);
type A2 is array (1 .. 8) of R;
for A2'Component_Size use 33;
end P;
Representation information for unit P (spec)
--------------------------------------------
for R'Object_Size use 40;
for R'Value_Size use 33;
for R'Alignment use 1;
for R use record
I at 0 range 0 .. 31;
B at 4 range 0 .. 0;
end record;
for A1'Size use 264;
for A1'Alignment use 1;
for A1'Component_Size use 33;
for A2'Size use 264;
for A2'Alignment use 1;
for A2'Component_Size use 33;
Tested on x86_64-suse-linux, applied on the mainline.
2016-05-16 Eric Botcazou <ebotcazou@adacore.com>
* exp_util.adb (Remove_Side_Effects): Also make a constant if we need
to capture the value for a small not by-reference record type.
* freeze.ads (Check_Compile_Time_Size): Adjust comment.
* freeze.adb (Set_Small_Size): Likewise. Accept a size in the range
of 33 .. 64 bits.
(Check_Compile_Time_Size): Merge scalar and access type cases. Change
variable name in array type case. For the computation of the packed
size, deal with record components and remove redundant test.
(Freeze_Array_Type): Also adjust packing status when the size of the
component type is in the range 33 .. 64 bits.
* doc/gnat_rm/representation_clauses_and_pragmas.rst: Turn primitive
into elementary type throughout. Minor tweaks.
(Alignment Clauses): Document actual alignment of packed array types.
(Pragma Pack for Arrays): List only the 3 main cases and adjust. Add
"simple" to the record case. Document effect on non packable types.
(Pragma Pack for Records): Likewise. Add record case and adjust.
--
Eric Botcazou
-------------- next part --------------
A non-text attachment was scrubbed...
Name: p.diff
Type: text/x-patch
Size: 17513 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20160516/2c3a53ee/attachment.bin>
More information about the Gcc-patches
mailing list