[flang] derived-type finalization
authorValentin Clement <clementval@gmail.com>
Tue, 31 Jan 2023 12:46:12 +0000 (13:46 +0100)
committerValentin Clement <clementval@gmail.com>
Tue, 31 Jan 2023 12:46:39 +0000 (13:46 +0100)
commit97492fd1aed56e3d041952914849d95b5ff999af
treea7c650d14ef9ae0f7a97a3d938986be3570f1e67
parent1a8abab26980f9339f9dfa858863d6eaf5595231
[flang] derived-type finalization

This patch implements the derived-type finalization for
monomorphic and polymorphic derived-type.

The finalization is done through a call to the `Destroy`
runtime function so the allocatable component object are also
finalized correctly when needed. It would be possible to finalize
monomorphic derived-type with non finalizable component with a
direct call to their finalize subroutine.

7.5.6.3 point 1: LHS nonallocatable object and LHS allocatable
object finalization. Done with call to `Destroy` for monomorphic
derived-type and through `Assign` for polymorphic entities.

7.5.6.3 point 2: Done within the deallocation calls.

7.5.6.3 point 3: A function context is added to the bridge to
attach finalization that need to happen on function/subroutine
exit.

7.5.6.3 point 4: BLOCK construct not yet implemented.

7.5.6.3 point 5/6: Finalization attach to the stmtCtx in a
similar way than 9.7.3.2 point 4.

7.5.6.3 point 7: INTENT(OUT) finalization done with a
call to `Destroy` runtime function call.

This patch passes 9/10 tests in the proposed test-suite
https://github.com/llvm/llvm-test-suite/pull/13

- The case with BLOCK construct will be implemented later when
  BLOCK are implemented upstream.

- Automatic deallocation is not yet implemented. Finalization triggered
  by automatic deallocation is then not triggered.

Reviewed By: jeanPerier, PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D142707
flang/include/flang/Lower/AbstractConverter.h
flang/include/flang/Lower/Bridge.h
flang/include/flang/Semantics/tools.h
flang/lib/Lower/Bridge.cpp
flang/lib/Lower/ConvertCall.cpp
flang/lib/Lower/ConvertType.cpp
flang/lib/Lower/ConvertVariable.cpp
flang/lib/Semantics/tools.cpp
flang/test/Lower/derived-type-finalization.f90 [new file with mode: 0644]
flang/test/Lower/polymorphic.f90