diff mbox

[fortran] PR59016, second version

Message ID 5526FAE2.2010000@sfr.fr
State New
Headers show

Commit Message

Mikael Morin April 9, 2015, 10:19 p.m. UTC
Hello,

I have finally taken over PR59016.
The bug was a pointer to a freed (derived type) symbol retained in the
generic one with the same name, because the symbols weren't versioned.

Evangelos proposed a patch that was freeing the memory by hand.  The
simpler one here, on the other hand, saves the symbol before any
modification and lets the symbol undo code do its job.
Thanks to Evangelos anyway for isolating the bug and proposing a fix.

This patch has been tested on x86_64-unknown-linux-gnu.
OK for trunk/4.9/4.8?

Mikael
2015-04-09  Mikael Morin  <mikael@gcc.gnu.org>

	PR fortran/56674
	PR fortran/58813
	PR fortran/59016
	PR fortran/59024
	* symbol.c (save_symbol_data, gfc_save_symbol_data): Rename the
	former to the latter and make non-static.  Update callers.
	* gfortran.h (gfc_save_symbol_data): New prototype.
	* decl.c (gfc_match_decl_type_spec): Call 'gfc_save_symbol_data'
	before modifying symbols 'sym' and 'dt_sym'.

2015-04-09  Mikael Morin  <mikael@gcc.gnu.org>

	PR fortran/56674
	PR fortran/58813
	PR fortran/59016
	PR fortran/59024
	* gfortran.dg/used_types_27.f90: New.

Comments

Tobias Burnus April 10, 2015, 10:24 a.m. UTC | #1
Hello,

Mikael Morin wrote:
> I have finally taken over PR59016.
> The bug was a pointer to a freed (derived type) symbol retained in the
> generic one with the same name, because the symbols weren't versioned.
>
> Evangelos proposed a patch that was freeing the memory by hand.  The
> simpler one here, on the other hand, saves the symbol before any
> modification and lets the symbol undo code do its job.
> Thanks to Evangelos anyway for isolating the bug and proposing a fix.
>
> This patch has been tested on x86_64-unknown-linux-gnu.
> OK for trunk/4.9/4.8?

Thanks for the work on this, Evangelos and Mikael!
The patch looks good to me.

Cheers,

Tobias
diff mbox

Patch

Index: decl.c
===================================================================
--- decl.c	(révision 221654)
+++ decl.c	(copie de travail)
@@ -2876,6 +2876,7 @@  gfc_match_decl_type_spec (gfc_typespec *ts, int im
       return MATCH_ERROR;
     }
 
+  gfc_save_symbol_data (sym);
   gfc_set_sym_referenced (sym);
   if (!sym->attr.generic
       && !gfc_add_generic (&sym->attr, sym->name, NULL))
@@ -2900,6 +2901,8 @@  gfc_match_decl_type_spec (gfc_typespec *ts, int im
       sym->generic = intr;
       sym->attr.if_source = IFSRC_DECL;
     }
+  else
+    gfc_save_symbol_data (dt_sym);
 
   gfc_set_sym_referenced (dt_sym);
 
Index: gfortran.h
===================================================================
--- gfortran.h	(révision 221657)
+++ gfortran.h	(copie de travail)
@@ -2819,6 +2819,7 @@  bool verify_bind_c_derived_type (gfc_symbol *);
 bool verify_com_block_vars_c_interop (gfc_common_head *);
 gfc_symtree *generate_isocbinding_symbol (const char *, iso_c_binding_symbol,
 					  const char *, gfc_symtree *, bool);
+void gfc_save_symbol_data (gfc_symbol *);
 int gfc_get_sym_tree (const char *, gfc_namespace *, gfc_symtree **, bool);
 int gfc_get_ha_symbol (const char *, gfc_symbol **);
 int gfc_get_ha_sym_tree (const char *, gfc_symtree **);
Index: symbol.c
===================================================================
--- symbol.c	(révision 221654)
+++ symbol.c	(copie de travail)
@@ -2758,8 +2758,8 @@  single_undo_checkpoint_p (void)
 
 /* Save symbol with the information necessary to back it out.  */
 
-static void
-save_symbol_data (gfc_symbol *sym)
+void
+gfc_save_symbol_data (gfc_symbol *sym)
 {
   gfc_symbol *s;
   unsigned i;
@@ -2860,7 +2860,7 @@  gfc_get_sym_tree (const char *name, gfc_namespace
       p->mark = 1;
 
       /* Copy in case this symbol is changed.  */
-      save_symbol_data (p);
+      gfc_save_symbol_data (p);
     }
 
   *result = st;
@@ -2899,7 +2899,7 @@  gfc_get_ha_sym_tree (const char *name, gfc_symtree
 
   if (st != NULL)
     {
-      save_symbol_data (st->n.sym);
+      gfc_save_symbol_data (st->n.sym);
       *result = st;
       return i;
     }