public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Accept size for record with oversized component clause
@ 2019-10-11  9:10 Eric Botcazou
  0 siblings, 0 replies; only message in thread
From: Eric Botcazou @ 2019-10-11  9:10 UTC (permalink / raw)
  To: gcc-patches

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

This makes the compiler accept again an exact size clause for a record type 
that contains both a component subject to a representation clause that gives 
it a size greater than its nominal size and another component that is aliased.

Tested on x86_64-suse-linux, applied on the mainline.


2019-10-11  Eric Botcazou  <ebotcazou@adacore.com>

	* gcc-interface/decl.c (gnat_to_gnu_field): Adjust again the packing
	for a field without strict alignment and with an oversized clause.


2019-10-11  Eric Botcazou  <ebotcazou@adacore.com>

	* gnat.dg/specs/size_clause4.ads: New test.

-- 
Eric Botcazou

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

Index: gcc-interface/decl.c
===================================================================
--- gcc-interface/decl.c	(revision 276866)
+++ gcc-interface/decl.c	(working copy)
@@ -7229,10 +7229,17 @@ gnat_to_gnu_field (Entity_Id gnat_field,
 	  && INTEGRAL_TYPE_P (TREE_TYPE (TYPE_FIELDS (gnu_field_type))))
 	gnu_field_type = TREE_TYPE (TYPE_FIELDS (gnu_field_type));
 
+      orig_field_type = gnu_field_type;
       gnu_field_type
 	= make_type_from_size (gnu_field_type, gnu_size,
 			       Has_Biased_Representation (gnat_field));
 
+      /* If the type has been extended, we may need to cap the alignment.  */
+      if (!needs_strict_alignment
+	  && gnu_field_type != orig_field_type
+	  && tree_int_cst_lt (TYPE_SIZE (orig_field_type), gnu_size))
+	packed = adjust_packed (gnu_field_type, gnu_record_type, packed);
+
       orig_field_type = gnu_field_type;
       gnu_field_type = maybe_pad_type (gnu_field_type, gnu_size, 0, gnat_field,
 				       false, false, definition, true);

[-- Attachment #3: size_clause4.ads --]
[-- Type: text/x-adasrc, Size: 350 bytes --]

-- { dg-do compile }

with System;

package Size_Clause4 is

  type Rec is record
    A1 : System.Address;  
    A2 : System.Address;  
    I  : aliased Integer; 
  end record;
       
  for Rec use record
    A1 at 0  range 0 .. 63; 
    A2 at 8  range 0 .. 63;
    I  at 16 range 0 .. 31;  
  end record;
  for Rec'Size use 160;

end Size_Clause4;

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

only message in thread, other threads:[~2019-10-11  9:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-11  9:10 [Ada] Accept size for record with oversized component 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).