https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86328
Bug ID: 86328 Summary: Runtime segfault reading an allocatable class(*) object in allocate statements Product: gcc Version: 8.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: mscfd at gmx dot net Target Milestone: --- The following code leads to a runtime segfault: program ptr_alloc type :: t class(*), allocatable :: val end type t type :: list type(t), dimension(:), pointer :: ll integer :: cnt end type list integer :: i type(list) :: a allocate(a%ll(1:1)) do i = 1,10 print *,i a%cnt = i allocate(a%ll(i)%val, source=i) call rrr(a) end do contains subroutine rrr(a) type(list) :: a integer :: s, i type(t), dimension(:), pointer :: mm s = ubound(a%ll,1) + 1 allocate(mm(1:s)) do i = 1, s-1 if (allocated(a%ll(i)%val)) then allocate(mm(i)%val, source=a%ll(i)%val) ! allocate(mm(i)%val, mold=a%ll(i)%val) ! mm(i)%val = a%ll(i)%val deallocate(a%ll(i)%val) end if end do deallocate(a%ll) a%ll => mm end subroutine rrr end program ptr_alloc Using the commented mold and assignment version also leads to a segfault. Using allocation on assignment (just the commented assignment) works, but then the deallocation statement fails with a segfault. valgrind reports an "Invalid read of size 8".