The TODO was left there to verify that Assign() runtime handles
overlaps of allocatable components. It did not, and this change-set
fixes it. Note that the same Assign() issue can be reproduced
without HLFIR. In the following example the LHS would be reallocated
before value of RHS (essentially, the same memory) is read:
program main type t1 integer, allocatable :: a(:) end type t1 type(t1) :: x, y allocate(x%a(10)) do i =1,10 x%a(i) = 2*i end do x = x print *, x%a deallocate(x%a) end program main
The test's output would be incorrect (though, this depends on the memory
reuse by malloc):
0 0 0 0 10 12 14 16 18 20
It is very hard to add a Flang unittest exploiting derived types.
Did you move this block of code in order to ensure LHS finalization prior to invoking defined assignment? Be advised, finalization applies only to intrinsic assignments (7.5.6.3); a defined assignment subroutine is responsible for calling any final subroutines. Programs with defined assignments basically have to implement everything, including storage allocation and deallocation and finalization, so I get worried when I see other stuff in here that might inappropriately take place "automatically" before a defined assignment procedure gets called.