public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* New type-based pool allocator code miscompiled due to aliasing issue?
@ 2015-06-11 16:55 Ulrich Weigand
  2015-06-11 17:33 ` pinskia
  0 siblings, 1 reply; 24+ messages in thread
From: Ulrich Weigand @ 2015-06-11 16:55 UTC (permalink / raw)
  To: gcc-patches; +Cc: mliska, law

Hello,

since the new type-based pool allocator was merged, the SPU toolchain
automated build / regression test has been failing due to crashes of
the compiled GCC due to random memory corruption.

Debugging this, it seems this is caused by GCC being miscompiled by
the host compiler.  As one example, var-tracking.c contains this
code in vt_initialize:

  empty_shared_hash = new shared_hash_def;
  empty_shared_hash->refcount = 1;

Via operator new, these bits of alloc-pool.h are inlined:

template <typename T>
inline T *
pool_allocator<T>::allocate ()
{
[...]
  /* Pull the first free element from the free list, and return it.  */
  header = m_returned_free_list;
  VALGRIND_DISCARD (VALGRIND_MAKE_MEM_DEFINED (header, sizeof (*header)));
  m_returned_free_list = header->next;
  m_elts_free--;
[...]
  /* Call default constructor.  */
  return (T *)(header);
}

Note that the read from "header->next" accesses the same memory location
as the write to "empty_shared_hash->refcount" above.

Type-based aliasing now assumes that those accesses cannot alias, since
they use incompatible types.  The scheduler then moves the write to
before the read, which causes m_returned_free_list to be set to 1,
causing a crash later on.

Now -- I'm only seeing this effect on my SPU toolchain regression test
machine, which uses a RHEL 5 distribution with its default GCC 4.1.2
system compiler.  (Using -fno-strict-aliasing fixes the symptom.)

Maybe this old compiler simply has a bug in type-based aliasing.  But
on the other hand, I'm not completely sure whether this *is* a bug --
is the code above supposed to be valid C++, or does it in fact violate
the aliasing rules after all?

Bye,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU/Linux compilers and toolchain
  Ulrich.Weigand@de.ibm.com

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2015-06-24 10:58 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-11 16:55 New type-based pool allocator code miscompiled due to aliasing issue? Ulrich Weigand
2015-06-11 17:33 ` pinskia
2015-06-11 17:54   ` Jakub Jelinek
2015-06-11 19:50     ` Richard Biener
2015-06-15  9:13       ` Martin Liška
2015-06-15  9:14         ` Andrew Pinski
2015-06-15 12:31           ` Martin Liška
2015-06-15 17:43             ` Marc Glisse
2015-06-16  7:47               ` Richard Biener
2015-06-16  9:49               ` Martin Liška
2015-06-16 13:24                 ` Richard Biener
2015-06-16 13:45                   ` Martin Liška
2015-06-16 14:04                     ` Richard Biener
2015-06-16 15:54                       ` Martin Liška
2015-06-16 16:02                         ` Richard Biener
2015-06-17  9:18                         ` Martin Jambor
2015-06-17 11:22                           ` Richard Biener
2015-06-17 11:29                           ` Jakub Jelinek
2015-06-17 11:33                             ` Richard Biener
2015-06-17 15:32                               ` Martin Liška
2015-06-18 11:18                                 ` Richard Biener
2015-06-23 19:49                                   ` Pat Haugen
2015-06-24 11:10                                     ` Martin Liška
2015-06-16 19:26                 ` Marc Glisse

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