Issue 126391
Summary [Flang] Missing finalization on `MOVE_ALLOC`
Labels flang:runtime
Assignees
Reporter DanielCChen
    Consider the following code
```
module m
    integer  :: numA = 0, numB = 0

 type A
        integer :: iA
        contains
            final :: finalA
    end type

    type, extends(A) :: B
        integer :: iB
 type(A) :: x
        contains
            final :: finalB
    end type

    contains
        subroutine finalA(a1)
            type(A), intent(in) :: a1
            numA = numA + 1
        end subroutine

 subroutine finalB(b1)
            type(B), intent(in) :: b1
 numB = numB + 1
        end subroutine
end module


program main
use m

    class(A), allocatable :: to(:)
    class(B), allocatable :: from(:)

    allocate(B :: to(1))
    allocate(B :: from (0:-1) )

 select type (to)
      type is (B)
        to(1) = B(iA = 101, iB = 102, x= A(11))      !! Finalize 'to' as of type B
    end select

    if ( numA /= 2 ) error stop 11
    if ( numB /= 1 ) error stop 13

    ! to is rank-1 array
    call move_alloc(from, to )                            !! Finalize 'to' again as of type B

    if ( numA /= 4 ) error stop 41
    if ( numB /= 2 ) error stop 43

   end

```

Flang currently failed at `error stop 41` because the counter of `finalA` is 3 instead of 4. 
Polymorphic allocatable variable `to` has dynamic type of `B` at the point before `move_alloc` is called, so it should call `finalB` once more and `finalA` twice more.

_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to