From 40109581065366e04c547d2bff6e8f7ff5646fb8 Mon Sep 17 00:00:00 2001 From: Janus Weil Date: Wed, 30 Nov 2016 10:50:04 +0100 Subject: [PATCH] re PR fortran/78592 (ICE in gfc_find_specific_dtio_proc, at fortran/interface.c:4939) 2016-11-30 Janus Weil PR fortran/78592 * interface.c (gfc_find_specific_dtio_proc): Rearrange code to avoid dereferencing a null pointer. 2016-11-30 Janus Weil PR fortran/78592 * gfortran.dg/dtio_18.f90: New test case. From-SVN: r243005 --- gcc/fortran/ChangeLog | 6 ++++++ gcc/fortran/interface.c | 14 +++++++------- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/dtio_18.f90 | 15 +++++++++++++++ 4 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/dtio_18.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 840eb8f17b8..3b4799abdaa 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2016-11-30 Janus Weil + + PR fortran/78592 + * interface.c (gfc_find_specific_dtio_proc): Rearrange code to avoid + dereferencing a null pointer. + 2016-11-30 Janus Weil PR fortran/78573 diff --git a/gcc/fortran/interface.c b/gcc/fortran/interface.c index f5d3f7762ca..8afba84a697 100644 --- a/gcc/fortran/interface.c +++ b/gcc/fortran/interface.c @@ -4933,15 +4933,15 @@ gfc_find_specific_dtio_proc (gfc_symbol *derived, bool write, bool formatted) && tb_io_st->n.sym && tb_io_st->n.sym->generic) { - gfc_interface *intr; - for (intr = tb_io_st->n.sym->generic; intr; intr = intr->next) + for (gfc_interface *intr = tb_io_st->n.sym->generic; + intr && intr->sym && intr->sym->formal; + intr = intr->next) { gfc_symbol *fsym = intr->sym->formal->sym; - if (intr->sym && intr->sym->formal - && ((fsym->ts.type == BT_CLASS - && CLASS_DATA (fsym)->ts.u.derived == extended) - || (fsym->ts.type == BT_DERIVED - && fsym->ts.u.derived == extended))) + if ((fsym->ts.type == BT_CLASS + && CLASS_DATA (fsym)->ts.u.derived == extended) + || (fsym->ts.type == BT_DERIVED + && fsym->ts.u.derived == extended)) { dtio_sub = intr->sym; break; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3074e6d05a5..3ed27c4c235 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-11-30 Janus Weil + + PR fortran/78592 + * gfortran.dg/dtio_18.f90: New test case. + 2016-11-30 Martin Liska PR sanitizer/78541 diff --git a/gcc/testsuite/gfortran.dg/dtio_18.f90 b/gcc/testsuite/gfortran.dg/dtio_18.f90 new file mode 100644 index 00000000000..cc85ba5ed06 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/dtio_18.f90 @@ -0,0 +1,15 @@ +! { dg-do compile } +! +! PR 78592: [7 Regression] ICE in gfc_find_specific_dtio_proc, at fortran/interface.c:4939 +! +! Contributed by Gerhard Steinmetz + +program p + type t + end type + type(t) :: z + interface write(formatted) + module procedure wf ! { dg-error "is neither function nor subroutine" } + end interface + print *, z +end -- 2.30.2