This is an archive of the discontinued LLVM Phabricator instance.

[flang] Ensure pointer components are always established
ClosedPublic

Authored by jeanPerier on May 9 2023, 12:40 AM.

Details

Summary

Follow up of https://reviews.llvm.org/D149979 for lowering.

In Fortran, it is possible to assign a pointer to another pointer
with an undefined association status.
When using the runtime do to none trivial pointer association, if the
descriptor are garbage, the runtime cannot safely detect that it has
a garbage descriptor, and it cannot safely know the descriptor size
leading to undefined behavior.
Another reason to initialize descriptor of pointers is to record any
non deferred length parameter value.
Hence, although this is not required by Fortran, f18 always initialize
pointers to NULL().
This was already done in lowering for whole pointer object, but not for
pointer components.

This patch uses the related semantics patch that updated
derivedTypeSpe::HasDefaultInitialization to ensure pointer components
of local and global object are always initialized.

It adds tests to ensure that allocation of such derived type uses the
runtime to ensure the storage is initialized, and that structure
constructors are setting the descriptor component to NULL() if no
initial target is given.

Diff Detail

Event Timeline

jeanPerier created this revision.May 9 2023, 12:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 9 2023, 12:40 AM
jeanPerier requested review of this revision.May 9 2023, 12:40 AM
klausler accepted this revision.May 9 2023, 8:16 AM

Thanks for closing the loop on this.

This revision is now accepted and ready to land.May 9 2023, 8:16 AM
vzakhari accepted this revision.May 9 2023, 8:44 AM

Thank you!