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);
--- /dev/null
+! { 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