Commit 7fd4d312 by Tobias Schlüter Committed by Tobias Schlüter

re PR fortran/23420 (ICE on invalid print statement)

fortran/
	PR fortran/23420
	* io.c (resolve_tag): Don't allow non-CHARACTER constants as formats.
	(match_io): Fix usage of gfc_find_symbol.
testsuite/
	PR fortran/23420
	* gfortran.dg/print_fmt_4.f: New.

From-SVN: r104454
parent 7a4ef45b
2005-09-20 Tobias Schl"uter <tobias.schlueter@physik.uni-muenchen.de>
PR fortran/23420
* io.c (resolve_tag): Don't allow non-CHARACTER constants as formats.
(match_io): Fix usage of gfc_find_symbol.
2005-09-20 Jakub Jelinek <jakub@redhat.com> 2005-09-20 Jakub Jelinek <jakub@redhat.com>
PR fortran/23663 PR fortran/23663
......
...@@ -979,6 +979,15 @@ resolve_tag (const io_tag * tag, gfc_expr * e) ...@@ -979,6 +979,15 @@ resolve_tag (const io_tag * tag, gfc_expr * e)
if (tag == &tag_format) if (tag == &tag_format)
{ {
if (e->expr_type == EXPR_CONSTANT
&& (e->ts.type != BT_CHARACTER
|| e->ts.kind != gfc_default_character_kind))
{
gfc_error ("Constant expression in FORMAT tag at %L must be "
"of type default CHARACTER", &e->where);
return FAILURE;
}
/* If e's rank is zero and e is not an element of an array, it should be /* If e's rank is zero and e is not an element of an array, it should be
of integer or character type. The integer variable should be of integer or character type. The integer variable should be
ASSIGNED. */ ASSIGNED. */
...@@ -2158,51 +2167,51 @@ match_io (io_kind k) ...@@ -2158,51 +2167,51 @@ match_io (io_kind k)
comma_flag = 0; comma_flag = 0;
current_dt = dt = gfc_getmem (sizeof (gfc_dt)); current_dt = dt = gfc_getmem (sizeof (gfc_dt));
if (gfc_match_char ('(') == MATCH_NO) if (gfc_match_char ('(') == MATCH_NO)
{ {
where = gfc_current_locus;
if (k == M_WRITE) if (k == M_WRITE)
goto syntax; goto syntax;
else if (k == M_PRINT else if (k == M_PRINT)
&& (gfc_current_form == FORM_FIXED
|| gfc_peek_char () == ' '))
{ {
/* Treat the non-standard case of PRINT namelist. */ /* Treat the non-standard case of PRINT namelist. */
where = gfc_current_locus; if ((gfc_current_form == FORM_FIXED || gfc_peek_char () == ' ')
if ((gfc_match_name (name) == MATCH_YES) && gfc_match_name (name) == MATCH_YES)
&& !gfc_find_symbol (name, NULL, 1, &sym)
&& sym->attr.flavor == FL_NAMELIST)
{ {
if (gfc_notify_std (GFC_STD_GNU, "PRINT namelist at " gfc_find_symbol (name, NULL, 1, &sym);
"%C is an extension") == FAILURE) if (sym && sym->attr.flavor == FL_NAMELIST)
{ {
m = MATCH_ERROR; if (gfc_notify_std (GFC_STD_GNU, "PRINT namelist at "
goto cleanup; "%C is an extension") == FAILURE)
{
m = MATCH_ERROR;
goto cleanup;
}
if (gfc_match_eos () == MATCH_NO)
{
gfc_error ("Namelist followed by I/O list at %C");
m = MATCH_ERROR;
goto cleanup;
}
dt->io_unit = default_unit (k);
dt->namelist = sym;
goto get_io_list;
} }
if (gfc_match_eos () == MATCH_NO) else
{ gfc_current_locus = where;
gfc_error ("Namelist followed by I/O list at %C");
m = MATCH_ERROR;
goto cleanup;
}
dt->io_unit = default_unit (k);
dt->namelist = sym;
goto get_io_list;
} }
else
gfc_current_locus = where;
} }
if (gfc_current_form == FORM_FREE) if (gfc_current_form == FORM_FREE)
{ {
c = gfc_peek_char(); c = gfc_peek_char();
if (c != ' ' && c != '*' && c != '\'' && c != '"') if (c != ' ' && c != '*' && c != '\'' && c != '"')
{ {
m = MATCH_NO; m = MATCH_NO;
goto cleanup; goto cleanup;
} }
} }
m = match_dt_format (dt); m = match_dt_format (dt);
if (m == MATCH_ERROR) if (m == MATCH_ERROR)
...@@ -2240,17 +2249,20 @@ match_io (io_kind k) ...@@ -2240,17 +2249,20 @@ match_io (io_kind k)
where = gfc_current_locus; where = gfc_current_locus;
if (gfc_match_name (name) == MATCH_YES m = gfc_match_name (name);
&& !gfc_find_symbol (name, NULL, 1, &sym) if (m == MATCH_YES)
&& sym->attr.flavor == FL_NAMELIST)
{ {
dt->namelist = sym; gfc_find_symbol (name, NULL, 1, &sym);
if (k == M_READ && check_namelist (sym)) if (sym && sym->attr.flavor == FL_NAMELIST)
{ {
m = MATCH_ERROR; dt->namelist = sym;
goto cleanup; if (k == M_READ && check_namelist (sym))
{
m = MATCH_ERROR;
goto cleanup;
}
goto next;
} }
goto next;
} }
gfc_current_locus = where; gfc_current_locus = where;
......
2005-09-20 Tobias Schl"uter <tobias.schlueter@physik.uni-muenchen.de>
PR fortran/23420
* gfortran.dg/print_fmt_4.f: New.
2005-09-20 Jakub Jelinek <jakub@redhat.com> 2005-09-20 Jakub Jelinek <jakub@redhat.com>
PR fortran/23663 PR fortran/23663
! { dg-do compile }
print precision(1.) ! { dg-error "must be of type default CHARACTER" }
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment