Incorrect behaviour with --Mchkptr

I have some code which when compiled with options -C -Mchkptr returns the diagnostic abort

0: Null pointer for x%p (pgi_check.f90: 21)

I see no indication in Metcalfe, Reid and Cohen’s book that it is an error to call “associated” with a null pointer. Surely it ought simply to return .FALSE.

The diagnostic abort only occurs for the two-argument form of the “associated”
intrinsic. IIt alsogoes away if the pointeris not a member of a derived type.

I think this is a bug and the diagnostic is incorrect - but am willing to be corrected.

module m

  integer,save,pointer :: x,y

  contains
    subroutine init(x,y)
      integer,pointer, intent(inout) :: x,y

      nullify(x)
      nullify(y)

    end subroutine init

    subroutine check_assoc

      if( associated(x,y) ) then
         write(*,*) "Yes"
      else
         write(*,*) "No"
      end if

    end subroutine check_assoc
  end module m

program assoc_test
  use m

  nullify(x)
  nullify(y)

  call init(x,y)

  call check_assoc

end program assoc_test

Hi Keith,

I’m not able to recreate this one. What compiler version and OS are you using? Are you running 32 or 64-bits? Are there any other compile options?

Thanks,
Mat


% cat chkptr.f90 
module m

  integer,save,pointer :: x,y

  contains
    subroutine init(x,y)
      integer,pointer, intent(inout) :: x,y

      nullify(x)
      nullify(y)

    end subroutine init

    subroutine check_assoc

      if( associated(x,y) ) then
         write(*,*) "Yes"
      else
         write(*,*) "No"
      end if

    end subroutine check_assoc
  end module m

program assoc_test
  use m

  nullify(x)
  nullify(y)

  call init(x,y)

  call check_assoc

end program assoc_test 
% pgf90 -C -Mchkptr chkptr.f90 -V12.9
% a.out
 No

Oops - I included the wrong code. This is the one which fails (with 12.9)

module m
  type t

     complex, pointer, dimension(:) :: p => null()

     complex, allocatable, dimension(:)  :: q
  end type t

  contains
    subroutine init(x)
      type(t), intent(inout) :: x

      nullify(x%p)

    end subroutine init

    subroutine check_assoc(x)

      type(t), intent(inout), target :: x

      if( associated(x%p,x%q) ) then
         write(*,*) "Yes"
      else
         write(*,*) "No"
      end if

    end subroutine check_assoc
  end module m


program assoc_test
  use m

  type(t) :: x

  call init(x)

  call check_assoc(x)

end program assoc_test

Thanks Keith. I sent this off to engineering and they agree that it’s a compiler error. They will have a fix in place in as of the the 13.0 compilers.

  • Mat