This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH]: Fix PR 13114, 13115
- From: Nathan Sidwell <nathan at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Mark Mitchell <mitchell at codesourcery dot com>
- Date: Fri, 12 Dec 2003 14:51:09 +0000
- Subject: [C++ PATCH]: Fix PR 13114, 13115
- Organization: Codesourcery LLC
Hi,
I've installed this fix for PRs 13114 and 13115. The bug only manifests
in the internal data structures and -fdump-class-hierarchy output --
it does not effect code generation, hence there is no test case. I attach
the bug reports code. To check the bug one would need to convert
directly from a ZZ object to the empty ambiguous W base within X. As
such a conversion is invalid (W is ambigous), one must first convert to
an X. At that point g++ starts using the binfo hiearachy of X, which
is correct.
built & tested on i686-pc-linux-gnu.
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
The voices in my head said this was stupid too
nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk
2003-12-12 Nathan Sidwell <nathan@codesourcery.com>
PR c++/13114, c++/13115
* class.c (layout_empty_base): Propagate the move of an empty base
to offset zero.
Index: cp/class.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/class.c,v
retrieving revision 1.584
diff -c -3 -p -r1.584 class.c
*** cp/class.c 6 Dec 2003 22:11:40 -0000 1.584
--- cp/class.c 12 Dec 2003 14:39:16 -0000
*************** layout_empty_base (tree binfo, tree eoc,
*** 3576,3589 ****
/* This routine should only be used for empty classes. */
my_friendly_assert (is_empty_class (basetype), 20000321);
alignment = ssize_int (CLASSTYPE_ALIGN_UNIT (basetype));
-
- if (abi_version_at_least (2))
- BINFO_OFFSET (binfo) = size_zero_node;
- if (warn_abi && !integer_zerop (BINFO_OFFSET (binfo)))
- warning ("offset of empty base `%T' may not be ABI-compliant and may"
- "change in a future version of GCC",
- BINFO_TYPE (binfo));
/* This is an empty base class. We first try to put it at offset
zero. */
if (layout_conflict_p (binfo,
--- 3576,3593 ----
/* This routine should only be used for empty classes. */
my_friendly_assert (is_empty_class (basetype), 20000321);
alignment = ssize_int (CLASSTYPE_ALIGN_UNIT (basetype));
+ if (!integer_zerop (BINFO_OFFSET (binfo)))
+ {
+ if (abi_version_at_least (2))
+ propagate_binfo_offsets
+ (binfo, size_diffop (size_zero_node, BINFO_OFFSET (binfo)));
+ else if (warn_abi)
+ warning ("offset of empty base `%T' may not be ABI-compliant and may"
+ "change in a future version of GCC",
+ BINFO_TYPE (binfo));
+ }
+
/* This is an empty base class. We first try to put it at offset
zero. */
if (layout_conflict_p (binfo,
struct W { int : 0;};
struct X : public W { };//W at zero in X
struct Y : public W { };//W at zero in Y
struct Z : virtual public X, public Y { };//Y at zero, X at 4
struct ZZ : public Z {//X at 8
int i;
int func() { return 0;};
};
int main(void) {
ZZ zz;
void *x_ptr = static_cast <X *> (&zz);
void *w_x_ptr = 0;
return 0;
}