This is an archive of the discontinued LLVM Phabricator instance.

[flang] Use input type to recover the type desc when emboxing
ClosedPublic

Authored by clementval on Jan 24 2023, 12:39 AM.

Details

Summary

When emboxing to a polymorphic entity without a type source box,
the type desc address must be retrived from the input type and
not from the box type.

Diff Detail

Event Timeline

clementval created this revision.Jan 24 2023, 12:39 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJan 24 2023, 12:39 AM
clementval requested review of this revision.Jan 24 2023, 12:39 AM
jeanPerier added inline comments.Jan 24 2023, 1:27 AM
flang/lib/Frontend/CompilerInvocation.cpp
959 ↗(On Diff #491640)

Probably not intended here?

flang/lib/Optimizer/CodeGen/CodeGen.cpp
1581

Is the input type the base type or the "base type after applying component refs" ?

e.g: if you have "call foo(some_derived1(:)%some_derived2)" beinging passed to a polymoprhic some_derived2_base_type, would input type here be "some_derived1" or "some_derived2" ?

Remove polymorphic type flag

clementval added inline comments.Jan 24 2023, 2:00 AM
flang/lib/Optimizer/CodeGen/CodeGen.cpp
1581

This should be some_derived2 but let me double check.

clementval added inline comments.Jan 24 2023, 2:20 AM
flang/lib/Optimizer/CodeGen/CodeGen.cpp
1581

So in this case we have a fir.embox first that goes to a fir.box of the correct type. The polymorphic box is created with a fir.rebox. So the embox is taking the normal codegen where the result box type is used. So the correct type is used.

type p1
  integer :: a
  integer :: b
end type
type outer
  type(p1) :: inner
end type
... 
subroutine test2(p)
   class(p1) :: p(:)
end subroutine

subroutine test1()
  type(outer) :: o(10)
  call test2(o(:)%inner)
end subroutine
%7 = fir.embox %0(%5) [%6] : (!fir.ref<!fir.array<10x!fir.type<_QMpolymorphic_testTouter{inner:!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>}>>>, !fir.shape<1>, !fir.slice<1>) -> !fir.box<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>
  %8 = fir.rebox %7 : (!fir.box<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>) -> !fir.class<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>
jeanPerier accepted this revision.Jan 24 2023, 5:38 AM

Thanks for checking, looks good

This revision is now accepted and ready to land.Jan 24 2023, 5:38 AM