diff mbox

[Ada] Fix crash on declaration of constant with discriminated type

Message ID 201103261114.32966.ebotcazou@adacore.com
State New
Headers show

Commit Message

Eric Botcazou March 26, 2011, 10:14 a.m. UTC
The compiler crashes on the declaration of a constant with discriminated record 
type and variable size, if the constant is initialized to an aggregate which 
assigns the length of an array with variable size to a discriminant.  The 
problem is again an incorrect sharing of a tree node between two types.

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


2011-03-26  Eric Botcazou  <ebotcazou@adacore.com>

	* gcc-interface/decl.c (gnat_to_gnu_entity) <object>: Create TYPE_DECL
	for the padded type built to support a specified size or alignment.


2011-03-26  Eric Botcazou  <ebotcazou@adacore.com>

	* gnat.dg/discr27.ad[sb]: New test.
diff mbox

Patch

Index: gcc-interface/decl.c
===================================================================
--- gcc-interface/decl.c	(revision 171552)
+++ gcc-interface/decl.c	(working copy)
@@ -911,9 +911,20 @@  gnat_to_gnu_entity (Entity_Id gnat_entit
 	   size of the object.  */
 	gnu_object_size = gnu_size ? gnu_size : TYPE_SIZE (gnu_type);
 	if (gnu_size || align > 0)
-	  gnu_type = maybe_pad_type (gnu_type, gnu_size, align, gnat_entity,
-				     false, false, definition,
-				     gnu_size ? true : false);
+	  {
+	    tree orig_type = gnu_type;
+
+	    gnu_type = maybe_pad_type (gnu_type, gnu_size, align, gnat_entity,
+				       false, false, definition,
+				       gnu_size ? true : false);
+
+	    /* 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.  */
+	    if (gnu_type != orig_type && !DECL_P (TYPE_NAME (gnu_type)))
+	      create_type_decl (TYPE_NAME (gnu_type), gnu_type, NULL, true,
+				debug_info_p, gnat_entity);
+	  }
 
 	/* If this is a renaming, avoid as much as possible to create a new
 	   object.  However, in several cases, creating it is required.