On Thu, 30 Jul 2020 11:53:10 +0200
Thomas Schwinge <tho...@codesourcery.com> wrote:

> Hi Julian, Tobias!
> 
> On 2020-07-27T15:33:41+0100, Julian Brown <jul...@codesourcery.com>
> wrote:
> > You can still get a "leak" if you try to attach a
> > synthesized/temporary array descriptor that goes out of scope
> > before the pointed-to data it refers to does -- that's a problem
> > I've mentioned earlier, and is kind-of unavoidable unless we do
> > some more sophisticated analysis to diagnose it as user error.  
> 
> ACK.  Do you remember if you already had a testcase (conceptual, or
> actual) to demonstrate that problem?

I have the attached, but it's not "clean", i.e. not really
testsuite-ready -- the breakage demonstrated depends on the stack
layout, and it only "works" at -O0.

HTH,

Julian
program myprog
  implicit none
  integer :: a(16)
  integer :: i

  call enterdata_wrapper(a, 16)
  call exitdata_wrapper(a, 16)

  contains

  subroutine enterdata_wrapper(a, n)
    implicit none
    integer :: n
    integer, target :: a(n)
    integer :: aa(16)
    integer :: bb(16)
    integer, pointer :: ap(:)
    integer :: cc(16)
    integer :: dd(16)

    ! An array descriptor appears somewhere around here...
    ap => a

    !$acc enter data copyin(aa,bb,cc,dd)
    call enterdata(ap)
    !$acc exit data copyout(aa,bb,cc,dd)

    ! ...and goes out of scope.
  end subroutine enterdata_wrapper

  subroutine enterdata(a)
    implicit none
    integer, pointer :: a(:)

    ! Map "to(a.data) to_pset(a) pointer(a.data)"
    !$acc enter data copyin(a)
  end subroutine enterdata

  subroutine exitdata_wrapper(a, n)
    implicit none
    integer :: n
    integer, target :: a(n)
    integer :: aa(32)
    integer :: bb(32)
    integer, pointer :: ap(:)
    integer :: cc(32)
    integer :: dd(32)

    ! A different array descriptor appears...
    ap => a

    !$acc enter data copyin(aa,bb,cc,dd)
    call exitdata(ap)
    !$acc exit data copyout(aa,bb,cc,dd)

    ! ...and goes out of scope.
  end subroutine exitdata_wrapper

  subroutine exitdata(a)
    implicit none
    integer, pointer :: a(:)

    ! Try to unmap the fresh array descriptor: FAILS.
    !$acc exit data copyout(a)
  end subroutine exitdata
end program myprog

Reply via email to