[flang] Fix element indexing in Destroy component deallocation
authorValentin Clement <clementval@gmail.com>
Thu, 23 Feb 2023 16:26:52 +0000 (17:26 +0100)
committerValentin Clement <clementval@gmail.com>
Thu, 23 Feb 2023 16:27:21 +0000 (17:27 +0100)
commite89a00db6d0596fe0263ca0a1052e5e6859744e9
tree3fcde7656d27e63766d958a9aff51b1a1c489a3a
parente340e9e632124f541d8225ccf0a5c55de402fb3c
[flang] Fix element indexing in Destroy component deallocation

Derived type `Destroy` function does not take step into consideration
when indexing the component element for deallocation. This leads to
incorrect deallocation in case like:

```
module mod1
  type :: t
    real, allocatable :: r(:)
  end type
contains
  subroutine do_smth(c)
    class(t), intent(out) :: c(:)
    do i = 1, size(c)
      if (allocated(c(i)%r)) then
        print*, i, 'not deallocated'
      end if
    end do
  end subroutine
end module

program test
  use mod1
  type(t) :: z(6)
  integer :: i
  do i = 1, 6
    Allocate(z(i)%r(i))
  end do
  call do_smth(z(::2))
end
```

Similar change was done in D142527

Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D144553
flang/runtime/derived.cpp