This is an archive of the discontinued LLVM Phabricator instance.

[flang] Handle emboxing of a fir.ref<none> to an unlimited polymorphic box
ClosedPublic

Authored by clementval on Jan 9 2023, 3:49 AM.

Details

Summary

When an array element is extracted from an unlimited polymorphic array, the
emboxing of this element has to retrive the type code and element size from
the initial array. This patch retrive this information through the extracted
type descriptor.

This situation can be found in code like:

subroutine sub1(a)
  class(*) :: a(:)
  select type (x=>a(1))
  type is (integer)
    x = 10
  end select
end subroutine

Diff Detail

Event Timeline

clementval created this revision.Jan 9 2023, 3:49 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJan 9 2023, 3:49 AM
Herald added a subscriber: mehdi_amini. · View Herald Transcript
clementval requested review of this revision.Jan 9 2023, 3:49 AM
jeanPerier accepted this revision.Jan 9 2023, 4:59 AM

Makes sense with the current IR. I think might be cleaner to try to improve the indexing/assumed type handling in lowering so that the FIR operation that produces a new fir.class hold the input fir.class as operand and there is no need to find it back.

Do you have the motivating Fortran example for this so that I can try to see if HLFIR addressing might help in the future ?

This revision is now accepted and ready to land.Jan 9 2023, 4:59 AM

Makes sense with the current IR. I think might be cleaner to try to improve the indexing/assumed type handling in lowering so that the FIR operation that produces a new fir.class hold the input fir.class as operand and there is no need to find it back.

Do you have the motivating Fortran example for this so that I can try to see if HLFIR addressing might help in the future ?

Agreed it would be nice to improve this and make it cleaner.

Here is an example:

program test
  integer :: arr(2) = [ 10,20 ]
  call sub1(arr)
Contains
  subroutine sub1(arr)
    class(*) :: arr(:)
    select type (x => arr(2))
    type is (integer)
      a = 10
    end select
  end subroutine
end
PeteSteinfeld accepted this revision.Jan 9 2023, 7:03 AM

All builds and tests correctly and looks good.