public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Fix bogus alignment error for derived array
@ 2009-04-24  7:08 Eric Botcazou
  0 siblings, 0 replies; only message in thread
From: Eric Botcazou @ 2009-04-24  7:08 UTC (permalink / raw)
  To: gcc-patches

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

Gigi promotes the alignment of the component type too aggressively, which 
results in a conflict between the final alignment of the whole array and the 
value set by the front-end through the derivation.

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


2009-04-24  Eric Botcazou  <ebotcazou@adacore.com>

	* gcc-interface/decl.c (gnat_to_gnu_entity) <E_Array_Type>: If an
	alignment is specified, do not promote that of the component type
	beyond it.
	<E_Array_Subtype>: Likewise.


2009-04-24  Eric Botcazou  <ebotcazou@adacore.com>

	* gnat.dg/specs/pr34799.ads: Rename to rep_clause1.ads.
	* gnat.dg/specs/rep_clause2.ads: New test.


-- 
Eric Botcazou

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

Index: gcc-interface/decl.c
===================================================================
--- gcc-interface/decl.c	(revision 146647)
+++ gcc-interface/decl.c	(working copy)
@@ -1957,11 +1957,28 @@ gnat_to_gnu_entity (Entity_Id gnat_entit
 
 	if (gnu_comp_size && !Is_Bit_Packed_Array (gnat_entity))
 	  {
-	    tree orig_tem;
+	    tree orig_tem = tem;
+	    unsigned int max_align;
+
+	    /* If an alignment is specified, use it as a cap on the component
+	       type so that it can be honored for the whole type.  But ignore
+	       it for the original type of packed array types.  */
+	    if (No (Packed_Array_Type (gnat_entity))
+		&& Known_Alignment (gnat_entity))
+	      max_align = validate_alignment (Alignment (gnat_entity),
+					      gnat_entity, 0);
+	    else
+	      max_align = 0;
+
 	    tem = make_type_from_size (tem, gnu_comp_size, false);
-	    orig_tem = tem;
+	    if (max_align > 0 && TYPE_ALIGN (tem) > max_align)
+	      tem = orig_tem;
+	    else
+	      orig_tem = tem;
+
 	    tem = maybe_pad_type (tem, gnu_comp_size, 0, gnat_entity,
 				  "C_PAD", false, definition, true);
+
 	    /* If a padding record was made, declare it now since it will
 	       never be declared otherwise.  This is necessary to ensure
 	       that its subtrees are properly marked.  */
@@ -2343,13 +2360,31 @@ gnat_to_gnu_entity (Entity_Id gnat_entit
 
 	      if (gnu_comp_size && !Is_Bit_Packed_Array (gnat_entity))
 		{
-		  tree orig_gnu_type;
+		  tree orig_gnu_type = gnu_type;
+		  unsigned int max_align;
+
+		  /* If an alignment is specified, use it as a cap on the
+		     component type so that it can be honored for the whole
+		     type.  But ignore it for the original type of packed
+		     array types.  */
+		  if (No (Packed_Array_Type (gnat_entity))
+		      && Known_Alignment (gnat_entity))
+		    max_align = validate_alignment (Alignment (gnat_entity),
+						    gnat_entity, 0);
+		  else
+		    max_align = 0;
+
 		  gnu_type
 		    = make_type_from_size (gnu_type, gnu_comp_size, false);
-		  orig_gnu_type = gnu_type;
+		  if (max_align > 0 && TYPE_ALIGN (gnu_type) > max_align)
+		    gnu_type = orig_gnu_type;
+		  else
+		    orig_gnu_type = gnu_type;
+
 		  gnu_type = maybe_pad_type (gnu_type, gnu_comp_size, 0,
 					     gnat_entity, "C_PAD", false,
 					     definition, true);
+
 		  /* If a padding record was made, declare it now since it
 		     will never be declared otherwise.  This is necessary
 		     to ensure that its subtrees are properly marked.  */

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

-- { dg-do compile }
-- { dg-options "-gnatws" }

package Rep_Clause2 is

  type S is new String;
  for S'Component_Size use 256;

  type T is new S(1..8);

end Rep_Clause2;

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

only message in thread, other threads:[~2009-04-24  7:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-24  7:08 [Ada] Fix bogus alignment error for derived array 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).