From 006fda1b17a4d55b6548a1b3bd7efd0d8e40b6c4 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Mon, 6 Jul 2020 18:52:39 +0200 Subject: [PATCH] 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) --- gcc/fortran/resolve.c | 16 ++++++++++++---- gcc/testsuite/gfortran.dg/pr95709.f90 | 12 ++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr95709.f90 diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 35f09e01f87a..11bb65c41e52 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -11480,10 +11480,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 000000000000..04f2da819885 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr95709.f90 @@ -0,0 +1,12 @@ +! { dg-do compile } +! { dg-options "-std=legacy" } +! PR fortran/95709 - ICE in gfc_resolve_code, at fortran/resolve.c:11807 + +program p + integer, parameter :: j = 1 + integer :: k(1) = 1 + goto j ! { dg-error "requires a scalar INTEGER variable" } + goto k(1) ! { dg-error "requires a scalar INTEGER variable" } + goto k%kind, (1) ! { dg-error "requires a scalar INTEGER variable" } +1 continue +end -- 2.43.5