From: Harald Anlauf Date: Mon, 6 Jul 2020 16:52:39 +0000 (+0200) Subject: PR fortran/95709 - ICE in gfc_resolve_code, at fortran/resolve.c:11807 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=824084e72e388f81015e7f67922c75f50741355a;p=gcc.git 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. --- diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 9c178d07e53..e8ba48770f7 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -11815,10 +11815,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); diff --git a/gcc/testsuite/gfortran.dg/pr95709.f90 b/gcc/testsuite/gfortran.dg/pr95709.f90 new file mode 100644 index 00000000000..e5876067524 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr95709.f90 @@ -0,0 +1,14 @@ +! { 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