This is an archive of the discontinued LLVM Phabricator instance.

[flang] Handle parent component of extended derived-type
ClosedPublic

Authored by clementval on Sep 19 2022, 2:16 AM.

Details

Summary

Parent component refers to the parent derived-type of an extended type.
The parent component is skipped when a specififc component is
referred to. This is fine since all the components in extended type
are available in the type itself. When the parent component is referred,
it need to be taken into account correctly.
This patch fixes the case when the parent component is referred. In a
box, an approriate slice is created or updated to point to the first
component of the parent component. For scalar, a simple conversion to
the parent component type is done.

Diff Detail

Event Timeline

clementval created this revision.Sep 19 2022, 2:16 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptSep 19 2022, 2:16 AM
Herald added a subscriber: mehdi_amini. · View Herald Transcript
clementval requested review of this revision.Sep 19 2022, 2:16 AM
jeanPerier added inline comments.Sep 19 2022, 6:35 AM
flang/lib/Lower/ConvertExpr.cpp
7779

This code might also have to deal with rebox (if for instance y is an assumed shape array dummy argument in y(:)%p).

7791

There is one killer case here: what if the parent type has no component ?

module m
  type t1
  end type
  type, extends(t1) :: t2
    integer :: i
  end type
  interface
  subroutine bar(a)
    import :: t1
    type(t1) :: a(:)
  end subroutine
  end interface
contains
  subroutine foo(a)
    type(t2) :: a(10)
    call bar(a%t1)
  end subroutine
end module

It is probably fine to leave a TODO in that edge case for now. We may need to touch embox/rebox to deal with this case.

7801

What if the original embox already had fields ? that can probably happen for:

module m
  type t1
   integer :: i
  end type
  type, extends(t1) :: t2
    integer :: j
  end type
  type t
    integer :: k
    type(t2) :: c
  end type
  interface
  subroutine bar(a)
    import :: t1
    type(t1) :: a(:)
  end subroutine
  end interface
contains
  subroutine foo(a)
    type(t) :: a(10)
    call bar(a%c%t1)
  end subroutine
end module
  • Handle rebox op
  • Keep existing fields
  • Add todo for parent component with no component
clementval marked 3 inline comments as done.Sep 20 2022, 7:55 AM
clementval added inline comments.
flang/lib/Lower/ConvertExpr.cpp
7779

Good point. I updated the code and added tests for this case.

7791

I just added a TODO for now. Seems like a use case that should not be widely used.

7801

We keep the existing fields. I added tests to check it is handled correctly.

jeanPerier accepted this revision.Sep 21 2022, 1:20 AM

Thanks for dealing with this tricky case.

This revision is now accepted and ready to land.Sep 21 2022, 1:20 AM
This revision was automatically updated to reflect the committed changes.
clementval marked 3 inline comments as done.