diff options
author | jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4> | 2009-07-23 18:09:43 +0000 |
---|---|---|
committer | jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4> | 2009-07-23 18:09:43 +0000 |
commit | 3506b33fb392a4177653c120138be8da0b28f71a (patch) | |
tree | e2355295ba4f503f046c98f919798986a5d39dbd /gcc/fortran/io.c | |
parent | 28f14b30c50e2859f5cfec61c292f781f58616a8 (diff) | |
download | gcc-3506b33fb392a4177653c120138be8da0b28f71a.tar.gz |
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.
* gfortran.dg/pr40839.f90: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@150021 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/fortran/io.c')
-rw-r--r-- | gcc/fortran/io.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/gcc/fortran/io.c b/gcc/fortran/io.c index ea562923f05..76cf6199abe 100644 --- a/gcc/fortran/io.c +++ b/gcc/fortran/io.c @@ -2555,7 +2555,7 @@ gfc_free_dt (gfc_dt *dt) /* 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; @@ -2576,6 +2576,12 @@ gfc_resolve_dt (gfc_dt *dt) 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))) @@ -2635,6 +2641,7 @@ gfc_resolve_dt (gfc_dt *dt) && 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 @@ -2857,6 +2864,7 @@ match_io_element (io_kind k, gfc_code **cpp) 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", @@ -2870,7 +2878,8 @@ match_io_element (io_kind k, gfc_code **cpp) 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)) |