diff mbox

[Ada] Fix layout of misaligned integer subtypes on big-endian

Message ID 1977384.cmRLxvxfV8@polaris
State New
Headers show

Commit Message

Eric Botcazou Jan. 6, 2013, 11:56 a.m. UTC
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  <ebotcazou@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  <ebotcazou@adacore.com>

	* gnat.dg/alignment10.adb: New test.
diff mbox

Patch

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);