From: Steven G. Kargl Date: Tue, 1 Oct 2019 19:21:05 +0000 (+0000) Subject: [multiple changes] X-Git-Tag: releases/gcc-9.3.0~583 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a68dbdc9d923ab5849ed1ffca2762d6df7bb793b;p=thirdparty%2Fgcc.git [multiple changes] 2019-10-01 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-10-01 Steven G. Kargl PR fortran/91864 * gcc/testsuite/gfortran.dg/pr91864.f90 From-SVN: r276425 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 691bca48e151..7e7e24c35fe6 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,12 @@ +2019-10-01 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-10-01 Steven G. Kargl Backport of r276254+276265 diff --git a/gcc/fortran/io.c b/gcc/fortran/io.c index 9bee9094e7f8..4b0426f8f997 100644 --- a/gcc/fortran/io.c +++ b/gcc/fortran/io.c @@ -3608,7 +3608,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 @@ -3618,7 +3628,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 2d91a2bbace4..efc0c2d7bc31 100644 --- a/gcc/fortran/match.c +++ b/gcc/fortran/match.c @@ -4219,6 +4219,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; @@ -4351,6 +4357,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; @@ -4627,6 +4639,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 949fa2f10c53..f6095aba8fdd 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-10-01 Steven G. Kargl + + PR fortran/91864 + * gcc/testsuite/gfortran.dg/pr91864.f90 + 2019-10-01 Steven G. Kargl PR fortran/91802 diff --git a/gcc/testsuite/gfortran.dg/pr91864.f90 b/gcc/testsuite/gfortran.dg/pr91864.f90 new file mode 100644 index 000000000000..a17187dcdc0f --- /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