Hi all,

the attached patch fixes an ICE-on-valid regression, where the
compiler runs into an infinite loop if a derived type contains a
procedure-pointer component which has a polymorphic result of the
original type.

We already have a piece of code which prevents the infinite loop for
TYPE-valued PPCs, but it doesn't work for CLASS results, which is
fixed by the patch here.

Ok for trunk and the 5/6 branches?

Cheers,
Janus



2017-04-17  Janus Weil  <ja...@gcc.gnu.org>

    PR fortran/80392
    * trans-types.c (gfc_get_derived_type): Prevent an infinite loop when
    building a derived type that includes a procedure pointer component
    with a polymorphic result.

2017-04-17  Janus Weil  <ja...@gcc.gnu.org>

    PR fortran/80392
    * gfortran.dg/proc_ptr_comp_49.f90: New test case.
Index: gcc/fortran/trans-types.c
===================================================================
--- gcc/fortran/trans-types.c   (revision 246939)
+++ gcc/fortran/trans-types.c   (working copy)
@@ -2617,9 +2617,10 @@ gfc_get_derived_type (gfc_symbol * derived, int co
         the same as derived, by forcing the procedure pointer component to
         be built as if the explicit interface does not exist.  */
       if (c->attr.proc_pointer
-         && ((c->ts.type != BT_DERIVED && c->ts.type != BT_CLASS)
-              || (c->ts.u.derived
-                  && !gfc_compare_derived_types (derived, c->ts.u.derived))))
+         && (c->ts.type != BT_DERIVED || (c->ts.u.derived
+                   && !gfc_compare_derived_types (derived, c->ts.u.derived)))
+         && (c->ts.type != BT_CLASS || (CLASS_DATA (c)->ts.u.derived
+                   && !gfc_compare_derived_types (derived, CLASS_DATA 
(c)->ts.u.derived))))
        field_type = gfc_get_ppc_type (c);
       else if (c->attr.proc_pointer && derived->backend_decl)
        {
! { dg-do compile }
!
! PR 80392: [5/6/7 Regression] [OOP] ICE with allocatable polymorphic function result in a procedure pointer component
!
! Contributed by <zed.th...@gmail.com>

module mwe

  implicit none

  type :: MyType
     procedure(my_op), nopass, pointer :: op
  end type

contains

  function my_op() result(foo)
    class(MyType), allocatable :: foo
  end function

end module

Reply via email to