This is an archive of the discontinued LLVM Phabricator instance.

[flang] Embox derived-type when passed to element procedure as passed object
ClosedPublic

Authored by clementval on Dec 8 2022, 12:37 PM.

Details

Summary

In elemental procedure lowering the passed object is always emboxed. The current code
was not correctly dealing with scalar derived-type used as passed object.

Diff Detail

Event Timeline

clementval created this revision.Dec 8 2022, 12:37 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptDec 8 2022, 12:37 PM
Herald added a subscriber: mehdi_amini. · View Herald Transcript
clementval requested review of this revision.Dec 8 2022, 12:37 PM
PeteSteinfeld accepted this revision.Dec 8 2022, 2:22 PM

All builds and tests correctly and looks goodl.

This revision is now accepted and ready to land.Dec 8 2022, 2:22 PM
jeanPerier added inline comments.Dec 9 2022, 12:20 AM
flang/test/Lower/polymorphic.f90
690

Do you know which passBy this argument is being set to by the Fortran::lower::CallerInterface at https://github.com/llvm/llvm-project/blob/main/flang/lib/Lower/ConvertExpr.cpp#L2591 ?

I did not test, but I find it weird that you have to deal with creating the box in convertWithSemantics(). It suggests to me that passBy may be set to PassBy::BaseAddressValueAttribute when I would expect it to be set to PassBy::Box.

If the same were to happen with arrays or with type with type parameters, the length/shape would be unavailable at that point.

clementval added inline comments.Dec 9 2022, 1:19 AM
flang/test/Lower/polymorphic.f90
690

In this particular example, it is correct. It's PassBy::Box. I'll update this patch with the correct example where it fails and double check the PassBy behavior.

clementval updated this revision to Diff 481588.Dec 9 2022, 3:08 AM

Fix the actual problem in element procedure lowering

clementval requested review of this revision.Dec 9 2022, 3:09 AM
clementval retitled this revision from [flang] Embox derived-type when passed to procedure expecting polymorphic entity to [flang] Embox derived-type when passed to element procedure as passed object.
clementval edited the summary of this revision. (Show Details)

@jeanPerier The issue was actually in genElementalUserDefinedProcRef in the code added in D139537. When the arg is scalar the lowering was not correct.

jeanPerier accepted this revision.Dec 9 2022, 5:26 AM

Makes sense to me now, thanks

This revision is now accepted and ready to land.Dec 9 2022, 5:26 AM
This revision was landed with ongoing or failed builds.Dec 9 2022, 6:38 AM
This revision was automatically updated to reflect the committed changes.