I think there are essentially two problems possible with pointers:

(a) Uninitialized pointer (i.e. neither NULL nor associated)
(b) Using an unassociated pointer

I think checking (a) is not easily doable as one would need to pass this status
(has been initialized? yes/no) on to subroutines.
(NAG f95 does so, but one needs to compile all parts of the program with this
option as the variable status is passed on to the subroutines. This
-C=uninitialized options is still great to find uninitialized variables, esp.
those (e.g. integer) which can not be pre-autoinitialized by NaN.)


Thus this is a request for enhancement for the second type.

Example:

program pointtest
  implicit none
  real, pointer :: r
  nullify(r)
  call foo(r) ! Error one
  r = 5.0     ! Error two
contains
  subroutine foo(bar)
     real, target, intent(in) :: bar
     ! The error occures already here and not in the next line!
     print *, bar
  end subroutine foo
end program pointtest


Both are caught by NAG f95 with -C=pointer and by ifort with -check pointer:

Reference to disassociated POINTER R
and
forrtl: severe (408): fort: (7): Attempt to use pointer R when it is not
associated with a target

However, the error analysis could be improved for both:
Ifort gives a trace, but even with "-g" it does not show where.
NAG at least coredumps and thus one can find out where it crashes:
gdb -> bt
...
#3  0x00002af4962e5e1a in __NAGf90_badptr1 () from /opt/nag/lib/libf98.so.1
#4  0x0000000000403338 in main (argc=1, argv=0x7fff14a00578) at pointest.f90:6

We should try to find something, which is easily debuggable (e.g. spitting out
the file and line number?). If we say that the user should use gdb himself [as
we used to with boundary check], then we should at least tell, were to set the
break point [unless we coredump, the one can use "bt"].
At least I didn't found it obvious to set a break point at "exit__" (or
something like that), which was also in a library not loaded when loading the
program in gdb. Well, fortunally -fbounds-check now prints file and line :-)


(The two pointer tests of Polyhedron's diagnotic check, by the way, only the
first type.)


-- 
           Summary: Run-time check using nullified pointers
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: tobias dot burnus at physik dot fu-berlin dot de


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

Reply via email to