[flang] Restore declared type when deallocating polymorphic entities
authorValentin Clement <clementval@gmail.com>
Thu, 12 Jan 2023 10:12:00 +0000 (11:12 +0100)
committerValentin Clement <clementval@gmail.com>
Thu, 12 Jan 2023 10:12:30 +0000 (11:12 +0100)
commit01e8e50ce397dcb08e7dfadab93a53ae31174c67
tree7f34702f47b2fee8dce14912a1f50238f44801cb
parent12ece76815ab330f8f33707efd7c93735dd9c178
[flang] Restore declared type when deallocating polymorphic entities

As mentioned in section 7.3.2.3 note 7, The dynamic type of an unallocated
allocatable object or a disassociated pointer is the same as its declared type.

This patch adds two function to the runtime:
- `PointerDeallocatePolymorphic`
- `AllocatableDeallocatePolymorphic`

These two functions take a DerivedTypeDesc pointer of the declared type.
The lowering is updated accordingly to call these functions for polymorphic
and unlimited polyrmophic entities. For unlimited polymorphic entities, the
dynamic type is set to nullptr when the entity is on an unallocated or
disassociated state.

Reviewed By: PeteSteinfeld, klausler

Differential Revision: https://reviews.llvm.org/D141519
flang/include/flang/Lower/Allocatable.h
flang/include/flang/Optimizer/Builder/Runtime/RTBuilder.h
flang/include/flang/Runtime/allocatable.h
flang/include/flang/Runtime/pointer.h
flang/lib/Lower/Allocatable.cpp
flang/lib/Lower/ConvertVariable.cpp
flang/runtime/allocatable.cpp
flang/runtime/pointer.cpp
flang/test/Lower/allocatable-polymorphic.f90
flang/test/Lower/intentout-deallocate.f90
flang/test/Lower/polymorphic-types.f90