Hello,

I have had a look at PR62044 where the compiler ICEs when loading the
extensions of a derived type from a module file, because one use-renamed
extended type is not found under its original name.

After scratching my head on the tree of extended types (rooted at
derived->f2k_derived->sym_root), wondering whether the renamed or
original name should be used, I decided to remove all that nonsense.

So here is the patch, regression tested on x86_64-unknown-linux-gnu.
There is a failure, graphite/pr42393.f90, also present on mainline.
OK for trunk/4.9/4.8 ?

Mikael


2015-01-25  Mikael Morin  <mik...@gcc.gnu.org>

        PR fortran/62044
        * decl.c (gfc_match_derived_decl): Don't insert a new symtree element.
        * module.c (MOD_VERSION): Bump.
        (write_module): Don't write list of extensions.
        (read_module): Don't jump over list of extensions;
        don't load list of extensions.
        (load_derived_extensions, write_dt_extensions,
         write_derived_extensions): Remove.

2015-01-25  Mikael Morin  <mik...@gcc.gnu.org>

        PR fortran/62044
        * gfortran.dg/use_rename_7.f90: New.



Index: decl.c
===================================================================
--- decl.c	(révision 220084)
+++ decl.c	(copie de travail)
@@ -7790,7 +7790,6 @@ gfc_match_derived_decl (void)
   if (extended && !sym->components)
     {
       gfc_component *p;
-      gfc_symtree *st;
 
       /* Add the extended derived type as the first component.  */
       gfc_add_component (sym, parent, &p);
@@ -7815,8 +7814,6 @@ gfc_match_derived_decl (void)
       /* Provide the links between the extended type and its extension.  */
       if (!extended->f2k_derived)
 	extended->f2k_derived = gfc_get_namespace (NULL, 0);
-      st = gfc_new_symtree (&extended->f2k_derived->sym_root, sym->name);
-      st->n.sym = sym;
     }
 
   if (!sym->hash_value)
Index: module.c
===================================================================
--- module.c	(révision 220084)
+++ module.c	(copie de travail)
@@ -92,7 +92,7 @@ along with GCC; see the file COPYING3.  If not see
 
 /* Don't put any single quote (') in MOD_VERSION, if you want it to be
    recognized.  */
-#define MOD_VERSION "13"
+#define MOD_VERSION "14"
 
 
 /* Structure that describes a position within a module file.  */
@@ -4542,71 +4542,6 @@ load_equiv (void)
 }
 
 
-/* This function loads the sym_root of f2k_derived with the extensions to
-   the derived type.  */
-static void
-load_derived_extensions (void)
-{
-  int symbol, j;
-  gfc_symbol *derived;
-  gfc_symbol *dt;
-  gfc_symtree *st;
-  pointer_info *info;
-  char name[GFC_MAX_SYMBOL_LEN + 1];
-  char module[GFC_MAX_SYMBOL_LEN + 1];
-  const char *p;
-
-  mio_lparen ();
-  while (peek_atom () != ATOM_RPAREN)
-    {
-      mio_lparen ();
-      mio_integer (&symbol);
-      info = get_integer (symbol);
-      derived = info->u.rsym.sym;
-
-      /* This one is not being loaded.  */
-      if (!info || !derived)
-	{
-	  while (peek_atom () != ATOM_RPAREN)
-	    skip_list ();
-	  continue;
-	}
-
-      gcc_assert (derived->attr.flavor == FL_DERIVED);
-      if (derived->f2k_derived == NULL)
-	derived->f2k_derived = gfc_get_namespace (NULL, 0);
-
-      while (peek_atom () != ATOM_RPAREN)
-	{
-	  mio_lparen ();
-	  mio_internal_string (name);
-	  mio_internal_string (module);
-
-          /* Only use one use name to find the symbol.  */
-	  j = 1;
-	  p = find_use_name_n (name, &j, false);
-	  if (p)
-	    {
-	      st = gfc_find_symtree (gfc_current_ns->sym_root, p);
-	      dt = st->n.sym;
-	      st = gfc_find_symtree (derived->f2k_derived->sym_root, name);
-	      if (st == NULL)
-		{
-		  /* Only use the real name in f2k_derived to ensure a single
-		    symtree.  */
-		  st = gfc_new_symtree (&derived->f2k_derived->sym_root, name);
-		  st->n.sym = dt;
-		  st->n.sym->refs++;
-		}
-	    }
-	  mio_rparen ();
-	}
-      mio_rparen ();
-    }
-  mio_rparen ();
-}
-
-
 /* This function loads OpenMP user defined reductions.  */
 static void
 load_omp_udrs (void)
@@ -4907,7 +4842,7 @@ check_for_ambiguous (gfc_symbol *st_sym, pointer_i
 static void
 read_module (void)
 {
-  module_locus operator_interfaces, user_operators, extensions, omp_udrs;
+  module_locus operator_interfaces, user_operators, omp_udrs;
   const char *p;
   char name[GFC_MAX_SYMBOL_LEN + 1];
   int i;
@@ -4926,13 +4861,10 @@ read_module (void)
   skip_list ();
   skip_list ();
 
-  /* Skip commons, equivalences and derived type extensions for now.  */
+  /* Skip commons and equivalences for now.  */
   skip_list ();
   skip_list ();
 
-  get_module_locus (&extensions);
-  skip_list ();
-
   /* Skip OpenMP UDRs.  */
   get_module_locus (&omp_udrs);
   skip_list ();
@@ -5238,11 +5170,6 @@ read_module (void)
 		 module_name);
     }
 
-  /* Now we should be in a position to fill f2k_derived with derived type
-     extensions, since everything has been loaded.  */
-  set_module_locus (&extensions);
-  load_derived_extensions ();
-
   /* Clean up symbol nodes that were never loaded, create references
      to hidden symbols.  */
 
@@ -5460,49 +5387,6 @@ write_equiv (void)
 }
 
 
-/* Write derived type extensions to the module.  */
-
-static void
-write_dt_extensions (gfc_symtree *st)
-{
-  if (!gfc_check_symbol_access (st->n.sym))
-    return;
-  if (!(st->n.sym->ns && st->n.sym->ns->proc_name
-	&& st->n.sym->ns->proc_name->attr.flavor == FL_MODULE))
-    return;
-
-  mio_lparen ();
-  mio_pool_string (&st->name);
-  if (st->n.sym->module != NULL)
-    mio_pool_string (&st->n.sym->module);
-  else
-    {
-      char name[GFC_MAX_SYMBOL_LEN + 1];
-      if (iomode == IO_OUTPUT)
-	strcpy (name, module_name);
-      mio_internal_string (name);
-      if (iomode == IO_INPUT)
-	module_name = gfc_get_string (name);
-    }
-  mio_rparen ();
-}
-
-static void
-write_derived_extensions (gfc_symtree *st)
-{
-  if (!((st->n.sym->attr.flavor == FL_DERIVED)
-	  && (st->n.sym->f2k_derived != NULL)
-	  && (st->n.sym->f2k_derived->sym_root != NULL)))
-    return;
-
-  mio_lparen ();
-  mio_symbol_ref (&(st->n.sym));
-  gfc_traverse_symtree (st->n.sym->f2k_derived->sym_root,
-			write_dt_extensions);
-  mio_rparen ();
-}
-
-
 /* Write a symbol to the module.  */
 
 static void
@@ -5900,13 +5784,6 @@ write_module (void)
   write_char ('\n');
 
   mio_lparen ();
-  gfc_traverse_symtree (gfc_current_ns->sym_root,
-			write_derived_extensions);
-  mio_rparen ();
-  write_char ('\n');
-  write_char ('\n');
-
-  mio_lparen ();
   write_omp_udrs (gfc_current_ns->omp_udr_root);
   mio_rparen ();
   write_char ('\n');

! { dg-do compile }
!
! PR fortran/62044
! ICE when loading module UnstructuredGridImages
! because the type UnstructuredGridImageSiloForm
! is not accessible there under its name.
!
! Contributed by Reuben Budiardja <reube...@gmail.com>

module UnstructuredGridImageSilo_Form
  implicit none
  private
  type, public, abstract :: GridImageSiloTemplate
  end type GridImageSiloTemplate
  type, public, extends ( GridImageSiloTemplate ) :: &
    UnstructuredGridImageSiloForm
  end type UnstructuredGridImageSiloForm
end module UnstructuredGridImageSilo_Form

module UnstructuredGridImages
  use UnstructuredGridImageSilo_Form, &
        UnstructuredGridImageForm => UnstructuredGridImageSiloForm
end module UnstructuredGridImages

module FileSystem
  use UnstructuredGridImages
end module FileSystem

Reply via email to