This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/13114] [ABI] wrong class hierarchy
- From: "yanliu at ca dot ibm dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 25 Nov 2003 03:11:25 -0000
- Subject: [Bug c++/13114] [ABI] wrong class hierarchy
- References: <20031118203607.13114.yanliu@ca.ibm.com>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From yanliu at ca dot ibm dot com 2003-11-25 03:11 -------
(In reply to comment #3)
> not a bug. X is an empty base, and so can be overlaid. Please refer to the ABI
> documentation linked to from the gcc site.
Thanks for the quick reply. But I am not convinced :-). In this particular
testcase, X is a virtual empty base. According to C++ ABI, before mapping X,
the current dsize(ZZ) =8 ( which includes 4 bytes for its vft pointer, 4 bytes
for its data member -- int i), so, when it's time to mapping X, X should be
mapped at offset 8( not at offset 4). With option -fabi-version=2, the layout
of X is indeed at offset 8. But I don't understand why X's W is put at offset
12.
According to C++ ABI, " 3. If D is an empty proper base class:
Its allocation is similar to case (2) above, except that additional candidate
offsets are considered before starting at dsize(C). First, attempt to place D
at offset zero. If unsuccessful (due to a component type conflict), proceed
with attempts at dsize(C) as for non-empty bases. As for that case, if there is
a type conflict at dsize(C) (with alignment updated as necessary), increment
the candidate offset by nvalign(D), and try again, repeating until success
occurs.
Once offset(D) has been chosen, update sizeof(C) to max (sizeof(C), offset(D)
+sizeof(D)). Note that nvalign(D) is 1, so no update of align(C) is needed.
Similarly, since D is an empty base class, no update of dsize(C) is needed".
Accordingly, after mapping X, the dsize(ZZ) should not be updated, thus W
should be put at the same offset as X -- offset 12.
The following class hierarchy is generated from IBM's VAC++ compiler, what we
did is first try to put X at offset 0, but since X's W has type confliction
with Y's W at offset 0, therefor X is put at dsize(ZZ), which is 8. This time,
there is not type confliction, so both X and X are put at offset 8.
Class ZZ
size=8 align=4
ZZ (0x00000000) 0
vptridx=0 vptr=((&ZZ::_ZTV2ZZ) + 12)
Z (0x00000000) 0 nearly-empty
primary-for ZZ (0x00000000)
subvttidx=4
X (0x00000000) 8 empty virtual canonical
vbaseoffset=-12
W (0x00000000) 8 empty
Y (0x00000000) 0 empty
W (0x00000000) 0 empty
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13114