This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch,Fortran] PR41869 - fix module writing ICE


The attached patch - submitted on behalf of Paul - fixes the ICE of PR
41869. For a comment what happens, see PR or comment in the patch.

Build and regtested on x86-64-linux.
I think Paul's patch is OK and will thus commit it this evening, unless
there are objections. I am considering it for 4.4.

Tobias


2010-02-09  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/41869
	* module.c (fix_mio_expr): Fix for private generic procedures.

2010-02-09  Tobias Burnus  <burnus@net-b.de>

	PR fortran/41869
	* gfortran.dg/module_write_1.f90: New test.

diff --git a/gcc/fortran/module.c b/gcc/fortran/module.c
index c72cac1..97d124a 100644
--- a/gcc/fortran/module.c
+++ b/gcc/fortran/module.c
@@ -2931,9 +2946,23 @@ fix_mio_expr (gfc_expr *e)
 	 expression, in one use associated module, can fail to be
 	 coupled to its symtree when used in a specification
 	 expression in another module.  */
+
       fname = e->value.function.esym ? e->value.function.esym->name
 				     : e->value.function.isym->name;
       e->symtree = gfc_find_symtree (gfc_current_ns->sym_root, fname);
+
+      if (e->symtree)
+	return;
+
+      /* This is probably a reference to a private procedure from another
+	 module.  To prevent a segfault, make a generic with no specific
+	 instances.  If this module is used, without the required
+	 specific coming from somewhere, the appropriate error message
+	 is issued.  */
+      gfc_get_symbol (fname, gfc_current_ns, &sym);
+      sym->attr.flavor = FL_PROCEDURE;
+      sym->attr.generic = 1;
+      e->symtree = gfc_find_symtree (gfc_current_ns->sym_root, fname);
     }
 }
 
--- /dev/null	2010-01-25 08:41:01.306185411 +0100
+++ gcc/testsuite/gfortran.dg/module_write_1.f90	2010-02-09 14:31:02.000000000 +0100
@@ -0,0 +1,59 @@
+! { dg-do compile }
+!
+! PR fortran/41869
+!
+! Was ICEing while module write of symbol 'vs_str' in m_dom_dom
+! because of "len" being private in fox_m_fsys_format.
+!
+module fox_m_fsys_array_str
+contains
+  pure function str_vs(vs) result(s)
+    character, dimension(:), intent(in) :: vs
+    character(len=size(vs)) :: s
+    s = transfer(vs, s)
+  end function str_vs
+  pure function vs_str(s) result(vs)
+    character(len=*), intent(in) :: s
+    character, dimension(len(s)) :: vs
+    vs = transfer(s, vs)
+  end function vs_str
+end module fox_m_fsys_array_str
+
+module fox_m_fsys_format
+  private
+  interface str
+    module procedure  str_logical_array
+  end interface str
+  interface len
+    module procedure str_logical_array_len
+  end interface
+  public :: str
+contains
+  pure function str_logical_array_len(la) result(n)
+    logical, dimension(:), intent(in)   :: la
+  end function str_logical_array_len
+  pure function str_logical_array(la) result(s)
+    logical, dimension(:), intent(in)   :: la
+    character(len=len(la)) :: s
+  end function str_logical_array
+  pure function checkFmt(fmt) result(good)
+    character(len=*), intent(in) :: fmt
+    logical :: good
+    good = len(fmt) > 0
+  end function checkFmt
+end module fox_m_fsys_format
+
+module m_dom_dom
+  use fox_m_fsys_array_str, only: str_vs, vs_str
+end module m_dom_dom
+
+module FoX_dom
+  use fox_m_fsys_format
+  use m_dom_dom
+end module FoX_dom
+
+use FoX_dom
+implicit none
+print *, vs_str("ABC")
+end
+! { dg-final { cleanup-modules "fox_m_fsys_array_str fox_m_fsys_format m_dom_dom fox_dom" } }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]