From patchwork Sun Jan 6 11:56:41 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [Ada] Fix layout of misaligned integer subtypes on big-endian Date: Sun, 06 Jan 2013 01:56:41 -0000 From: Eric Botcazou X-Patchwork-Id: 209745 Message-Id: <1977384.cmRLxvxfV8@polaris> To: gcc-patches@gcc.gnu.org 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 * gcc-interface/decl.c (gnat_to_gnu_entity) : Do not pack the field of the record type made for a misaligned type. 2013-01-06 Eric Botcazou * gnat.dg/alignment10.adb: New test. 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);