Bug 40882 - [F03] infinite recursion in gfc_get_derived_type with PPC returning derived type
Summary: [F03] infinite recursion in gfc_get_derived_type with PPC returning derived type
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: ---
Assignee: janus
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2009-07-27 20:05 UTC by janus
Modified: 2009-07-28 12:14 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2009-07-27 21:05:09


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description janus 2009-07-27 20:05:58 UTC
The following test program induces an infinite recursion in gfc_get_derived_type:


implicit none

type :: t
  real :: data
  procedure(foo), pointer, nopass :: ppc
end type

type(t) :: o,o2

o%ppc => foo

o2 = o%ppc()

contains

  function foo()
    type(t) :: foo
    foo%data = 5.
    foo%ppc => NULL()
  end function

end
Comment 1 janus 2009-07-27 21:05:08 UTC
Here is a preliminary patch which makes the test case compile:

Index: gcc/fortran/trans-types.c
===================================================================
--- gcc/fortran/trans-types.c	(revision 150133)
+++ gcc/fortran/trans-types.c	(working copy)
@@ -1894,7 +1894,12 @@ gfc_get_ppc_type (gfc_component* c)
 {
   tree t;
   if (c->attr.function && !c->attr.dimension)
-    t = gfc_typenode_for_spec (&c->ts);
+    {
+      if (c->ts.type == BT_DERIVED)
+	t = c->ts.derived->backend_decl;
+      else
+	t = gfc_typenode_for_spec (&c->ts);
+    }
   else
     t = void_type_node;
   /* TODO: Build argument list.  */
@@ -1974,7 +1979,8 @@ gfc_get_derived_type (gfc_symbol * deriv
       if (c->ts.type != BT_DERIVED)
 	continue;
 
-      if (!c->attr.pointer || c->ts.derived->backend_decl == NULL)
+      if ((!c->attr.pointer && !c->attr.proc_pointer)
+	  || c->ts.derived->backend_decl == NULL)
 	c->ts.derived->backend_decl = gfc_get_derived_type (c->ts.derived);
 
       if (c->ts.derived && c->ts.derived->attr.is_iso_c)
@@ -2003,10 +2009,10 @@ gfc_get_derived_type (gfc_symbol * deriv
   fieldlist = NULL_TREE;
   for (c = derived->components; c; c = c->next)
     {
-      if (c->ts.type == BT_DERIVED)
-        field_type = c->ts.derived->backend_decl;
-      else if (c->attr.proc_pointer)
+      if (c->attr.proc_pointer)
 	field_type = gfc_get_ppc_type (c);
+      else if (c->ts.type == BT_DERIVED)
+        field_type = c->ts.derived->backend_decl;
       else
 	{
 	  if (c->ts.type == BT_CHARACTER)
Comment 2 janus 2009-07-28 11:40:58 UTC
Subject: Bug 40882

Author: janus
Date: Tue Jul 28 11:40:42 2009
New Revision: 150154

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=150154
Log:
2009-07-28  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/40882
	* trans-types.c (gfc_get_ppc_type): For derived types, directly use the
	backend_decl, instead of calling gfc_typenode_for_spec, to avoid
	infinte loop.
	(gfc_get_derived_type): Correctly handle PPCs returning derived types,
	avoiding infinite recursion.


2009-07-28  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/40882
	* gfortran.dg/proc_ptr_comp_13.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/proc_ptr_comp_13.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-types.c
    trunk/gcc/testsuite/ChangeLog

Comment 3 janus 2009-07-28 12:14:08 UTC
Fixed with r150154. Closing.