This is an archive of the discontinued LLVM Phabricator instance.

[flang] Restore declared type when deallocating polymorphic entities
ClosedPublic

Authored by clementval on Jan 11 2023, 9:43 AM.

Details

Summary

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.

Diff Detail

Event Timeline

clementval created this revision.Jan 11 2023, 9:43 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald Transcript
Herald added a subscriber: mehdi_amini. · View Herald Transcript
clementval requested review of this revision.Jan 11 2023, 9:43 AM
clementval planned changes to this revision.Jan 11 2023, 9:45 AM

Need a change in the runtime function.

Set the dynamic type to the declared type after the descriptor.Destroy() is
called so the proper finalization will be done.

klausler accepted this revision.Jan 11 2023, 10:43 AM
klausler added inline comments.
flang/runtime/allocatable.cpp
110

Perhaps this should not be done when stat != StatOk. I'm not sure.

This revision is now accepted and ready to land.Jan 11 2023, 10:43 AM
PeteSteinfeld accepted this revision.Jan 11 2023, 11:05 AM

Things generally build and test correctly and look good. But most runtime routines have unit tests in .../flang/unittests/Runtime. Have you looked at adding unit tests for these new runtime routines?

Update dynamic type if deallocation succeed

Things generally build and test correctly and look good. But most runtime routines have unit tests in .../flang/unittests/Runtime. Have you looked at adding unit tests for these new runtime routines?

I look at adding some tests briefly but it doesn't seem trivial to create the correct derived type in the unit test to pass it to the function.

clementval marked an inline comment as done.Jan 12 2023, 12:58 AM