public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "janus at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/46408] [OOP] Segfault when running gfortran.dg/class_allocate_6.f03
Date: Sun, 02 Jan 2011 15:58:00 -0000	[thread overview]
Message-ID: <bug-46408-4-Ji6PPMZvn7@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-46408-4@http.gcc.gnu.org/bugzilla/>

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 = {};


  parent reply	other threads:[~2011-01-02 15:58 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-10 10:39 [Bug fortran/46408] New: " burnus at gcc dot gnu.org
2010-11-10 13:05 ` [Bug fortran/46408] " janus at gcc dot gnu.org
2010-11-11 10:09 ` burnus at gcc dot gnu.org
2010-11-20 22:02 ` danglin at gcc dot gnu.org
2011-01-02 15:58 ` janus at gcc dot gnu.org [this message]
2011-01-02 16:24 ` janus at gcc dot gnu.org
2011-01-02 17:51 ` janus at gcc dot gnu.org
2011-01-02 19:02 ` janus at gcc dot gnu.org
2011-01-02 19:24 ` janus at gcc dot gnu.org
2011-01-02 21:02 ` janus at gcc dot gnu.org
2011-01-02 21:20 ` janus at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-46408-4-Ji6PPMZvn7@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).