[Bug fortran/46408] [OOP] Segfault when running gfortran.dg/class_allocate_6.f03

janus at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sun Jan 2 15:58:00 GMT 2011


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

--- Comment #4 from janus at gcc dot gnu.org 2011-01-02 15:58:13 UTC ---
Reduced test case:

type t
end type

type, extends(t) :: t2
  integer, allocatable :: a
end type

class(t), allocatable :: x, y

allocate(t2 :: x)
allocate(y, source=x)

end



As far as I can see, the copying routine itself is alright. The problem seems
to be with the default initialization of x%a. From the dump:


MAIN__ ()
{
  static struct t __def_init_MAIN___t;
  static struct t2 __def_init_MAIN___t2 = {};
  static struct __vtype_MAIN___t __vtab_MAIN___t = {._hash=6232021, ._size=0,
._extends=0B, ._def_init=&__def_init_MAIN___t, ._copy=__copy_MAIN___t};
  static struct __vtype_MAIN___t2 __vtab_MAIN___t2 = {._hash=43807140,
._size=8, ._extends=&__vtab_MAIN___t, ._def_init=&__def_init_MAIN___t2,
._copy=__copy_MAIN___t2};
  static struct __class_MAIN___t_a x = {};
  static struct __class_MAIN___t_a y = {};
  static void __copy_MAIN___t (struct t & restrict, struct t & restrict);
  static void __copy_MAIN___t2 (struct t2 & restrict, struct t2 & restrict);

  try
    {
      x._data = 0B;
      y._data = 0B;

      ! [ ... allocation of x._data ... ]

      (void) __builtin_memcpy ((void *) x._data, (void *) x._vptr->_def_init,
(<unnamed-unsigned:64>) x._vptr->_size);

      ! [ ... allocation of y.data ... ]

      x._vptr->_copy (x._data, y._data);
      (struct __vtype_MAIN___t *) y._vptr = (struct __vtype_MAIN___t *)
x._vptr;
    }
  finally
    {
      [...]
    }
}


x%a should get default-initialized to NULL via the memcpy call from
x._vptr->_def_init. The memcpy itself is done alright, but apparently the
_def_init variable is not properly initialized (is it?):

  static struct t2 __def_init_MAIN___t2 = {};



More information about the Gcc-bugs mailing list