Emptyness vs. virtualness

Nathan Sidwell nathan at codesourcery.com
Mon Apr 2 09:18:12 UTC 2001


Mark Mitchell wrote:
> 
> >>>>> "Jim" == Jim Dehnert <dehnert at transmeta.com> writes:
> 
>     Jim> But that's what I would have expected.  The rule is that we
>     Jim> first lay out the non-virtual things (C (not B), A2 (with A))
>     Jim> and then all the virtual bases (B).  By the time we get to B,
>     Jim> it's A can't be at 0, so we get a new one.
> 
> Yup, that's the issue all right.
> 
> So, how do we decide?
1) I don't recall any discussion of this - but that may be because I wasn't
paying attention.
2) It is the nearly empty base class optimization that's allowing C's B to
be C's primary base.
3) the allocation algorithm does not specify how *and* when indirect primary
bases are allocated, except when one becomes the primary base of the class
being layed out.
	[2.4]I.2.a defines the indirect primary base classes
	[2.4]I.2.b specifies how you pick one to be the primary base
	[2.4]II allocates all but the virtual bases
	[2.4]III allocates the virtual bases other than the indirect primary
	bases. It does mention that an indirect primary base that has been
	chosen as the primary base of some other base will be allocated there.
	The procedure for allocating these indirect primaries is documented
	here, but presumed to have happened earlier.

If we determine which bases get which indirect primaries directly after
determining the primary base, then we do not need to consider empty bases
in doing so (we just need to walk in inheritance graph order). I find this
simpler, as we keep the invariant that once a base becomes a primary in some
graph, it is always a primary in any graphs derived from that graph. Also
the exception, of when a base with an indirect primary base loses that primary
base in an inheritance graph is simple -- it is because some other base
with a higher priority `stole' it.

If we determine which bases get which indirect primaries during the virtual
base allocation, we have to consider empty bases. We lose the invariant of
the previous paragraph, and have to add another exception to when a base
loses its primary.

My vote as to how to resolve this is to assign the indirect primaries directly
after assigning the primary base. Obviously we won't know the offsets, but
we will know where in the inheritance graph they belong.

nathan

-- 
Dr Nathan Sidwell   ::   http://www.codesourcery.com   ::   CodeSourcery LLC
         'But that's a lie.' - 'Yes it is. What's your point?'
nathan at codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan at acm.org




More information about the cxx-abi-dev mailing list