Bug with argument association / dummy argument with pointer,intent(in) attribute

nvfortran does not properly handle the F2008+ interpretation of dummy arguments with pointer,intent(in) attribute. Example code:

program bug
  integer, pointer :: p(:), q
  allocate (p(3))
  p = [1, 42, 3]
  ! Argument association which works:
  call s1 (p(2))
  ! This is explained in F2018: clause 2 (or F2023:
  ! "... the actual argument shall be a pointer or a valid target
  !  for the dummy pointer in a pointer assignment statement. ..."
  q => p(2)      ! q is a pointer, p(2) is a valid target
  call s2 (q)    ! q is a pointer
  call s2 (null()) ! Test: pass NULL() pointer
  call s2 (p(2)) ! p(2) is still a valid target
  ! (wrong code with nvfortran -> runtime crash)
  subroutine s1 (x)
    integer, target              :: x
    print *, "s1: x=", x
  end subroutine s1
  subroutine s2 (x)
    integer, pointer, intent(in) :: x
    print *, "s2: associated(x)=", associated (x)
    if (associated (x)) print *, "s2: x=", x
  end subroutine s2
end program bug

This crashes at runtime with:

 s1: x=           42
 s2: associated(x)=  T
 s2: x=           42
 s2: associated(x)=  F
 s2: associated(x)=  T
Segmentation fault (core dumped)

Expected result: the last call should again print:

 s2: x=           42

NAG and gfortran do the right thing.


Thanks Harald,

I filed a new problem report, TPR #33693, and sent it to engineering for review.