From 036aa59282d3084076e78216c6ba8e5291dc29f7 Mon Sep 17 00:00:00 2001 From: "Steven G. Kargl" Date: Sat, 28 Sep 2019 16:26:43 +0000 Subject: [PATCH] re PR fortran/91864 (ICE in gfc_check_do_variable, at fortran/parse.c:4405) 2019-09-28 Steven G. Kargl PR fortran/91864 * gcc/fortran/io.c (match_io_element): An inquiry parameter cannot be read into. * gcc/fortran/match.c (gfc_match_allocate): An inquiry parameter can be neither an allocate-object nor stat variable. (gfc_match_deallocate): An inquiry parameter cannot be deallocated. 2019-09-28 Steven G. Kargl PR fortran/91864 * gcc/testsuite/gfortran.dg/pr91864.f90 From-SVN: r276253 --- gcc/fortran/ChangeLog | 9 +++++++++ gcc/fortran/io.c | 13 +++++++++++-- gcc/fortran/match.c | 18 ++++++++++++++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/pr91864.f90 | 22 ++++++++++++++++++++++ 5 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr91864.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 1c1997f..d5a17da 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,12 @@ +2019-09-28 Steven G. Kargl + + PR fortran/91864 + * gcc/fortran/io.c (match_io_element): An inquiry parameter cannot be + read into. + * gcc/fortran/match.c (gfc_match_allocate): An inquiry parameter + can be neither an allocate-object nor stat variable. + (gfc_match_deallocate): An inquiry parameter cannot be deallocated. + 2019-09-26 Alessandro Fanfarillo * trans-array.c (structure_alloc_comps): diff --git a/gcc/fortran/io.c b/gcc/fortran/io.c index bb64560..9ae06b1 100644 --- a/gcc/fortran/io.c +++ b/gcc/fortran/io.c @@ -3657,7 +3657,17 @@ match_io_element (io_kind k, gfc_code **cpp) { m = gfc_match_variable (&expr, 0); if (m == MATCH_NO) - gfc_error ("Expected variable in READ statement at %C"); + { + gfc_error ("Expecting variable in READ statement at %C"); + m = MATCH_ERROR; + } + + if (m == MATCH_YES && expr->expr_type == EXPR_CONSTANT) + { + gfc_error ("Expecting variable or io-implied-do in READ statement " + "at %L", &expr->where); + m = MATCH_ERROR; + } if (m == MATCH_YES && expr->expr_type == EXPR_VARIABLE @@ -3667,7 +3677,6 @@ match_io_element (io_kind k, gfc_code **cpp) &expr->where); m = MATCH_ERROR; } - } else { diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c index 9b9dbf1..83b1189 100644 --- a/gcc/fortran/match.c +++ b/gcc/fortran/match.c @@ -4242,6 +4242,12 @@ gfc_match_allocate (void) if (m == MATCH_ERROR) goto cleanup; + if (tail->expr->expr_type == EXPR_CONSTANT) + { + gfc_error ("Unexpected constant at %C"); + goto cleanup; + } + if (gfc_check_do_variable (tail->expr->symtree)) goto cleanup; @@ -4374,6 +4380,12 @@ alloc_opt_list: tmp = NULL; saw_stat = true; + if (stat->expr_type == EXPR_CONSTANT) + { + gfc_error ("STAT tag at %L cannot be a constant", &stat->where); + goto cleanup; + } + if (gfc_check_do_variable (stat->symtree)) goto cleanup; @@ -4650,6 +4662,12 @@ gfc_match_deallocate (void) if (m == MATCH_NO) goto syntax; + if (tail->expr->expr_type == EXPR_CONSTANT) + { + gfc_error ("Unexpected constant at %C"); + goto cleanup; + } + if (gfc_check_do_variable (tail->expr->symtree)) goto cleanup; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ecdce9b..8d8ba5d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-09-28 Steven G. Kargl + + PR fortran/91864 + * gcc/testsuite/gfortran.dg/pr91864.f90 + 2019-09-28 Marek Polacek PR c++/91889 - follow-up fix for DR 2352. diff --git a/gcc/testsuite/gfortran.dg/pr91864.f90 b/gcc/testsuite/gfortran.dg/pr91864.f90 new file mode 100644 index 0000000..a17187d --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr91864.f90 @@ -0,0 +1,22 @@ +program p + integer :: i + read (*,*) i%kind ! { dg-error "Expecting variable or io-implied-do" } +end + +subroutine t + integer, allocatable :: x(:) + integer :: stat + allocate (x(3), stat=stat%kind) ! { dg-error "cannot be a constant" } +end + +subroutine u + integer, allocatable :: x(:) + integer :: stat + allocate (x(3), stat%kind=stat) ! { dg-error "Unexpected constant" } +end + +subroutine v + integer, allocatable :: x(:) + integer :: stat + deallocate (x, stat%kind=stat) ! { dg-error "Unexpected constant" } +end -- 2.7.4