[Bug fortran/107872] ICE on recursive DT with DTIO since r7-4096-gbf9f15ee55f5b291

pault at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Nov 28 10:01:06 GMT 2022


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

--- Comment #3 from Paul Thomas <pault at gcc dot gnu.org> ---
Created attachment 53975
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53975&action=edit
Fix for this PR

This is a trivial bug. The ICE is occurring in resolve.cc(derived_inaccessible)
because derived types with recursive allocatable components have not been
allowed for.

With the patch, the test below does the right thing.

I am tied up with my finalization work at present. If somebody else wishes to
commit the patch, be my guest.

With a pointer component, the test runs correctly back to gfortran 7.4.1
20191027.

Cheers

Paul

! { dg-do run }
!
! Test the fix for PR107872, where an ICE occurred in
resolve.cc(derived_inaccessible)
! because derived types with recursive allocatable components were not catered
for.
!
module mod1
    type t
        integer :: data
        type(t), allocatable :: next
    contains
        procedure, private :: write_t
        generic :: write(formatted) => write_t
    end type
contains
    recursive subroutine write_t(this, unit, iotype, v_list, iostat, iomsg)
        class(t), intent(in) :: this
        integer, intent(in) :: unit
        character(*), intent(in) :: iotype
        integer, intent(in) :: v_list(:)
        integer, intent(out) :: iostat
        character(*), intent(inout) :: iomsg
        if (ALLOCATED(this%next)) &
            write (unit, '(dt)') this%next
            write (unit, '(i2)') this%data
    end subroutine
end module

  use mod1
  type(t) :: a
  character (8) :: buffer
  a%data = 1
  allocate (a%next)
  a%next%data = 2
  allocate (a%next%next)
  a%next%next%data = 3
  write (buffer, '(dt)')a
  deallocate (a%next)
  if (trim (buffer) .ne. ' 3 2 1') stop 1
end


More information about the Gcc-bugs mailing list