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

janus at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |janus at gcc dot gnu.org

--- Comment #3 from janus at gcc dot gnu.org ---
Further reduced test case:


MODULE test_nesting_mod
  IMPLICIT NONE
  TYPE :: test_obj1
  CONTAINS
    PROCEDURE :: destroy
  END TYPE

  TYPE :: obj_ptr
    CLASS(test_obj1), POINTER :: f => NULL()
  END TYPE

  TYPE :: obj_container
    TYPE(obj_ptr), POINTER, DIMENSION(:) :: v => NULL()
  END TYPE

CONTAINS

  SUBROUTINE destroy(self)
    CLASS(test_obj1), INTENT(INOUT) :: self
    WRITE(*,*)'Obj1'
  END SUBROUTINE

  SUBROUTINE container_destroy(self)
    type(obj_container), INTENT(INOUT) :: self
    INTEGER :: i
    DO i=1,ubound(self%v,1)
      CALL self%v(i)%f%destroy()
    END DO
  END SUBROUTINE

END MODULE


PROGRAM test_nesting_ptr
  USE test_nesting_mod
  IMPLICIT NONE
  INTEGER :: i
  INTEGER, PARAMETER :: n = 2
  TYPE(obj_container) :: var

  ALLOCATE(var%v(n))
  DO i=1,n
    ALLOCATE(test_obj1::var%v(i)%f)
  END DO
  CALL container_destroy(var)
END


This one does not always segfault, but when compiled with trunk and -O3,
valgrind reliably shows the error:


==24015== Invalid read of size 8
==24015==    at 0x400989: __test_nesting_mod_MOD_container_destroy
(test.f90:27)
==24015==    by 0x40075C: test_nesting_ptr (test.f90:45)
==24015==    by 0x40075C: main (test.f90:35)


When compiled with gfortran 8 and -O3, valgrind only shows:

==24605== Use of uninitialised value of size 8
==24605==    at 0x108B65: __test_nesting_mod_MOD_container_destroy
(test.f90:27)
==24605==    by 0x108912: test_nesting_ptr (test.f90:45)
==24605==    by 0x108912: main (test.f90:35)


When compiled with gfortran 7, valgrind shows no errors. Both errors above
reference the line where 'destroy' is called.

Reply via email to