PR fortran/95709 - [9/10/11 Regression] ICE in gfc_resolve_code, at fortran/resolve.c:11807

Message ID trinity-2929439c-322b-4eb3-be7d-9f11cfbb6bb7-1593722476492@3c-app-gmx-bs71
State New
Headers show
Series
  • PR fortran/95709 - [9/10/11 Regression] ICE in gfc_resolve_code, at fortran/resolve.c:11807
Related show

Commit Message

Harald Anlauf July 2, 2020, 8:41 p.m.
The obsolescent (=legacy) assigned GOTO should only allow scalar integer
variables.  Check for proper conditions.

Regtested on x86_64-pc-linux-gnu.

OK for master / backports?

Thanks,
Harald


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
	asigned GOTO.

Comments

Harald Anlauf July 3, 2020, 8:30 p.m. | #1
> The obsolescent (=legacy) assigned GOTO should only allow scalar integer

> variables.  Check for proper conditions.


I've played around some more with invalid uses of assigned GOTO and found
that some cases produced a suboptimal error message.  The attached patch
(v2) improves upon this and provides a slightly larger testcase.

Again regtested on x86_64-pc-linux-gnu.

OK for master / backports?

Thanks,
Harald

> 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.

>
Thomas Koenig July 6, 2020, 6:54 a.m. | #2
Hi Harald,

> OK for master / backports?


OK.  Thanks for the patch!

Regards

	Thomas

Patch

diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 5cc9f72e55c..34b1b80c31e 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -11814,10 +11814,13 @@  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->ts.type != BT_INTEGER
+		  || code->expr1->rank != 0
+		  || code->expr1->symtree == NULL)
+		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..6acd6fd14e6
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr95709.f90
@@ -0,0 +1,10 @@ 
+! { 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
+  goto i(1)        ! { dg-error "requires a scalar INTEGER variable" }
+  goto i%kind, (1) ! { dg-error "requires a scalar INTEGER variable" }
+1 continue
+end