[flang] preserve pointer rank in polymorphic_pointer => NULL()
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. Differential Revision: https://reviews.llvm.org/D147317
Loading
Please sign in to comment