From 3d07fb21d2aaf83548efc4f7ca42fc9deb4028b6 Mon Sep 17 00:00:00 2001 From: "Steven G. Kargl" Date: Tue, 11 Dec 2018 23:13:19 +0000 Subject: [PATCH] re PR fortran/88249 (ICE in gfc_resolve_filepos, at fortran/io.c:2853) 2018-12-11 Steven G. Kargl PR fortran/88249 * gfortran.h: Update prototype for gfc_resolve_filepos(). * io.c (gfc_resolve_filepos): Check for UNIT number if ERR= is present. Use passed in locus for error message. * resolve.c (gfc_resolve_code): Pass locus in gfc_resolve_filepos() call. 2018-12-11 Steven G. Kargl PR fortran/88249 * gfortran.dg/pr88249.f90: New test. From-SVN: r267035 --- gcc/fortran/ChangeLog | 9 +++++++++ gcc/fortran/gfortran.h | 2 +- gcc/fortran/io.c | 13 ++++++------- gcc/fortran/resolve.c | 2 +- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/pr88249.f90 | 7 +++++++ 6 files changed, 29 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr88249.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index f5e397946e1..945bb23e369 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,12 @@ +2018-12-11 Steven G. Kargl + + PR fortran/88249 + * gfortran.h: Update prototype for gfc_resolve_filepos(). + * io.c (gfc_resolve_filepos): Check for UNIT number if ERR= is present. + Use passed in locus for error message. + * resolve.c (gfc_resolve_code): Pass locus in gfc_resolve_filepos() + call. + 2018-12-10 Steven G. Kargl PR fortran/97922 diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index a14b4c44a18..fd0bc36fee1 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -3395,7 +3395,7 @@ bool gfc_resolve_open (gfc_open *); void gfc_free_close (gfc_close *); bool gfc_resolve_close (gfc_close *); void gfc_free_filepos (gfc_filepos *); -bool gfc_resolve_filepos (gfc_filepos *); +bool gfc_resolve_filepos (gfc_filepos *, locus *); void gfc_free_inquire (gfc_inquire *); bool gfc_resolve_inquire (gfc_inquire *); void gfc_free_dt (gfc_dt *); diff --git a/gcc/fortran/io.c b/gcc/fortran/io.c index 8415df1c68e..9c3e6892a07 100644 --- a/gcc/fortran/io.c +++ b/gcc/fortran/io.c @@ -2849,22 +2849,21 @@ cleanup: bool -gfc_resolve_filepos (gfc_filepos *fp) +gfc_resolve_filepos (gfc_filepos *fp, locus *where) { RESOLVE_TAG (&tag_unit, fp->unit); RESOLVE_TAG (&tag_iostat, fp->iostat); RESOLVE_TAG (&tag_iomsg, fp->iomsg); - if (!gfc_reference_st_label (fp->err, ST_LABEL_TARGET)) - return false; - if (!fp->unit && (fp->iostat || fp->iomsg)) + if (!fp->unit && (fp->iostat || fp->iomsg || fp->err)) { - locus where; - where = fp->iostat ? fp->iostat->where : fp->iomsg->where; - gfc_error ("UNIT number missing in statement at %L", &where); + gfc_error ("UNIT number missing in statement at %L", where); return false; } + if (!gfc_reference_st_label (fp->err, ST_LABEL_TARGET)) + return false; + if (fp->unit->expr_type == EXPR_CONSTANT && fp->unit->ts.type == BT_INTEGER && mpz_sgn (fp->unit->value.integer) < 0) diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index f4bf84b3349..dd705ed1bbf 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -11545,7 +11545,7 @@ start: case EXEC_ENDFILE: case EXEC_REWIND: case EXEC_FLUSH: - if (!gfc_resolve_filepos (code->ext.filepos)) + if (!gfc_resolve_filepos (code->ext.filepos, &code->loc)) break; resolve_branch (code->ext.filepos->err, code); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 36c4232bf2b..8c04149484c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-12-11 Steven G. Kargl + + PR fortran/88249 + * gfortran.dg/pr88249.f90: New test. + 2018-12-11 Jakub Jelinek PR tree-optimization/80520 diff --git a/gcc/testsuite/gfortran.dg/pr88249.f90 b/gcc/testsuite/gfortran.dg/pr88249.f90 new file mode 100644 index 00000000000..401fb3514e7 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr88249.f90 @@ -0,0 +1,7 @@ +! { dg-do compile } +program p + backspace (err=1) ! { dg-error "UNIT number missing" } + endfile (err=1) ! { dg-error "UNIT number missing" } + flush (err=1) ! { dg-error "UNIT number missing" } + rewind (err=1) ! { dg-error "UNIT number missing" } +end -- 2.30.2