llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[Flang] Missing finalization call at intrinsic assignment.

Open DanielCChen opened this issue 2 years ago • 2 comments

Consider the following test case:

MODULE mDerivedModule

    TYPE :: tTypeDerived(k1)    ! (4)
        INTEGER, KIND :: K1
        INTEGER(4)   :: i
        INTEGER(4) :: j
        CONTAINS
            FINAL :: tTypeDerivedFinal
    END TYPE tTypeDerived

    CONTAINS
        SUBROUTINE tTypeDerivedFinal( o )
            TYPE(tTypeDerived(4)) :: o( :,:,: )
          print*, "in final."
        END SUBROUTINE tTypeDerivedFinal
END MODULE mDerivedModule


PROGRAM allocatedArrayDerived02
    USE mDerivedModule

    INTEGER(4) :: i

    TYPE(tTypeDerived(4)) :: derivedArray( 2,2,2 ) =&
        RESHAPE((/ (tTypeDerived(4)( i,(8 - i) ), i = 1, 8) /), (/ 2,2,2 /))

    TYPE(tTypeDerived(4)), ALLOCATABLE :: derivedArrayAlloc( :,:,: )


    ALLOCATE(derivedArrayAlloc( 3,3,3 ),&
        SOURCE=RESHAPE((/ (tTypeDerived(4)( (27 - i),i ), i = 27, 1, -1) /),&
                                                                (/ 3,3,3 /)))

    derivedArrayAlloc = derivedArray. !!! Finalization should occur here.


END PROGRAM allocatedArrayDerived02

Expected behavior:

a.out in final

Actual behavior:

a.out

It will work as expected if I

  1. remove the KIND type parameter from the derived type definition, OR
  2. remove the static initialization from the variables.

DanielCChen avatar Oct 22 '24 20:10 DanielCChen

@llvm/issue-subscribers-bug

Author: Daniel Chen (DanielCChen)

Consider the following test case: ``` MODULE mDerivedModule
TYPE :: tTypeDerived(k1)    ! (4)
    INTEGER, KIND :: K1
    INTEGER(4)   :: i
    INTEGER(4) :: j
    CONTAINS
        FINAL :: tTypeDerivedFinal
END TYPE tTypeDerived

CONTAINS
    SUBROUTINE tTypeDerivedFinal( o )
        TYPE(tTypeDerived(4)) :: o( :,:,: )
      print*, "in final."
    END SUBROUTINE tTypeDerivedFinal

END MODULE mDerivedModule

PROGRAM allocatedArrayDerived02 USE mDerivedModule

INTEGER(4) :: i

TYPE(tTypeDerived(4)) :: derivedArray( 2,2,2 ) =&
    RESHAPE((/ (tTypeDerived(4)( i,(8 - i) ), i = 1, 8) /), (/ 2,2,2 /))

TYPE(tTypeDerived(4)), ALLOCATABLE :: derivedArrayAlloc( :,:,: )


ALLOCATE(derivedArrayAlloc( 3,3,3 ),&
    SOURCE=RESHAPE((/ (tTypeDerived(4)( (27 - i),i ), i = 27, 1, -1) /),&
                                                            (/ 3,3,3 /)))

derivedArrayAlloc = derivedArray

END PROGRAM allocatedArrayDerived02


Expected behavior:
>a.out
in final

Actual behavior: 
>a.out


It will work as expected if I 
1. remove the KIND type parameter from the derived type definition, OR
2. remove the static initialization from the variables.
</details>

llvmbot avatar Oct 22 '24 20:10 llvmbot

@llvm/issue-subscribers-flang-runtime

Author: Daniel Chen (DanielCChen)

Consider the following test case: ``` MODULE mDerivedModule
TYPE :: tTypeDerived(k1)    ! (4)
    INTEGER, KIND :: K1
    INTEGER(4)   :: i
    INTEGER(4) :: j
    CONTAINS
        FINAL :: tTypeDerivedFinal
END TYPE tTypeDerived

CONTAINS
    SUBROUTINE tTypeDerivedFinal( o )
        TYPE(tTypeDerived(4)) :: o( :,:,: )
      print*, "in final."
    END SUBROUTINE tTypeDerivedFinal

END MODULE mDerivedModule

PROGRAM allocatedArrayDerived02 USE mDerivedModule

INTEGER(4) :: i

TYPE(tTypeDerived(4)) :: derivedArray( 2,2,2 ) =&amp;
    RESHAPE((/ (tTypeDerived(4)( i,(8 - i) ), i = 1, 8) /), (/ 2,2,2 /))

TYPE(tTypeDerived(4)), ALLOCATABLE :: derivedArrayAlloc( :,:,: )


ALLOCATE(derivedArrayAlloc( 3,3,3 ),&amp;
    SOURCE=RESHAPE((/ (tTypeDerived(4)( (27 - i),i ), i = 27, 1, -1) /),&amp;
                                                            (/ 3,3,3 /)))

derivedArrayAlloc = derivedArray

END PROGRAM allocatedArrayDerived02


Expected behavior:
&gt;a.out
in final

Actual behavior: 
&gt;a.out


It will work as expected if I 
1. remove the KIND type parameter from the derived type definition, OR
2. remove the static initialization from the variables.
</details>

llvmbot avatar Oct 22 '24 20:10 llvmbot