From 7e703f019b351ceb6c68da23bde1e1754746e1f2 Mon Sep 17 00:00:00 2001 From: Thomas Koenig Date: Mon, 18 Mar 2019 07:28:42 +0000 Subject: [PATCH] re PR fortran/88008 (ICE in check_typebound_baseobject, at fortran/resolve.c:6058) 2019-03-17 Thomas Koenig PR fortran/88008 * gfortran.h (expr_t): Add EXPR_UNKNOWN. * expr.c (gfc_copy_expr): Add EXPR_UNKNOWN to switch statement. (gfc_simplify_expr): Likewise. * module.c (mio_expr): Likewise. * resovle.c (extract_compcall_passed_object): Issue error on unknown type. (check_typebound_baseobject): Issue error on wrong type. * trans-expr.c (gfc_apply_interface_mapping_to_expr): Add EXPR_UNKNOWN to switch statement. 2019-03-17 Thomas Koenig PR fortran/88008 * gfortran.dg/typebound_call_31.f90: New test. From-SVN: r269750 --- gcc/fortran/ChangeLog | 13 +++++++++++++ gcc/fortran/expr.c | 6 ++++++ gcc/fortran/gfortran.h | 2 +- gcc/fortran/module.c | 1 + gcc/fortran/resolve.c | 13 ++++++++++++- gcc/fortran/trans-expr.c | 1 + gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/typebound_call_31.f90 | 16 ++++++++++++++++ 8 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/typebound_call_31.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 762da701b00..8028118c97c 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,16 @@ +2019-03-17 Thomas Koenig + + PR fortran/88008 + * gfortran.h (expr_t): Add EXPR_UNKNOWN. + * expr.c (gfc_copy_expr): Add EXPR_UNKNOWN to switch statement. + (gfc_simplify_expr): Likewise. + * module.c (mio_expr): Likewise. + * resovle.c (extract_compcall_passed_object): Issue error on + unknown type. + (check_typebound_baseobject): Issue error on wrong type. + * trans-expr.c (gfc_apply_interface_mapping_to_expr): Add + EXPR_UNKNOWN to switch statement. + 2019-03-16 Jakub Jelinek PR fortran/89724 diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index d654f4e74d0..4c76f539031 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -390,6 +390,9 @@ gfc_copy_expr (gfc_expr *p) case EXPR_VARIABLE: case EXPR_NULL: break; + + case EXPR_UNKNOWN: + gcc_unreachable (); } q->shape = gfc_copy_shape (p->shape, p->rank); @@ -2206,6 +2209,9 @@ gfc_simplify_expr (gfc_expr *p, int type) case EXPR_COMPCALL: case EXPR_PPC: break; + + case EXPR_UNKNOWN: + gcc_unreachable (); } return true; diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index dd959e6403e..2f55b9c387a 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -142,7 +142,7 @@ enum gfc_source_form /* Expression node types. */ enum expr_t -{ EXPR_OP = 1, EXPR_FUNCTION, EXPR_CONSTANT, EXPR_VARIABLE, + { EXPR_UNKNOWN = 0, EXPR_OP = 1, EXPR_FUNCTION, EXPR_CONSTANT, EXPR_VARIABLE, EXPR_SUBSTRING, EXPR_STRUCTURE, EXPR_ARRAY, EXPR_NULL, EXPR_COMPCALL, EXPR_PPC }; diff --git a/gcc/fortran/module.c b/gcc/fortran/module.c index 0572b8e02c1..0c2699c1260 100644 --- a/gcc/fortran/module.c +++ b/gcc/fortran/module.c @@ -3694,6 +3694,7 @@ mio_expr (gfc_expr **ep) case EXPR_COMPCALL: case EXPR_PPC: + case EXPR_UNKNOWN: gcc_unreachable (); break; } diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 62c7d376b92..7539aa7038c 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -5945,6 +5945,13 @@ extract_compcall_passed_object (gfc_expr* e) { gfc_expr* po; + if (e->expr_type == EXPR_UNKNOWN) + { + gfc_error ("Error in typebound call at %L", + &e->where); + return NULL; + } + gcc_assert (e->expr_type == EXPR_COMPCALL); if (e->value.compcall.base_object) @@ -6090,7 +6097,11 @@ check_typebound_baseobject (gfc_expr* e) if (!base) return false; - gcc_assert (base->ts.type == BT_DERIVED || base->ts.type == BT_CLASS); + if (base->ts.type != BT_DERIVED && base->ts.type != BT_CLASS) + { + gfc_error ("Error in typebound call at %L", &e->where); + goto cleanup; + } if (base->ts.type == BT_CLASS && !gfc_expr_attr (base).class_ok) return false; diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index 9575f391abd..3cd2ffa722d 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -4536,6 +4536,7 @@ gfc_apply_interface_mapping_to_expr (gfc_interface_mapping * mapping, case EXPR_COMPCALL: case EXPR_PPC: + case EXPR_UNKNOWN: gcc_unreachable (); break; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 131ef49ee68..ecb99628167 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-03-17 Thomas Koenig + + PR fortran/88008 + * gfortran.dg/typebound_call_31.f90: New test. + 2019-03-03-17 John David Anglin * gcc.dg/compat/pr83487-1_x.c: Use -fno-common option on hppa*-*-hpux*. diff --git a/gcc/testsuite/gfortran.dg/typebound_call_31.f90 b/gcc/testsuite/gfortran.dg/typebound_call_31.f90 new file mode 100644 index 00000000000..b33bbf1c52f --- /dev/null +++ b/gcc/testsuite/gfortran.dg/typebound_call_31.f90 @@ -0,0 +1,16 @@ +! { dg-do compile } +! PR 88008 - this use to ICE. Original test case by +! Gerhard Steinmetz. + +module m + type t + integer, pointer :: z + contains + procedure :: g + end type +contains + subroutine g(x) + class(t) :: x + call x%z%g() ! { dg-error "Error in typebound call" } + end +end -- 2.30.2