When FLUSH is used with a flulsh-spec-list, a unit is required. Thus, a statement like 'flush(iostat=i)' would lead to an ICE because gfortran was dereference a pointer to a non-existant unit number. The attached patch was built and tested on x86-*-freebsd. OK to commit?
2015-09-30 Steven G. Kargl <ka...@gcc.gnu.org> * io.c (gfc_resolve_filepos): Check for a UNIT number. Add a nearby missing 'return false'. 2015-09-30 Steven G. Kargl <ka...@gcc.gnu.org> gfortran.dg/pr66979.f90: new test. -- Steve
Index: fortran/io.c =================================================================== --- fortran/io.c (revision 228306) +++ fortran/io.c (working copy) @@ -2515,12 +2515,21 @@ gfc_resolve_filepos (gfc_filepos *fp) if (!gfc_reference_st_label (fp->err, ST_LABEL_TARGET)) return false; + if (!fp->unit && (fp->iostat || fp->iomsg)) + { + locus where; + where = fp->iostat ? fp->iostat->where : fp->iomsg->where; + gfc_error ("UNIT number missing in statement at %L", &where); + return false; + } + if (fp->unit->expr_type == EXPR_CONSTANT && fp->unit->ts.type == BT_INTEGER && mpz_sgn (fp->unit->value.integer) < 0) { gfc_error ("UNIT number in statement at %L must be non-negative", &fp->unit->where); + return false; } return true; Index: testsuite/gfortran.dg/pr66979.f90 =================================================================== --- testsuite/gfortran.dg/pr66979.f90 (revision 0) +++ testsuite/gfortran.dg/pr66979.f90 (working copy) @@ -0,0 +1,7 @@ +! { dg-do compile } +! PR fortran/66979 +program p + implicit none + integer::i + flush (iostat=i) ! { dg-error "UNIT number missing" } +end program p