https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91864
kargl at gcc dot gnu.org changed: What |Removed |Added ---------------------------------------------------------------------------- Priority|P3 |P4 Status|UNCONFIRMED |NEW Last reconfirmed| |2019-09-23 CC| |kargl at gcc dot gnu.org Ever confirmed|0 |1 --- Comment #2 from kargl at gcc dot gnu.org --- This fixes the ICEs Index: gcc/fortran/io.c =================================================================== --- gcc/fortran/io.c (revision 276019) +++ gcc/fortran/io.c (working copy) @@ -3660,14 +3660,14 @@ match_io_element (io_kind k, gfc_code **cpp) gfc_error ("Expected variable in READ statement at %C"); if (m == MATCH_YES - && expr->expr_type == EXPR_VARIABLE - && expr->symtree->n.sym->attr.external) + && ((expr->expr_type == EXPR_VARIABLE + && expr->symtree->n.sym->attr.external) + || expr->expr_type == EXPR_CONSTANT)) { gfc_error ("Expecting variable or io-implied-do at %L", &expr->where); m = MATCH_ERROR; } - } else { Index: gcc/fortran/match.c =================================================================== --- gcc/fortran/match.c (revision 276019) +++ gcc/fortran/match.c (working copy) @@ -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; @@ -4649,6 +4661,12 @@ gfc_match_deallocate (void) goto cleanup; 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; Index: gcc/testsuite/gfortran.dg/pr91864.f90 =================================================================== --- gcc/testsuite/gfortran.dg/pr91864.f90 (nonexistent) +++ gcc/testsuite/gfortran.dg/pr91864.f90 (working copy) @@ -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