This is a regression present on mainline and 4.7 branch, exposed by a recent
change in the propagation of alignment from types to subtypes. The layout of
misaligned integer subtypes is incorrect on big-endian platforms (it is left
justified instead of being right justified).
Fixed thusly, tested on x86_64-suse-linux, applied on mainline and 4.7 branch.
2013-01-06 Eric Botcazou <ebotca...@adacore.com>
* gcc-interface/decl.c (gnat_to_gnu_entity) <discrete_type>: Do not
pack the field of the record type made for a misaligned type.
2013-01-06 Eric Botcazou <ebotca...@adacore.com>
* gnat.dg/alignment10.adb: New test.
--
Eric Botcazou
Index: gcc-interface/decl.c
===================================================================
--- gcc-interface/decl.c (revision 194939)
+++ gcc-interface/decl.c (working copy)
@@ -1887,8 +1887,10 @@ gnat_to_gnu_entity (Entity_Id gnat_entit
}
/* If the type we are dealing with has got a smaller alignment than the
- natural one, we need to wrap it up in a record type and under-align
- the latter. We reuse the padding machinery for this purpose. */
+ natural one, we need to wrap it up in a record type and misalign the
+ latter; we reuse the padding machinery for this purpose. Note that,
+ even if the record type is marked as packed because of misalignment,
+ we don't pack the field so as to give it the size of the type. */
else if (align > 0)
{
tree gnu_field_type, gnu_field;
@@ -1918,7 +1920,8 @@ gnat_to_gnu_entity (Entity_Id gnat_entit
a bitfield. */
gnu_field
= create_field_decl (get_identifier ("F"), gnu_field_type,
- gnu_type, NULL_TREE, bitsize_zero_node, 1, 0);
+ gnu_type, TYPE_SIZE (gnu_field_type),
+ bitsize_zero_node, 0, 0);
finish_record_type (gnu_type, gnu_field, 2, debug_info_p);
compute_record_mode (gnu_type);
-- { dg-do run }
procedure Alignment10 is
type Short_T is mod 2 ** 16;
for Short_T'Size use 16;
for Short_T'Alignment use 1;
subtype Short_Sub_T is Short_T range 1000 .. 1005;
A : aliased Short_T := 1000;
B : Short_Sub_T;
for B'Address use A'Address;
pragma Import (Ada, B);
begin
if B /= 1000 then
raise Program_Error;
end if;
end;