From f79be3a7dbf8d9cd7e675918472ebc3c2c9d5e47 Mon Sep 17 00:00:00 2001 From: Paul Thomas Date: Mon, 2 Sep 2019 19:54:02 +0000 Subject: [PATCH] re PR fortran/91589 (ICE in gfc_conv_component_ref, at fortran/trans-expr.c:2447) 2019-09-02 Paul Thomas PR fortran/91589 * primary.c (gfc_match_varspec): Return MATCH_NO on an apparent component ref, when the primary type is intrinsic. 2019-09-02 Paul Thomas PR fortran/91589 * gfortran.dg/pr91589.f90 : New test. From-SVN: r275324 --- gcc/fortran/ChangeLog | 6 ++++++ gcc/fortran/primary.c | 15 ++++++++++++--- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/pr91589.f90 | 15 +++++++++++++++ 4 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr91589.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index b0dfb0e7da4..065099a62d9 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2019-09-02 Paul Thomas + + PR fortran/91589 + * primary.c (gfc_match_varspec): Return MATCH_NO on an apparent + component ref, when the primary type is intrinsic. + 2019-09-02 Steven G. Kargl PR fortran/91552 diff --git a/gcc/fortran/primary.c b/gcc/fortran/primary.c index a33a7972f13..e94ea821ba7 100644 --- a/gcc/fortran/primary.c +++ b/gcc/fortran/primary.c @@ -2028,6 +2028,7 @@ gfc_match_varspec (gfc_expr *primary, int equiv_flag, bool sub_flag, match m; bool unknown; bool inquiry; + bool intrinsic; locus old_loc; char sep; @@ -2232,11 +2233,15 @@ gfc_match_varspec (gfc_expr *primary, int equiv_flag, bool sub_flag, if (m != MATCH_YES) return MATCH_ERROR; + intrinsic = false; if (primary->ts.type != BT_CLASS && primary->ts.type != BT_DERIVED) { inquiry = is_inquiry_ref (name, &tmp); if (inquiry) sym = NULL; + + if (sep == '%' && primary->ts.type != BT_UNKNOWN) + intrinsic = true; } else inquiry = false; @@ -2296,12 +2301,16 @@ gfc_match_varspec (gfc_expr *primary, int equiv_flag, bool sub_flag, break; } - if (!inquiry) + if (!inquiry && !intrinsic) component = gfc_find_component (sym, name, false, false, &tmp); else component = NULL; - if (component == NULL && !inquiry) + /* In some cases, returning MATCH_NO gives a better error message. Most + cases return "Unclassifiable statement at..." */ + if (intrinsic && !inquiry) + return MATCH_NO; + else if (component == NULL && !inquiry) return MATCH_ERROR; /* Extend the reference chain determined by gfc_find_component or @@ -2598,7 +2607,7 @@ gfc_variable_attr (gfc_expr *expr, gfc_typespec *ts) case AR_UNKNOWN: /* For standard conforming code, AR_UNKNOWN should not happen. - For nonconforming code, gfortran can end up here. Treat it + For nonconforming code, gfortran can end up here. Treat it as a no-op. */ break; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c2608ce8db4..2f93d91dcac 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-09-02 Paul Thomas + + PR fortran/91589 + * gfortran.dg/pr91589.f90 : New test. + 2019-09-02 Steven G. Kargl PR fortran/91552 diff --git a/gcc/testsuite/gfortran.dg/pr91589.f90 b/gcc/testsuite/gfortran.dg/pr91589.f90 new file mode 100644 index 00000000000..d02cb64bfc2 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr91589.f90 @@ -0,0 +1,15 @@ +! { dg-do compile } +! +! Check the fix for PR91589, in which the invalid expression caused an ICE. +! Other statements using this invalid expression cause "Unclassifiable statement at..." +! +! Contributed by Gerhardt Steinmetz +! +program p + type t + integer :: a + end type + type(t) :: x = t(1) + call sub (x%a%a) ! { dg-error "Syntax error in argument list" } +end + -- 2.30.2