This is a regression present on all actives branches: the compiler doesn't 
correctly align a field in a record type if there is a partial representation 
clause on this record type that does not cover the field, but covers another 
field which is aliased (or contains an aliased subcomponent) and whose nominal 
alignment is smaller than that of the former field.

Tested on x86_64-suse-linux, applied on the mainline, 7 & 6 branches.


2017-12-14  Eric Botcazou  <ebotca...@adacore.com>

        * gcc-interface/decl.c (gnat_to_gnu_field): Do not set the alignment
        of the enclosing record type if it is not already set.


2017-12-14  Eric Botcazou  <ebotca...@adacore.com>

        * gnat.dg/alignment13.adb: New test.

-- 
Eric Botcazou
-- { dg-do run }
-- { dg-options "-gnatws" }

procedure Alignment13 is

  type Rec is record
    I1 : aliased Short_Integer;
    I2 : Integer;
  end record;

  for Rec use record
    I1 at 0 range 0 .. 15;
  end record;

  R : Rec;

begin
  if R.I2'Bit_Position /= 32 then
    raise Program_Error;
  end if;
end;
Index: gcc-interface/decl.c
===================================================================
--- gcc-interface/decl.c	(revision 255631)
+++ gcc-interface/decl.c	(working copy)
@@ -6890,7 +6890,8 @@ gnat_to_gnu_field (Entity_Id gnat_field,
 	{
 	  const unsigned int type_align = TYPE_ALIGN (gnu_field_type);
 
-	  if (TYPE_ALIGN (gnu_record_type) < type_align)
+	  if (TYPE_ALIGN (gnu_record_type)
+	      && TYPE_ALIGN (gnu_record_type) < type_align)
 	    SET_TYPE_ALIGN (gnu_record_type, type_align);
 
 	  /* If the position is not a multiple of the alignment of the type,

Reply via email to