Handle EXEC_IOLENGTH in doloop_contained_procedure_code.
authorThomas Koenig <tkoenig@gcc.gnu.org>
Mon, 15 Mar 2021 10:02:02 +0000 (11:02 +0100)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Mon, 15 Mar 2021 10:02:02 +0000 (11:02 +0100)
This rather obvious patch fixes an ICE on valid which came about
because I did not handle EXEC_IOLENGTH as start of an I/O statement
when checking for the DO loop variable.  This is an 11 regression.

gcc/fortran/ChangeLog:

PR fortran/99345
* frontend-passes.c (doloop_contained_procedure_code):
Properly handle EXEC_IOLENGTH.

gcc/testsuite/ChangeLog:

PR fortran/99345
* gfortran.dg/do_check_16.f90: New test.
* gfortran.dg/do_check_17.f90: New test.

gcc/fortran/frontend-passes.c
gcc/testsuite/gfortran.dg/do_check_16.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/do_check_17.f90 [new file with mode: 0644]

index 2b9c2d1..cfc4747 100644 (file)
@@ -2405,6 +2405,7 @@ doloop_contained_procedure_code (gfc_code **c,
     case EXEC_READ:
     case EXEC_WRITE:
     case EXEC_INQUIRE:
+    case EXEC_IOLENGTH:
       saved_io_op = last_io_op;
       last_io_op = co->op;
       break;
@@ -2460,6 +2461,12 @@ doloop_contained_procedure_code (gfc_code **c,
                           info->procedure->name, &info->where_do);
          break;
 
+       case EXEC_IOLENGTH:
+         if (co->expr1 && co->expr1->symtree->n.sym == do_var)
+           gfc_error_now (errmsg, do_var->name, &co->expr1->where,
+                          info->procedure->name, &info->where_do);
+         break;
+
        default:
          gcc_unreachable ();
        }
diff --git a/gcc/testsuite/gfortran.dg/do_check_16.f90 b/gcc/testsuite/gfortran.dg/do_check_16.f90
new file mode 100644 (file)
index 0000000..db0d45c
--- /dev/null
@@ -0,0 +1,13 @@
+! { dg-do compile }
+program main
+  implicit none
+  integer :: iq,nq,recl
+  DO iq = 1, nq
+     call foobar  ! { dg-error "redefined" }     
+  ENDDO  
+CONTAINS
+
+  subroutine foobar
+    inquire (iolength=nq) iq ! { dg-error "redefined" }
+  end subroutine foobar
+END program main
diff --git a/gcc/testsuite/gfortran.dg/do_check_17.f90 b/gcc/testsuite/gfortran.dg/do_check_17.f90
new file mode 100644 (file)
index 0000000..02b8993
--- /dev/null
@@ -0,0 +1,16 @@
+! { dg-do compile }
+! PR 99345 - this used to cause an ICE.
+! Original test case by Matthias Klose
+program main
+  implicit none
+  integer :: iq,nq,recl
+  DO iq = 1, nq
+     CALL calc_upper_fan (iq)
+  ENDDO  
+CONTAINS
+  SUBROUTINE calc_upper_fan (iq)
+    INTEGER :: iq
+    INTEGER :: recl
+    INQUIRE(IOLENGTH=recl) iq
+  END SUBROUTINE calc_upper_fan
+END