Segfault: is it a bug?

Tobias Burnus burnus@net-b.de
Thu Feb 15 10:52:00 GMT 2007


Hi Paul,

Paul Thomas wrote:
>  call create_field(quality,msh)
>  print *, "here"                    ! without this => seg fault
>  mshp => msh_(quality)
>
> I have seen something like this before - an I/O statement clearing a
> segfault.  Does anybody recall which PR it was?
Doesn't work here. I think you only hide the error, you don't get rid of
the error (what does valgrind tell you)?

Investigating PR30793 I found that gfortran generates for

function get_scalar_field_msh(fld)
    use class_mesh
    type(mesh), pointer :: get_scalar_field_msh
    type(scalar_field), intent(in), target  :: fld
    get_scalar_field_msh => msh_(fld%base)
end function get_scalar_field_msh

The code:

get_scalar_field_msh (fld)
{
  struct mesh * __result_get_scalar_field_msh;
  __result_get_scalar_field_msh->area.data = 0B; /* SIC! */
  __result_get_scalar_field_msh->dist.data = 0B; /* SIC! */
  __result_get_scalar_field_msh->interp.data = 0B; /* SIC! */
  __result_get_scalar_field_msh = msh_ (&fld->base);
  return __result_get_scalar_field_msh;
}

The lines marked by SIC look wrong as the C pointer
__result_get_scalar_field_msh points into the nirvana. (Besides,
initializing a pointer just to do a pointer assignment afterwards is
also crazy.)

Tobias



More information about the Fortran mailing list