[Bug fortran/88249] ICE in gfc_resolve_filepos, at fortran/io.c:2853
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88249 kargl at gcc dot gnu.org changed: What|Removed |Added Priority|P3 |P4 Status|UNCONFIRMED |NEW Last reconfirmed||2018-11-30 Ever confirmed|0 |1 --- Comment #1 from kargl at gcc dot gnu.org --- (In reply to G. Steinmetz from comment #0) > With a missing file-unit-number, down to at least gcc-5 : > > > $ cat z1.f90 > program p >backspace (err=1) >endfile (err=1) >flush (err=1) >rewind (err=1) > end > > > $ gfortran-9-20181125 -c z1.f90 > f951: internal compiler error: Segmentation fault > 0xb2bcff crash_signal > ../../gcc/toplev.c:326 > 0x63f696 gfc_resolve_filepos(gfc_filepos*) > ../../gcc/fortran/io.c:2853 > 0x6850ab gfc_resolve_code(gfc_code*, gfc_namespace*) > ../../gcc/fortran/resolve.c:11547 > 0x68702f resolve_codes Index: gcc/fortran/resolve.c === --- gcc/fortran/resolve.c (revision 266386) +++ gcc/fortran/resolve.c (working copy) @@ -11544,7 +11544,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); Index: gcc/fortran/io.c === --- gcc/fortran/io.c(revision 266386) +++ gcc/fortran/io.c(working copy) @@ -2834,22 +2834,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)
[Bug fortran/88249] ICE in gfc_resolve_filepos, at fortran/io.c:2853
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88249 kargl at gcc dot gnu.org changed: What|Removed |Added CC||kargl at gcc dot gnu.org --- Comment #2 from kargl at gcc dot gnu.org --- Better. Index: gcc/fortran/gfortran.h === --- gcc/fortran/gfortran.h (revision 266386) +++ gcc/fortran/gfortran.h (working copy) @@ -3374,7 +3374,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 *); Index: gcc/fortran/resolve.c === --- gcc/fortran/resolve.c (revision 266386) +++ gcc/fortran/resolve.c (working copy) @@ -11544,7 +11544,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); Index: gcc/fortran/io.c === --- gcc/fortran/io.c(revision 266386) +++ gcc/fortran/io.c(working copy) @@ -2834,22 +2834,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)
[Bug fortran/88249] ICE in gfc_resolve_filepos, at fortran/io.c:2853
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88249 --- Comment #3 from kargl at gcc dot gnu.org --- Author: kargl Date: Tue Dec 11 23:13:19 2018 New Revision: 267035 URL: https://gcc.gnu.org/viewcvs?rev=267035&root=gcc&view=rev Log: 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. Added: trunk/gcc/testsuite/gfortran.dg/pr88249.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/gfortran.h trunk/gcc/fortran/io.c trunk/gcc/fortran/resolve.c trunk/gcc/testsuite/ChangeLog
[Bug fortran/88249] ICE in gfc_resolve_filepos, at fortran/io.c:2853
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88249 --- Comment #4 from kargl at gcc dot gnu.org --- Author: kargl Date: Tue Dec 11 23:39:43 2018 New Revision: 267036 URL: https://gcc.gnu.org/viewcvs?rev=267036&root=gcc&view=rev Log: 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. Added: branches/gcc-8-branch/gcc/testsuite/gfortran.dg/pr88249.f90 Modified: branches/gcc-8-branch/gcc/fortran/ChangeLog branches/gcc-8-branch/gcc/fortran/gfortran.h branches/gcc-8-branch/gcc/fortran/io.c branches/gcc-8-branch/gcc/fortran/resolve.c branches/gcc-8-branch/gcc/testsuite/ChangeLog
[Bug fortran/88249] ICE in gfc_resolve_filepos, at fortran/io.c:2853
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88249 --- Comment #5 from kargl at gcc dot gnu.org --- Author: kargl Date: Wed Dec 12 00:08:12 2018 New Revision: 267037 URL: https://gcc.gnu.org/viewcvs?rev=267037&root=gcc&view=rev Log: 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. Added: branches/gcc-7-branch/gcc/testsuite/gfortran.dg/pr88249.f90 Modified: branches/gcc-7-branch/gcc/fortran/ChangeLog branches/gcc-7-branch/gcc/fortran/gfortran.h branches/gcc-7-branch/gcc/fortran/io.c branches/gcc-7-branch/gcc/fortran/resolve.c branches/gcc-7-branch/gcc/testsuite/ChangeLog
[Bug fortran/88249] ICE in gfc_resolve_filepos, at fortran/io.c:2853
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88249 kargl at gcc dot gnu.org changed: What|Removed |Added Status|NEW |RESOLVED Resolution|--- |FIXED Assignee|unassigned at gcc dot gnu.org |kargl at gcc dot gnu.org Target Milestone|--- |7.5 --- Comment #6 from kargl at gcc dot gnu.org --- Fixed on trunk, branch-8, and branch-7. Closing.