This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran 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]

Re: SIGSEV in user-defined elemental function


$> cat sigsev.f90
PROGRAM main
  TYPE :: atype
    INTEGER, POINTER :: p => null()
  END TYPE

  TYPE(atype), DIMENSION(:), POINTER :: t
  t => null()
  WRITE(*,*) func(t)

  CONTAINS
    ELEMENTAL LOGICAL FUNCTION func(t)
      TYPE(atype), INTENT(in) :: t
      func = ASSOCIATED(t%p)
    END FUNCTION
END PROGRAM

As output, I would expect an empty line (as func should not be called?)

I don't see why func wouldn't be called. And when it's called, then trying to use t%p when t is NULL is certainly the reason of your segfault.

The Sun compiler also generates an executable that segfaults at
runtime. With checking enabled, the Intel compiler says:

forrtl: severe (408): fort: (7): Attempt to use pointer T when it is
not associated with a target

Regards,
FX


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