This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug fortran/67614] ICE on using arithmetic if with null


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67614

kargl at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kargl at gcc dot gnu.org

--- Comment #3 from kargl at gcc dot gnu.org ---
I'm inclined to close this PR as WONTFIX.  The F2008 in
2.4.8 states: "A pointer that is not associated shall
not be referenced or defined."  This is not a numbered
constraint and so a Fortran processor is not required
to report an error.  It is the programmer's responsibility
to ensure that a referenced pointer is associated.

In addition, consider the code

program y1
   real, pointer :: a
   real, target :: b
   b = 42
   a => b
   call foo(a)
   a => null()
   call foo(a)
   contains
      subroutine foo(x)
         real, pointer :: x
         if (2*x+1) 10, 20, 30
10       print *, 'a'; goto 40
20       print *, 'b'; goto 40
30       print *, 'c'; goto 40
40       continue
      end subroutine
end program y1

The evaluation of the scalar-numeric-expr in the
arithmetic-if would requires a runtime check that
x is in fact an associated pointer.  This could 
be rather costly and prevent possible optimizations
if gfortran tried to always ensure any reference
to a pointer is properly associated.

It is the responsibility of the programmer to
write

if (associated(x) then
   if (2*x+1) 10, 20, 30
   ...
end if

Of course, if someone wants to add an -fcheck=pointer-status
option, then problems in this PR can be at least checked.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]