https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91077
Bug ID: 91077 Summary: [8/9/10 Regression] Wrong indexing when using a pointer Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: tkoenig at gcc dot gnu.org Target Milestone: --- From a c.l.f. post by ygalkl...@gmail.com (slightly modified): program test implicit none integer, parameter :: length = 9 real(8), dimension(2) :: a, b integer :: i type point real(8) :: x end type point type stored type(point), dimension(:), allocatable :: np end type stored type(stored), dimension(:), pointer :: std =>null() allocate(std(1)) allocate(std(1)%np(length)) std(1)%np(1)%x = 0.3d0 std(1)%np(2)%x = 0.3555d0 std(1)%np(3)%x = 0.26782d0 std(1)%np(4)%x = 0d0 std(1)%np(5)%x = 1.555d0 std(1)%np(6)%x = 7.3d0 std(1)%np(7)%x = 7.8d0 std(1)%np(8)%x = 6.3d0 std(1)%np(9)%x = 5.5d0 do i = 1, 2 write(*, "('std(1)%np(',i1,')%x = ',1e22.14)") i, std(1)%np(i)%x end do do i = 1, 2 write(*, "('std(1)%np(1:',i1,') = ',9e22.14)") i, std(1)%np(1:i)%x end do a = std(1)%np(1:2)%x b = [std(1)%np(1)%x, std(1)%np(2)%x] print *,a print *,b if (norm2(a - b) .gt. 1d-3) then write(*,*) 'failure' else write(*, *) 'success' end if end program test yields std(1)%np(1)%x = 0.30000000000000E+00 std(1)%np(2)%x = 0.35550000000000E+00 std(1)%np(1:1) = 0.30000000000000E+00 std(1)%np(1:2) = 0.30000000000000E+00 0.55000000000000E+01 0.29999999999999999 5.5000000000000000 0.29999999999999999 0.35549999999999998 failure with gcc-8, gcc-9 and current trunk. Something is rotten in the state of Denmark here.