From cdeb16cbf2c388432fa4672d37d87ee55878de13 Mon Sep 17 00:00:00 2001 From: Janus Weil Date: Fri, 9 Dec 2016 14:21:44 +0100 Subject: [PATCH] re PR fortran/61767 ([OOP] ICE in generate_finalization_wrapper at fortran/class.c:1491) 2016-12-09 Janus Weil PR fortran/61767 * class.c (has_finalizer_component): Fix this function to detect only non-pointer non-allocatable components which have a finalizer. 2016-12-09 Janus Weil PR fortran/61767 * gfortran.dg/finalize_31.f90: New test. From-SVN: r243483 --- gcc/fortran/ChangeLog | 6 +++++ gcc/fortran/class.c | 27 ++++++++++---------- gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/gfortran.dg/finalize_31.f90 | 30 +++++++++++++++++++++++ 4 files changed, 54 insertions(+), 14 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/finalize_31.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 23421639671..819f5ef9156 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2016-12-09 Janus Weil + + PR fortran/61767 + * class.c (has_finalizer_component): Fix this function to detect only + non-pointer non-allocatable components which have a finalizer. + 2016-12-09 Andre Vehreschild PR fortran/78505 diff --git a/gcc/fortran/class.c b/gcc/fortran/class.c index e59b87cdeae..1fba6c93072 100644 --- a/gcc/fortran/class.c +++ b/gcc/fortran/class.c @@ -841,20 +841,19 @@ has_finalizer_component (gfc_symbol *derived) gfc_component *c; for (c = derived->components; c; c = c->next) - { - if (c->ts.type == BT_DERIVED && c->ts.u.derived->f2k_derived - && c->ts.u.derived->f2k_derived->finalizers) - return true; - - /* Stop infinite recursion through this function by inhibiting - calls when the derived type and that of the component are - the same. */ - if (c->ts.type == BT_DERIVED - && !gfc_compare_derived_types (derived, c->ts.u.derived) - && !c->attr.pointer && !c->attr.allocatable - && has_finalizer_component (c->ts.u.derived)) - return true; - } + if (c->ts.type == BT_DERIVED && !c->attr.pointer && !c->attr.allocatable) + { + if (c->ts.u.derived->f2k_derived + && c->ts.u.derived->f2k_derived->finalizers) + return true; + + /* Stop infinite recursion through this function by inhibiting + calls when the derived type and that of the component are + the same. */ + if (!gfc_compare_derived_types (derived, c->ts.u.derived) + && has_finalizer_component (c->ts.u.derived)) + return true; + } return false; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 49146a3b6b3..3f169367138 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-12-09 Janus Weil + + PR fortran/61767 + * gfortran.dg/finalize_31.f90: New test. + 2016-12-09 Andre Vehreschild PR fortran/78505 diff --git a/gcc/testsuite/gfortran.dg/finalize_31.f90 b/gcc/testsuite/gfortran.dg/finalize_31.f90 new file mode 100644 index 00000000000..8817a4f6365 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/finalize_31.f90 @@ -0,0 +1,30 @@ +! { dg-do run } +! +! PR 61767: [OOP] ICE in generate_finalization_wrapper at fortran/class.c:1491 +! +! Contributed by + +module Communicator_Form + implicit none + type :: CommunicatorForm + contains + final :: Finalize + end type + type :: MessageTemplate + type ( CommunicatorForm ), pointer :: Communicator + end type +contains + subroutine Finalize ( C ) + type ( CommunicatorForm ) :: C + ! should not be called + call abort() + end subroutine +end module + +program p + use Communicator_Form + implicit none + class ( MessageTemplate ), pointer :: M + allocate(M) + deallocate(M) +end -- 2.30.2