public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/48035] New: Mismatch on size of class when initializing hierarchy involving virtual inheritance and empty base classes
@ 2011-03-08 22:14 scot4spam at yahoo dot com
  2011-03-08 22:43 ` [Bug c++/48035] " pinskia at gcc dot gnu.org
                   ` (16 more replies)
  0 siblings, 17 replies; 18+ messages in thread
From: scot4spam at yahoo dot com @ 2011-03-08 22:14 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: Mismatch on size of class when initializing hierarchy
                    involving virtual inheritance and empty base classes
           Product: gcc
           Version: 4.4.5
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: scot4spam@yahoo.com


Created attachment 23585
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=23585
preprocessed source file

The attached preprocessed source file is a much-simplified version of a more
complex class hierarchy involving several levels of virtual inheritance and
empty classes in the hierarchy.

"g++ -v" details:
Using built-in specs.
Target: i686-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla
--enable-bootstrap --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-gnu-unique-object
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk
--disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre
--enable-libgcj-multifile --enable-java-maintainer-mode
--with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib
--with-ppl --with-cloog --with-tune=generic --with-arch=i686
--build=i686-redhat-linux
Thread model: posix
gcc version 4.4.5 20101112 (Red Hat 4.4.5-2) (GCC)

Also tested with a new build:
Using built-in specs.
COLLECT_GCC=./g++
Target: i686-pc-linux-gnu
Configured with: ./configure
Thread model: posix
gcc version 4.5.2 (GCC)

Among others.

Compile with "g++ -c vtable-bug.i".

What we observe (tested on x86 and ARM) is that "operator new" is called to
allocate 12 bytes for the class (and sizeof matches that 12 byte size), but the
compiled code then proceeds to load four-byte 0's into offsets 0, 4, 8, AND 12
from the allocated buffer, stomping data at byte offsets 12-15.  (More complex
hierarchies can result in more than one 4-byte offset being stomped, and/or the
same offset being initialized repeatedly.)

Changing which classes are virtual, or adding data to empty base classes,
changes or fixes the behavior.


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

end of thread, other threads:[~2011-10-13 18:07 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-08 22:14 [Bug c++/48035] New: Mismatch on size of class when initializing hierarchy involving virtual inheritance and empty base classes scot4spam at yahoo dot com
2011-03-08 22:43 ` [Bug c++/48035] " pinskia at gcc dot gnu.org
2011-03-08 22:46 ` [Bug c++/48035] [4.4/4.5/4.6 Regression] " pinskia at gcc dot gnu.org
2011-03-09 11:45 ` dodji at gcc dot gnu.org
2011-03-09 12:46 ` jakub at gcc dot gnu.org
2011-03-09 14:04 ` jakub at gcc dot gnu.org
2011-03-11 14:47 ` jakub at gcc dot gnu.org
2011-03-11 15:44 ` jakub at gcc dot gnu.org
2011-03-11 15:47 ` [Bug c++/48035] [4.4/4.5 " jakub at gcc dot gnu.org
2011-04-10 10:49 ` rguenth at gcc dot gnu.org
2011-04-11 21:23 ` tschwinge at gcc dot gnu.org
2011-04-16  9:58 ` jakub at gcc dot gnu.org
2011-04-18 14:04 ` rguenth at gcc dot gnu.org
2011-04-18 14:44 ` [Bug c++/48035] [4.4 " rguenth at gcc dot gnu.org
2011-09-23 22:02 ` paolo.carlini at oracle dot com
2011-10-05  8:11 ` sezeroz at gmail dot com
2011-10-13 18:06 ` jason at gcc dot gnu.org
2011-10-13 18:07 ` jason at gcc dot gnu.org

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