This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH]: More virtual base stuff
- To: gcc-patches at gcc dot gnu dot org
- Subject: [C++ PATCH]: More virtual base stuff
- From: Nathan Sidwell <nathan at codesourcery dot com>
- Date: Thu, 26 Jul 2001 13:22:02 +0100
- CC: mark at codesourcery dot com
- Organization: Codesourcery LLC
Mark,
this fixes some more of the virtual base problems. get_binfo has the
bad habit, in the face of ambiguous bases, of returning an 'arbitrary'
choice. In this case it cound return the binfo of a non-primary instance
and therefore we'd think our vtable was not at offset zero. Fortunately
things are now simpler, as the vtable must be at offset zero.
When I've got the vbase initialization sorted, I'll probably go on a
crusade against get_binfo and related functions which behave this way.
booted & tested on i686-pc-linux-gnu, ok for mainline & branch?
more problems remain ...
nathan
--
Dr Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org
2001-07-26 Nathan Sidwell <nathan@codesourcery.com>
* class.c (finish_struct_1): When copying the primary base's
VFIELD, make sure we find it is at offset zero.
Index: cp/class.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/class.c,v
retrieving revision 1.399
diff -c -3 -p -r1.399 class.c
*** class.c 2001/07/25 08:54:06 1.399
--- class.c 2001/07/26 09:12:54
*************** finish_struct_1 (t)
*** 5092,5111 ****
/* Make sure that we get our own copy of the vfield FIELD_DECL. */
vfield = TYPE_VFIELD (t);
! if (vfield != NULL_TREE
! && DECL_FIELD_CONTEXT (vfield) != t)
{
! tree binfo = get_binfo (DECL_FIELD_CONTEXT (vfield), t, 0);
vfield = copy_decl (vfield);
-
DECL_FIELD_CONTEXT (vfield) = t;
- DECL_FIELD_OFFSET (vfield)
- = size_binop (PLUS_EXPR,
- BINFO_OFFSET (binfo),
- DECL_FIELD_OFFSET (vfield));
TYPE_VFIELD (t) = vfield;
}
overridden_virtuals
= modify_all_vtables (t, &vfuns, nreverse (overridden_virtuals));
--- 5092,5116 ----
/* Make sure that we get our own copy of the vfield FIELD_DECL. */
vfield = TYPE_VFIELD (t);
! if (vfield && CLASSTYPE_HAS_PRIMARY_BASE_P (t))
{
! tree primary = CLASSTYPE_PRIMARY_BINFO (t);
+ my_friendly_assert (same_type_p (DECL_FIELD_CONTEXT (vfield),
+ BINFO_TYPE (primary)),
+ 20010726);
+ /* The vtable better be at the start. */
+ my_friendly_assert (integer_zerop (DECL_FIELD_OFFSET (vfield)),
+ 20010726);
+ my_friendly_assert (integer_zerop (BINFO_OFFSET (primary)),
+ 20010726);
+
vfield = copy_decl (vfield);
DECL_FIELD_CONTEXT (vfield) = t;
TYPE_VFIELD (t) = vfield;
}
+ else
+ my_friendly_assert (!vfield || DECL_FIELD_CONTEXT (vfield) == t, 20010726);
overridden_virtuals
= modify_all_vtables (t, &vfuns, nreverse (overridden_virtuals));
// Special g++ Options: -w
// Copyright (C) 2001 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 26 Jul 2001 <nathan@codesourcery.com>
// Origin stefan@space.twc.de
// Bug 3145 case 10. Horribly complicated class hierarchy
class C0
{};
class C1
: public C0
{};
class C2
: public C1
, virtual public C0
{};
class C3
: public C1
, public C2
, virtual public C0
{};
class C4
: virtual public C1
, virtual public C0
, virtual public C3
, public C2
{};
class C5
: public C3
, virtual public C0
, virtual public C2
{};
class C6
: public C1
, public C2
, virtual public C5
, virtual public C3
, virtual public C0
{};
class C7
: public C1
, virtual public C5
, virtual public C4
, virtual public C2
, virtual public C0
, virtual public C6
{};
class C8
: virtual public C4
, public C3
, public C0
, virtual public C7
, virtual public C6
{};
class C9
: virtual public C0
, public C4
, public C8
, public C1
, public C6
{};
main() {
C0 c0;
C1 c1;
C2 c2;
C3 c3;
C4 c4;
C5 c5;
C6 c6;
C7 c7;
C8 c8;
C9 c9;
}