public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Fix type mismatch for discriminant of derived type
@ 2009-10-24 11:47 Eric Botcazou
  0 siblings, 0 replies; only message in thread
From: Eric Botcazou @ 2009-10-24 11:47 UTC (permalink / raw)
  To: gcc-patches

[-- 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

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

only message in thread, other threads:[~2009-10-24 11:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-24 11:47 [Ada] Fix type mismatch for discriminant of derived type 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).