https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87659
Bug ID: 87659 Summary: Memory corruption in array component of intent(in) unlimited polymorphic with optimization Product: gcc Version: 8.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: damian at sourceryinstitute dot org Target Milestone: --- The following bug disappears if the pointer intent is switched to intent(out) or if the optimization level is dropped to -O0: $ cat all.f90 module vectors implicit none type vector integer, allocatable :: elements(:) end type contains subroutine set_elements(input) class(*), pointer, intent(in) :: input select type (input) type is (vector) input%elements=[2] end select end subroutine end module implicit none call set_vector contains subroutine set_vector() use vectors type (vector), target :: v class(*), pointer :: v_ptr v_ptr => v call set_elements ( v_ptr ) select type ( v_ptr ) type is ( vector ) print *, v%elements(1), '<-- should be 2' end select end subroutine end $ gfortran -O1 all.f90 $ ./a.out 0 <-- should be 2 $ gfortran --version GNU Fortran (Homebrew GCC 8.2.0) 8.2.0