The current code was not taking provided lower bounds when the pointer
is polymorphic and was just calling PointerAssociate. This patch
updates the behavior and use PointerAssociateLowerBounds with the provided
lower bounds.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
I think PointerAssociateLowerBounds must be called instead here. At first, I though, why not using computing ubounds even if not needed and using PointerAssociateRemapping to re-use createBoundArray like you did, but pointer association with bounds remapping is special because it requires the target to be contiguous (except maybe in the first dimension), which the normal pointer association, with potential new lower bounds, does not. The runtime relies on this contiguity to compute the new strides for the pointer in PointerAssociateRemapping. So `PointerAssociateRemapping cannot be used here.
I expect the following would give bad results:
module test type t integer :: i end type contains subroutine assoc(p, z) class(t), pointer :: p(:, :) class(t), target :: z(:, :) p(2:, 2:) => z end subroutine end module use test type(t) :: z(10, 10) class(t), pointer :: p(:, :) do j = 0, 9 do i = 1,10 z(i, j+1)%i = i + j*10 end do end do call assoc(p, z(1:10:5, 1:10:5)) print *, p(2:,2:)%i end
This should print "1 6 51 56". The last two numbers will probably something else with this patch.
Somehow I didn't find PointerAssociateLowerBounds when I looked into the runtime :-). The test seems to pass with this but I'll update the patch to make use of the correct runtime function.