Your recent change
Mark Mitchell
mark@codesourcery.com
Sun Mar 26 10:53:00 GMT 2000
>>>>> "Richard" == Richard Kenner <kenner@vlsi1.ultra.nyu.edu> writes:
Richard> I'm so ignorant of C++ that I'm not even totally sure
Richard> what a "base class" is. Clearly this is due to some of
Richard> the BINFO stuff being wrong, but a little more direction
Richard> would help me *a lot*. Thanks!
Fortunately, it turns out the bug is just a typo. You did:
*************** finish_struct_1 (t)
*** 5283,5300 ****
if (vfield != NULL_TREE
&& DECL_FIELD_CONTEXT (vfield) != t)
{
- tree binfo = get_binfo (DECL_FIELD_CONTEXT (vfield), t, 0);
- tree offset = convert (bitsizetype, BINFO_OFFSET (binfo));
-
vfield = copy_node (vfield);
copy_lang_decl (vfield);
- if (! integer_zerop (offset))
- offset = size_binop (MULT_EXPR, offset, bitsize_int (BITS_PER_UNIT));
-
DECL_FIELD_CONTEXT (vfield) = t;
! DECL_FIELD_BITPOS (vfield)
! = size_binop (PLUS_EXPR, offset, bit_position (vfield));
TYPE_VFIELD (t) = vfield;
}
--- 5262,5276 ----
if (vfield != NULL_TREE
&& DECL_FIELD_CONTEXT (vfield) != t)
{
vfield = copy_node (vfield);
copy_lang_decl (vfield);
DECL_FIELD_CONTEXT (vfield) = t;
! DECL_FIELD_OFFSET (vfield)
! = size_binop (PLUS_EXPR,
! BINFO_OFFSET (get_binfo (DECL_FIELD_CONTEXT (vfield),
! t, 0)),
! DECL_FIELD_OFFSET (vfield));
TYPE_VFIELD (t) = vfield;
}
Note that the whole point of this code is change DECL_FIELD_CONTEXT
for the vfield, so changing when we evaluate DECL_FIELD_CONTEXT
changes what we get. Oops.
I'm testing the obvious fix now.
For future reference, here's a little on what a "base class" is.
In C++, you can write:
struct S { int i; };
struct T : public S { int j; };
If you wrote this in C, it would look roughly like:
struct T {
struct S __base;
int i;
};
In other words, a `T' starts off like an `S', but then adds some extra
stuff. `S' is the base class; `T' is the derived class. You can talk
about the fields of `S' as if they were the fields of a `T':
T t;
t.i = 3;
Similarly, every `T*' is implicitly also an `S*'.
(In other words, if GCC were written in C++, `tree_common' would be a
base class, and `tree_decl' would be a derived class.)
There is "multiple inheritance", i.e., you can write:
struct U : public T, public X { int k; };
This looks like:
struct U {
struct T __base1;
struct X __base2;
};
The BINFO_OFFSET for the `X' subobject in `U' will be non-zero; it's
not at the beginning of the `U'. So, although every `U*' is
implicitly also an `X*', doing that conversion requires code: the
BINFO_OFFSET must be added to the `U*' to get an `X*'.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
More information about the Gcc-bugs
mailing list