This is an archive of the discontinued LLVM Phabricator instance.

[flang] preserve pointer rank in polymorphic_pointer => NULL()
ClosedPublic

Authored by jeanPerier on Mar 31 2023, 4:55 AM.

Details

Summary

The current lowering for polymorphic pointer association was not
dealing with NULL in a "context aware" fashion: it was calling the
PointerAssociate runtime entry point with a fir.box<none> target.
But the fir.box<none> is a descriptor for a scalar, this lead the
runtime to set the pointer rank to zero, regardless of its actual
rank.

I do not think there is a way to expose this problem with the Fortran
code currently supported by flang, because most further manipulation of
the pointer would either set the rank correctly, or do not rely on the
rank in the runtime descriptor.

However, this is incorrect, and when assumed rank are supported, the
following would have failed:

subroutine check_rank(p)
  class(*), pointer :: p(..)
  p => null()
  select rank(p)
  rank (1)
   print *, "OK"
  rank default
   print *, "FAILED"
  end select
end subroutine
  class(*), pointer :: p(:)
  p => null()
  call check_rank(p)
end

Instead, detect NULL() in polymorphic pointer lowering and trigger the
deallocation of the pointer.

Diff Detail

Event Timeline

jeanPerier created this revision.Mar 31 2023, 4:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 31 2023, 4:55 AM
jeanPerier requested review of this revision.Mar 31 2023, 4:55 AM
This revision is now accepted and ready to land.Mar 31 2023, 9:10 AM