Fortran: Fix DTIO with type ICE [PR99146]
authorTobias Burnus <tobias@codesourcery.com>
Fri, 19 Feb 2021 17:05:31 +0000 (18:05 +0100)
committerTobias Burnus <tobias@codesourcery.com>
Fri, 19 Feb 2021 17:05:31 +0000 (18:05 +0100)
gcc/fortran/ChangeLog:

PR fortran/99146
* interface.c:

gcc/testsuite/ChangeLog:

PR fortran/99146
* gfortran.dg/dtio_36.f90: New test.

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

index 87fe14280e62fa9c3a7e8017f08056af3dd15319..f7ca52e6550a957d16461b93c3221004ebf87dcf 100644 (file)
@@ -5305,7 +5305,9 @@ gfc_find_specific_dtio_proc (gfc_symbol *derived, bool write, bool formatted)
     }
 
 finish:
-  if (dtio_sub && derived != CLASS_DATA (dtio_sub->formal->sym)->ts.u.derived)
+  if (dtio_sub
+      && dtio_sub->formal->sym->ts.type == BT_CLASS
+      && derived != CLASS_DATA (dtio_sub->formal->sym)->ts.u.derived)
     gfc_find_derived_vtab (derived);
 
   return dtio_sub;
diff --git a/gcc/testsuite/gfortran.dg/dtio_36.f90 b/gcc/testsuite/gfortran.dg/dtio_36.f90
new file mode 100644 (file)
index 0000000..4e53581
--- /dev/null
@@ -0,0 +1,33 @@
+! { dg-do compile }
+!
+! PR fortran/99146
+!
+      MODULE p
+      TYPE :: person
+      sequence
+      END TYPE person
+      INTERFACE READ(UNFORMATTED)
+       MODULE PROCEDURE pruf
+      END INTERFACE
+
+      CONTAINS
+
+      SUBROUTINE pruf (dtv,unit,iostat,iomsg)
+       type(person), INTENT(INOUT) :: dtv
+       INTEGER, INTENT(IN) :: unit
+       INTEGER, INTENT(OUT) :: iostat
+       CHARACTER (LEN=*), INTENT(INOUT) :: iomsg
+       iostat = 1
+      END SUBROUTINE pruf
+
+      END MODULE p
+
+      PROGRAM test
+      USE p
+      TYPE (person) :: chairman
+
+      OPEN (UNIT=71, status = 'scratch', FORM='UNFORMATTED')
+
+      read(71) chairman
+
+      END PROGRAM test