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


On Tuesday 21 November 2006 08:31, François-Xavier Coudert wrote:

FX,

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

which version of ifort do you use? Here, with v9.0, I get:
$> ifort -g -warn all -check all main.f90 && ./a.out
[empty line]
$>

Which is, what I expected.

> 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.

I'm not sure how ELEMENTAL is implemented, but since the argument type of 
func() is not a pointer type but a reference, one can not try to avoid this 
segfault by

    ELEMENTAL LOGICAL FUNCTION func(t)
      TYPE(atype), INTENT(in) :: t
      IF (ASSOCIATED(t))
        func = ASSOCIATED(t%p)
      ELSE
        func = .FALSE.
      END IF 
    END FUNCTION

or similar since both, gfortran and ifort, complain that 't' is lacking the 
pointer attribute. Also, if func is put in a module, gdb shows a reference 
for t, which is, from my point of view, questionable. I wouldn't argue if a 
reference to null would be passed, but a random(?) address?

(gdb) run
Program received signal SIGSEGV, Segmentation fault.
0x0804859d in __themod__func (t=@0xf465f440) at sigsev.f90:31
31            func = ASSOCIATED(t%p)

Regards
	Daniel


P.S. The modified code:

MODULE themod
  TYPE :: atype
    INTEGER, POINTER :: p => null()
  END TYPE

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

PROGRAM main
  USE themod

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


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