https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124661
--- Comment #4 from Mikael Morin <mikael at gcc dot gnu.org> ---
(In reply to Christopher Albert from comment #3)
> Created attachment 64058 [details]
> Proposed patch
>
> Proposed patch attached. Reproduced on current trunk. The fix keeps the
> saved descriptor reference alive across the INDIRECT_REF walk in
> set_factored_descriptor_value and then uses that factored descriptor for the
> later data and offset accesses in gfc_conv_ss_descriptor. The reproducer now
> runs clean with -fcheck=bounds. I also reran make check-gfortran
> RUNTESTFLAGS="dg.exp=pr124661.f90", make check-gfortran
> RUNTESTFLAGS="dg.exp=assign_14.f90", and a full check-gfortran run with 0
> FAIL / XPASS.
Here is a variant that fails similarly, even with the patch:
module tools
implicit none
type point_t
real :: coords(1:3)
end type point_t
type intermediary_t
type(point_t), allocatable :: ac(:)
end type intermediary_t
type point_cloud_t
type(intermediary_t), allocatable :: points(:)
contains
procedure :: init_point_cloud
end type point_cloud_t
contains
subroutine init_point_cloud(c)
class(point_cloud_t) :: c
allocate (c%points(1))
allocate (c%points(1)%ac(1))
print *, c%points(1)%ac(1)%coords(3) ! <-- ok
print *, c%points(1)%ac(1)%coords ! <-- SIGSEGV with
-fcheck=bounds
end subroutine init_point_cloud
end module tools
program scatci_integrals
use tools, only: point_cloud_t
implicit none
type(point_cloud_t) :: c
call c%init_point_cloud
end program scatci_integrals