+2009-07-23 Jakub Jelinek <jakub@redhat.com>
+
+ PR fortran/40839
+ * io.c (gfc_resolve_dt): Add LOC argument. Fail if
+ dt->io_unit is NULL. Return FAILURE after issuing error about
+ negative UNIT number.
+ (match_io_element): Don't segfault if current_dt->io_unit is NULL.
+ * gfortran.h (gfc_resolve_dt): Adjust prototype.
+ * resolve.c (resolve_code): Adjust caller.
+
2009-07-22 Paul Thomas <pault@gcc.gnu.org>
PR fortran/40796
void gfc_free_inquire (gfc_inquire *);
gfc_try gfc_resolve_inquire (gfc_inquire *);
void gfc_free_dt (gfc_dt *);
-gfc_try gfc_resolve_dt (gfc_dt *);
+gfc_try gfc_resolve_dt (gfc_dt *, locus *);
void gfc_free_wait (gfc_wait *);
gfc_try gfc_resolve_wait (gfc_wait *);
/* Resolve everything in a gfc_dt structure. */
gfc_try
-gfc_resolve_dt (gfc_dt *dt)
+gfc_resolve_dt (gfc_dt *dt, locus *loc)
{
gfc_expr *e;
RESOLVE_TAG (&tag_e_async, dt->asynchronous);
e = dt->io_unit;
+ if (e == NULL)
+ {
+ gfc_error ("UNIT not specified at %L", loc);
+ return FAILURE;
+ }
+
if (gfc_resolve_expr (e) == SUCCESS
&& (e->ts.type != BT_INTEGER
&& (e->ts.type != BT_CHARACTER || e->expr_type != EXPR_VARIABLE)))
&& mpz_sgn (e->value.integer) < 0)
{
gfc_error ("UNIT number in statement at %L must be non-negative", &e->where);
+ return FAILURE;
}
if (dt->extra_comma
if (gfc_pure (NULL)
&& gfc_impure_variable (expr->symtree->n.sym)
+ && current_dt->io_unit
&& current_dt->io_unit->ts.type == BT_CHARACTER)
{
gfc_error ("Cannot read to variable '%s' in PURE procedure at %C",
break;
case M_WRITE:
- if (current_dt->io_unit->ts.type == BT_CHARACTER
+ if (current_dt->io_unit
+ && current_dt->io_unit->ts.type == BT_CHARACTER
&& gfc_pure (NULL)
&& current_dt->io_unit->expr_type == EXPR_VARIABLE
&& gfc_impure_variable (current_dt->io_unit->symtree->n.sym))
case EXEC_READ:
case EXEC_WRITE:
- if (gfc_resolve_dt (code->ext.dt) == FAILURE)
+ if (gfc_resolve_dt (code->ext.dt, &code->loc) == FAILURE)
break;
resolve_branch (code->ext.dt->err, code);
+2009-07-23 Jakub Jelinek <jakub@redhat.com>
+
+ PR fortran/40839
+ * gfortran.dg/pr40839.f90: New test.
+
2009-07-23 Michael Matz <matz@suse.de>
PR middle-end/40830
--- /dev/null
+! PR fortran/40839
+! { dg-do compile }
+write(fmt='(a)'), 'abc' ! { dg-error "UNIT not specified" }
+write(fmt='()') ! { dg-error "UNIT not specified" }
+end