[Ada] Fix misalignment in record with aliased field and rep clause

Message ID 6469179.kLBJeh23V6@polaris
State New
Headers show
Series
  • [Ada] Fix misalignment in record with aliased field and rep clause
Related show

Commit Message

Eric Botcazou Dec. 14, 2017, 5:07 p.m.
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  <ebotcazou@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  <ebotcazou@adacore.com>

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

-- 
Eric Botcazou

Patch

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,