If one passes an ALLOCATABLE variable as actual to a dummy argument which is
not ALLOCATBLE, the should be an optional run-time to check whether the
variable is allocated.

For pointers, one could check whether a pointer is NULL as this means
non-associated. Checking for an uninitialized pointer is more difficult ...

Using NAG f95 -C=pointer, the error is:
  ALLOCATABLE array N is not currently allocated
  Program terminated by fatal error
  In $main$, line 2 of test.f90

Using ifort -check pointers, the result is:
  forrtl: severe (408): fort: (7): Attempt to use pointer N when it is not
  associated with a target
  a.out              0000000000402D2D  BAR                         6  test.f90
  a.out              0000000000402C60  MAIN__                      2  test.f90

Remark: NAG f95 does the check for the actual argument, ifort does it before
using the dummy argument.

I think I would fiddle it into gfc_conv_procedure_call (-> se.pre) using the
check:
  if (actual->attr.allocatable
      && (!formal || !formal->attr.allocatable)
      && (gfc_option.rtcheck & GFC_RTCHECK_POINTER))
   generateCode: if( not associated(actual) ) then rt-error
  else if (actual->attr.pointer
           && (!formal || !forrmal->attr.pointer)
           && (gfc_option.rtcheck & GFC_RTCHECK_POINTER))
   generateCode: if( actual == NULL ) then rt-error

(The check will fail if the actual argument is an uninitialized pointer; for
this and further pointer checks, see PR .)

integer, allocatable :: n(:)
call bar(n)
contains
  subroutine bar(n)
    integer :: n(:)
    print *, n
  end subroutine bar
end


-- 
           Summary: Add -fcheck=pointer with runtime check for using an
                    unallocated argument
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: burnus at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40580

Reply via email to