This is an archive of the discontinued LLVM Phabricator instance.

[flang][hlfir] Fix multiple return declaration type
ClosedPublic

Authored by tblah on Jun 14 2023, 9:05 AM.

Details

Summary

When the ENTRY statement is used, the same source can return different
types depending on the entry point. These different return values are
storage associated (share the same storage). Previously, this led to the
declaration of the results to all have the largest type. This patch adds
a convert between the stack allocation and the declaration so that the
hlfir.decl gets the right type.

I haven't managed to generate code where this convert converted a
reference to an allocation for a smaller type into an allocation for a
larger one, but I have added an assert just in case.

This is a different solution to https://reviews.llvm.org/D152725, see
discussion there.

Diff Detail

Event Timeline

tblah created this revision.Jun 14 2023, 9:05 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJun 14 2023, 9:05 AM
tblah requested review of this revision.Jun 14 2023, 9:05 AM
jeanPerier accepted this revision.Jun 15 2023, 9:07 AM

Thanks, LGTM!

I haven't managed to generate code where this convert converted a
reference to an allocation for a smaller type into an allocation for a
larger one, but I have added an assert just in case.

By construction, the "primaryFuncResultStorage" is the biggest one: https://github.com/llvm/llvm-project/blob/52ca6ad755b0cc2aa603cfb3124bf58c04a47005/flang/lib/Lower/PFTBuilder.cpp#L1022-L1024.

Still sane to add an assert though.

This revision is now accepted and ready to land.Jun 15 2023, 9:07 AM
This revision was automatically updated to reflect the committed changes.