public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Fix misalignment in record with aliased field and rep clause
@ 2017-12-14 17:07 Eric Botcazou
  0 siblings, 0 replies; only message in thread
From: Eric Botcazou @ 2017-12-14 17:07 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 726 bytes --]

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

[-- Attachment #2: alignment13.adb --]
[-- Type: text/x-adasrc, Size: 313 bytes --]

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

[-- Attachment #3: p.diff --]
[-- Type: text/x-patch, Size: 580 bytes --]

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,

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-12-14 17:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-14 17:07 [Ada] Fix misalignment in record with aliased field and rep clause Eric Botcazou

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).