This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug fortran/81499] New: internal compiler error when compiling gfortran code with user-defined derived type i/o


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81499

            Bug ID: 81499
           Summary: internal compiler error when compiling gfortran code
                    with user-defined derived type i/o
           Product: gcc
           Version: 7.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kenneth.c.hall at duke dot edu
  Target Milestone: ---

I have some fortran code with a derived type that includes pointers, as well as
user defined derived type i/o.  The code compiles and works correctly if I omit
the user defined derived type i/o, or even if it is included but no write
statement is included that would use the usddtio. But if both are present, the
compiler gives the error:

    gfortran: internal compiler error: Segmentation fault: 11 (program f951)
    Please submit a full bug report,
    with preprocessed source if appropriate.
    See <https://gcc.gnu.org/bugs/> for instructions.

I have simplified the code to the smallest unit that will produce the error;
that code is included at the bottom of these comments.

The code was compiled using the command:

    gfortran -o test_bug test_bug.f90 -Wall -Wextra -std=f2008 -save-temps

Unfortunately, the resulting test_bug.s file is empty.

I am running MAC OS X 10.11.4 (15E65). gfortran -v gives:

    Using built-in specs.
    COLLECT_GCC=gfortran
   
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-apple-darwin15.6.0/7.1.0/lto-wrapper
    Target: x86_64-apple-darwin15.6.0
    Configured with: ../gcc-7.1.0/configure --enable-languages=c++,fortran
    Thread model: posix
    gcc version 7.1.0 (GCC) 

One interesting thing is that if the read/write statements are NAMELIST, then
everything works as it should -- the code compiles and runs.  But if the
read/write statements are DT or LISTDIRECTED, then the compilation fails.   

Here is the input file the code reads, which should be named "input":

1.0
2.0
3.0
4.0
&test_nml
dtv1 = 10.0   
dtv2 = 20.0   
dtv3 = 30.0   
not_dtv=40.0
/

Here is the code, which I have named "test_bug.f90":

!====================================================================================================
!====================================================================================================
   module test_module
      implicit none

      type                              :: tape_node_type
         real (kind = 4)                :: val  = 0.0
         type (tape_type), pointer      :: ref  => null()  !  if this line is
commented out, the code will compile
      end type tape_node_type
      type                              :: tape_type
         type (tape_node_type), pointer :: tape => null()
      contains
      end type tape_type

      interface write(formatted)
         module procedure writeformatted
      end interface
      interface read(formatted)
         module procedure readformatted
      end interface

    contains

      subroutine writeformatted (dtv, unit, iotype, v_list, iostat, iomsg)

         class(tape_type) ,  intent(in)      :: dtv
         integer(kind=4)  ,  intent(in)      :: unit
         character(len=*) ,  intent(in)      :: iotype
         integer          ,  intent(in)      :: v_list(:)
         integer(kind=4)  ,  intent(out)     :: iostat
         character(len=*) ,  intent(inout)   :: iomsg
         iostat = 0
         write(unit,fmt=*,iostat=iostat,iomsg=iomsg) dtv%tape%val
      end subroutine writeformatted

      subroutine readformatted(dtv, unit, iotype, v_list, iostat, iomsg)

         class (tape_type),  intent(inout)   :: dtv
         integer (kind=4) ,  intent(in)      :: unit
         character (len=*),  intent(in)      :: iotype
         integer          ,  intent(in)      :: v_list(:)
         integer (kind=4) ,  intent(out)     :: iostat
         character (len=*),  intent(inout)   :: iomsg
         real :: x
         iostat = 0
         if (.not.associated(dtv%tape)) then
            allocate(dtv%tape)
         end if

         read(unit,fmt=*,iostat=iostat,iomsg=iomsg) dtv%tape%val
      end subroutine readformatted
!
      end module test_module
!====================================================================================================
!==================================================================================================== 
      program main
         use test_module
         type (tape_type),target :: dtv1,dtv2,dtv3
         real :: not_dtv
         namelist /test_nml/ dtv1,dtv2,dtv3,not_dtv

         open (unit=1,file='input',form='formatted')
         read (1,fmt='(dt)', ADVANCE='NO') dtv1   ! if these four lines are
commented out, the code will compile
         write(*,fmt='(dt)') dtv1                 ! if these four lines are
commented out, the code will compile
         read (1,*) dtv1                          ! if these four lines are
commented out, the code will compile
         write(*,*) dtv1                          ! if these four lines are
commented out, the code will compile
         read (1,nml=test_nml)                    ! this line is OK!
         write(*,nml=test_nml)                    ! this line is OK!
      end program main

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]