public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "burnus at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/51529] [OOP] gfortran.dg/class_to_type_1.f03 is miscompiled: Uninitialized variable used
Date: Tue, 13 Dec 2011 22:23:00 -0000	[thread overview]
Message-ID: <bug-51529-4-vTffnJ9YSW@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-51529-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> 2011-12-13 22:18:44 UTC ---
The problem is the following, for:
  allocate(t2 :: x(10))
one has:
  x._data.data = (void * restrict) __builtin_malloc (640);

I had now expected that one would do:
  for (i = 1; i <= 10; i++)
    __builtin_memcpy ((void *) x._data,
                      (void *) &__vtab_MAIN___T2._def_init,
                      __vtab_MAIN___T2._size)

However, the current code does:
  struct t2 D.1921;
  struct t2 t2.2;
  integer(kind=8) D.1919;
  struct t[0:] * restrict D.1918;
  D.1918 = (struct t[0:] * restrict) x._data.data;
  D.1919 = x._data.offset;
  t2.2.t.b.data = 0B;
  t2.2.z = __complex__ (3.2999999523162841796875e+0,
4.400000095367431640625e+0);
  D.1921 = t2.2;
So far so good. That's the same as __vtab_MAIN___T2._def_init. Disadvantage:
Code duplication. Advantage: The information in in the same file (translation
unit).

However, instead of just doing a __builtin_memcpy in a loop, one calls:
  __vtab_MAIN___T2._copy (&D.1921,
                          (struct t *) D.1918
                          + (sizetype) ((S.3 + D.1919) * (integer(kind=8))
                          x._vptr->_size));

This has several disadvantages: First, makes the advantage of having all data
in the same translation unit void as one calls a function, located in another
translation unit. It is also much slower as _copy does many checks which we
know shouldn't matter. For MOLD= or a type-spec we know that the destination
does not have allocated allocatable components.


However, I do now understand why one needs for SOURCE= to memset the source to
NULL - at least as long _copy not only copies the data but also frees it. The
latter could be also left to _free. - Actually, I am in favour of separating
_copy and _free. As this issue shows, there are cases where one does not want
to combine them, leading to work around actions (memset). I think only for
polymorphic assignment, one needs _free + _copy, for allocate with SOURCE= a
_copy should be enough.


The reason for the crash is:

__copy_MAIN___T2 (struct t2 & restrict src, struct t2 & restrict dst)
{
  if (dst->t.b.data != 0B)
      __builtin_free ((void *) dst->t.b.data);

where dst == x._data.data, where the latter and thus also
x._data.data->t.b.data is filled with random memory.


  parent reply	other threads:[~2011-12-13 22:19 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-13 17:46 [Bug fortran/51529] New: " burnus at gcc dot gnu.org
2011-12-13 18:50 ` [Bug fortran/51529] [OOP] " pault at gcc dot gnu.org
2011-12-13 22:23 ` burnus at gcc dot gnu.org [this message]
2011-12-14  9:08 ` paul.richard.thomas at gmail dot com
2011-12-14 11:30 ` burnus at gcc dot gnu.org
2011-12-19  0:23 ` danglin at gcc dot gnu.org
2012-01-02 12:46 ` pault at gcc dot gnu.org
2012-01-02 13:06 ` pault 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-51529-4-vTffnJ9YSW@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).