This is an archive of the discontinued LLVM Phabricator instance.

[flang][hlfir] Moved TODO for polymorphic vector subscripted expressions.
ClosedPublic

Authored by vzakhari on Jul 9 2023, 10:17 PM.

Details

Summary

If I understand it correctly, the TODO is intended to catch cases
when we may need to create a temporary array for polymorphic entities
resulting from a vector subscription, i.e. when the final expression
type of hlfir.elemental_addr is polymorphic. The TODO check was done
very early, so it kicked in for cases where the it should not have.
For example,

type t
  integer n
end type
class(t), pointer :: p(:)
... p(vector_of_indices)%n

Such designators are supported by FIR lowering and can be currently
supported by HLFIR, but the TODO prevented this. I just moved the TODO
check later in the lowering pipeline.

I also updated the comment trying to describe my understanding of how
the correct mold entity can be computed for the elemental operation
producing HLFIR expression of polymorphic type.

This change provides 34 new passes in my nag testing.

Diff Detail

Event Timeline

vzakhari created this revision.Jul 9 2023, 10:17 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 9 2023, 10:17 PM
vzakhari requested review of this revision.Jul 9 2023, 10:17 PM
tblah accepted this revision.Jul 10 2023, 2:53 AM

LGTM but please wait for Jean to have a look too

This revision is now accepted and ready to land.Jul 10 2023, 2:53 AM

Thank you for the review, Tom! I would like to merge this now. I will discuss it with Jean whenever he is available :)

Sorry for the delay, this looks good to me.

Regarding the comment, I do not think one needs to evaluate an element to get the mold (although that may be a solution). If a vector subscripted designator is polymorphic, its dynamic type comes from the array part that is being vector subscripted (the partInfo.base near the previous TODO), the array should be usable directly as a mold for the dynamic type. In other words, there cannot be a polymorphic component after a vector subscript.
Rational:

  • components can only be polymorphic if they are pointers/allocatable (F2018 C708)
  • it is forbidden to have a ranked array part on the left of a pointer/allocatable component (F2018 C919)
  • vector subscripted parts are ranked parts

-> The vector subscript must be on the right of the "polymorphic part"

So if the vector subscripted designator is polymorphic, the dynamic type is the same as the part that is vector subscripted (partInfo.base). However, as shown by your patch, partInfo.base being polymorphic does not imply that the resulting designator is polymorphic.

Thank you for the explanation, Jean! It helps a lot!