public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Eric Botcazou <ebotcazou@adacore.com>
To: gcc-patches@gcc.gnu.org
Subject: [Ada] Fix type mismatch for discriminant of derived type
Date: Sat, 24 Oct 2009 11:47:00 -0000	[thread overview]
Message-ID: <200910241315.06108.ebotcazou@adacore.com> (raw)

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

Deriving a discriminated record type can create a type mismatch when the type 
is packed.  This is now detected on the mainline.  The fix is to use the 
proper type to build the problematic COMPONENT_REF.

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


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

	* gcc-interface/decl.c (gnat_to_gnu_entity) <E_Record_Type>: When
	processing the parent type, build the COMPONENT_REF for a discriminant
	with the proper type.


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

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


-- 
Eric Botcazou

[-- Attachment #2: pack4.ads --]
[-- Type: text/x-adasrc, Size: 249 bytes --]

package Pack4 is

   type Buffer is array (Natural range <>) of Boolean;

   type Root (Size : Natural) is tagged record
      Data : Buffer (1..Size);
   end record;
   pragma Pack (Root);

   type Derived is new Root with null record;

end Pack4;

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

Index: gcc-interface/decl.c
===================================================================
--- gcc-interface/decl.c	(revision 153447)
+++ gcc-interface/decl.c	(working copy)
@@ -2729,15 +2729,16 @@ gnat_to_gnu_entity (Entity_Id gnat_entit
 		   Present (gnat_field);
 		   gnat_field = Next_Stored_Discriminant (gnat_field))
 		if (Present (Corresponding_Discriminant (gnat_field)))
-		  save_gnu_tree
-		    (gnat_field,
-		     build3 (COMPONENT_REF,
-			     get_unpadded_type (Etype (gnat_field)),
-			     gnu_get_parent,
-			     gnat_to_gnu_field_decl (Corresponding_Discriminant
-						     (gnat_field)),
-			     NULL_TREE),
-		     true);
+		  {
+		    tree gnu_field
+		      = gnat_to_gnu_field_decl (Corresponding_Discriminant
+						(gnat_field));
+		    save_gnu_tree
+		      (gnat_field,
+		       build3 (COMPONENT_REF, TREE_TYPE (gnu_field),
+			       gnu_get_parent, gnu_field, NULL_TREE),
+		       true);
+		  }
 
 	    /* Then we build the parent subtype.  If it has discriminants but
 	       the type itself has unknown discriminants, this means that it

                 reply	other threads:[~2009-10-24 11:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200910241315.06108.ebotcazou@adacore.com \
    --to=ebotcazou@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).