This is an archive of the discontinued LLVM Phabricator instance.

[flang] Use derivedType from toAddedum to get updated components
ClosedPublic

Authored by clementval on Feb 16 2023, 1:44 AM.

Details

Summary

When the rhs is polymorphic and allocated during assignment, the
derivedType might have change from the one set in toDerived.
Use the one set in the addendum so it is always up to date.

This can happen in cases like the one shown below:

type :: t1
end type t1

type, extends(t1) :: t2
  integer, allocatable :: i(:)
end type

subroutine assign(t)
  class(t2), intent(in) :: t
  class(t1), allocatable :: cp

  cp = t
end subroutine

Diff Detail

Event Timeline

clementval created this revision.Feb 16 2023, 1:44 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptFeb 16 2023, 1:44 AM
Herald added a subscriber: sunshaoce. · View Herald Transcript
clementval requested review of this revision.Feb 16 2023, 1:44 AM
jeanPerier accepted this revision.Feb 16 2023, 3:08 AM
jeanPerier added inline comments.
flang/runtime/assign.cpp
316–317

Probably best to use:

if (const typeInfo::DerivedType *updatedToDerived{toAddendum ? toAddendum->derivedType() : nullptr}) {
  ...

}

so that it is obvious that toAddendum is not null, and the there is a good reason not to use toDerived.

This revision is now accepted and ready to land.Feb 16 2023, 3:08 AM
clementval marked an inline comment as done.

Update toDerived condition.

flang/runtime/assign.cpp
316–317

Update for more safety.