Commit 17327d6c by Harald Anlauf

PR fortran/95709 - ICE in gfc_resolve_code, at fortran/resolve.c:11807

The legacy "assigned GOTO" accepts only scalar integer variables.
Check for proper arguments.

gcc/fortran/
	PR fortran/95709
	* resolve.c (gfc_resolve_code): Check for valid arguments to
	assigned GOTO.

(cherry picked from commit 824084e72e388f81015e7f67922c75f50741355a)
parent b7f84beb
......@@ -11801,10 +11801,18 @@ start:
case EXEC_GOTO:
if (code->expr1 != NULL)
{
if (code->expr1->ts.type != BT_INTEGER)
gfc_error ("ASSIGNED GOTO statement at %L requires an "
"INTEGER variable", &code->expr1->where);
else if (code->expr1->symtree->n.sym->attr.assign != 1)
if (code->expr1->expr_type != EXPR_VARIABLE
|| code->expr1->ts.type != BT_INTEGER
|| (code->expr1->ref
&& code->expr1->ref->type == REF_ARRAY)
|| code->expr1->symtree == NULL
|| (code->expr1->symtree->n.sym
&& (code->expr1->symtree->n.sym->attr.flavor
== FL_PARAMETER)))
gfc_error ("ASSIGNED GOTO statement at %L requires a "
"scalar INTEGER variable", &code->expr1->where);
else if (code->expr1->symtree->n.sym
&& code->expr1->symtree->n.sym->attr.assign != 1)
gfc_error ("Variable %qs has not been assigned a target "
"label at %L", code->expr1->symtree->n.sym->name,
&code->expr1->where);
......
! { dg-do compile }
! { dg-options "-std=legacy" }
! PR fortran/95709 - ICE in gfc_resolve_code, at fortran/resolve.c:11807
program p
integer, parameter :: i(1) = 1
integer, parameter :: j = 1
integer :: k(1) = 1
goto i(1) ! { dg-error "requires a scalar INTEGER variable" }
goto j ! { dg-error "requires a scalar INTEGER variable" }
goto k(1) ! { dg-error "requires a scalar INTEGER variable" }
goto i%kind, (1) ! { dg-error "requires a scalar INTEGER variable" }
1 continue
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