From: Steven G. Kargl Date: Wed, 2 Oct 2019 17:04:57 +0000 (+0000) Subject: re PR fortran/91942 (ICE in match_vtag, at fortran/io.c:1485) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=939e9f696b843f2c6472ac0fd541399e2b3faa7e;p=gcc.git re PR fortran/91942 (ICE in match_vtag, at fortran/io.c:1485) 2019-10-02 Steven G. Kargl PR fortran/91942 * io.c (match_vtag): Check for non-NULL result->symtree. (match_out_tag): Check for invalid constant due to inquiry parameter. (match_filepos): Instead of a syntax error, go to cleanup to get better error messages. 2019-10-02 Steven G. Kargl PR fortran/91942 * gfortran.dg/pr91587.f90: Update dg-error regex. * gfortran.dg/pr91942.f90: New test. From-SVN: r276472 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index f225ff2ced6..476973d5cf2 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,11 @@ +2019-10-02 Steven G. Kargl + + PR fortran/91942 + * io.c (match_vtag): Check for non-NULL result->symtree. + (match_out_tag): Check for invalid constant due to inquiry parameter. + (match_filepos): Instead of a syntax error, go to cleanup to get better + error messages. + 2019-10-02 Steven G. Kargl PR fortran/91943 diff --git a/gcc/fortran/io.c b/gcc/fortran/io.c index 9ae06b1f5c4..b969a1a4738 100644 --- a/gcc/fortran/io.c +++ b/gcc/fortran/io.c @@ -1482,24 +1482,29 @@ match_vtag (const io_tag *tag, gfc_expr **v) return MATCH_ERROR; } - if (result->symtree->n.sym->attr.intent == INTENT_IN) + if (result->symtree) { - gfc_error ("Variable %s cannot be INTENT(IN) at %C", tag->name); - gfc_free_expr (result); - return MATCH_ERROR; - } + bool impure; - bool impure = gfc_impure_variable (result->symtree->n.sym); - if (impure && gfc_pure (NULL)) - { - gfc_error ("Variable %s cannot be assigned in PURE procedure at %C", - tag->name); - gfc_free_expr (result); - return MATCH_ERROR; - } + if (result->symtree->n.sym->attr.intent == INTENT_IN) + { + gfc_error ("Variable %s cannot be INTENT(IN) at %C", tag->name); + gfc_free_expr (result); + return MATCH_ERROR; + } + + impure = gfc_impure_variable (result->symtree->n.sym); + if (impure && gfc_pure (NULL)) + { + gfc_error ("Variable %s cannot be assigned in PURE procedure at %C", + tag->name); + gfc_free_expr (result); + return MATCH_ERROR; + } - if (impure) - gfc_unset_implicit_pure (NULL); + if (impure) + gfc_unset_implicit_pure (NULL); + } *v = result; return MATCH_YES; @@ -1515,7 +1520,16 @@ match_out_tag (const io_tag *tag, gfc_expr **result) m = match_vtag (tag, result); if (m == MATCH_YES) - gfc_check_do_variable ((*result)->symtree); + { + if ((*result)->symtree) + gfc_check_do_variable ((*result)->symtree); + + if ((*result)->expr_type == EXPR_CONSTANT) + { + gfc_error ("Expecting a variable at %L", &(*result)->where); + return MATCH_ERROR; + } + } return m; } @@ -2845,7 +2859,7 @@ match_filepos (gfc_statement st, gfc_exec_op op) m = match_file_element (fp); if (m == MATCH_ERROR) - goto syntax; + goto cleanup; if (m == MATCH_NO) { m = gfc_match_expr (&fp->unit); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3256a02f7a0..88e4d32695b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2019-10-02 Steven G. Kargl + + PR fortran/91942 + * gfortran.dg/pr91587.f90: Update dg-error regex. + * gfortran.dg/pr91942.f90: New test. + 2019-10-02 Steven G. Kargl PR fortran/91943 diff --git a/gcc/testsuite/gfortran.dg/pr91587.f90 b/gcc/testsuite/gfortran.dg/pr91587.f90 index c07735df65e..c304be116c0 100644 --- a/gcc/testsuite/gfortran.dg/pr91587.f90 +++ b/gcc/testsuite/gfortran.dg/pr91587.f90 @@ -2,9 +2,9 @@ ! PR fortran/91587 ! Code contributed by Gerhard Steinmetz program p - backspace(err=!) ! { dg-error "Syntax error in" } - flush(err=!) ! { dg-error "Syntax error in" } - rewind(err=!) ! { dg-error "Syntax error in" } + backspace(err=!) ! { dg-error "Invalid value for" } + flush(err=!) ! { dg-error "Invalid value for" } + rewind(err=!) ! { dg-error "Invalid value for" } end subroutine bar ! An other matcher runs, and gives a different error. diff --git a/gcc/testsuite/gfortran.dg/pr91942.f90 b/gcc/testsuite/gfortran.dg/pr91942.f90 new file mode 100644 index 00000000000..cd237d38660 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr91942.f90 @@ -0,0 +1,10 @@ +! { dg-do compile } +! PR fortran/91942 +! Code contributed by Gerhard Steinmetz +program p + integer :: i + backspace (iostat=i%kind) ! { dg-error "Expecting a variable at" } + endfile (iostat=i%kind) ! { dg-error "Expecting END PROGRAM" } + flush (iostat=i%kind) ! { dg-error "Expecting a variable at" } + rewind (iostat=i%kind) ! { dg-error "Expecting a variable at" } +end