PR fortran/95709 - ICE in gfc_resolve_code, at fortran/resolve.c:11807
authorHarald Anlauf <anlauf@gmx.de>
Mon, 6 Jul 2020 16:52:39 +0000 (18:52 +0200)
committerHarald Anlauf <anlauf@gmx.de>
Mon, 6 Jul 2020 16:52:39 +0000 (18:52 +0200)
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.

gcc/fortran/resolve.c
gcc/testsuite/gfortran.dg/pr95709.f90 [new file with mode: 0644]

index 9c178d07e53c7e4e66984a3fc981ca895d043f6a..e8ba48770f7982facc4c004407033bf09288a8c1 100644 (file)
@@ -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 (file)
index 0000000..e587606
--- /dev/null
@@ -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