This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/22488] [4.1 Regression] push_fields_onto_fieldstack calculates offset incorrectly
- From: "mmitchel at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 28 Sep 2005 15:57:31 -0000
- Subject: [Bug tree-optimization/22488] [4.1 Regression] push_fields_onto_fieldstack calculates offset incorrectly
- References: <20050714141428.22488.micis@gmx.de>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From mmitchel at gcc dot gnu dot org 2005-09-28 15:57 -------
> If so, are those fields of "A in B" really *there*, at those offsets
> from the beginning of type B?
Sort of. Because B would otherwise need a virtual table pointer, it just uses
the one in A. So, there is a vptr at offset zero from the start of B. However,
there's no actual A object at the same address as B because A is a virtual base.
There's certainly no A::i at offset four from the start of B, for example.
> The layout you had posted in the bug matches the offsets when we process
> the type A field of C, but not the type A field of type B.
Ugh.
We create two versions of class types: the "complete" class type and the
"as-base" type. (Look for CLASSTYPE_AS_BASE.) The as-base type does not
include virtual bases, and the B field in C should have the B-as-base type, not
the complete B type. The B-as-base type does not have the A parts. In fact, if
you look at layout_class_type, and, in particular, build_base_field, you'll see
it does use the as-base type.
However, at the end of layout_class_type, we have:
/* Now that we're done with layout, give the base fields the real types. */
and that installs the complete type.
Jason added this in 2004:
+ 2004-04-30 Jason Merrill <jason@redhat.com>
+
+ Refer to base members using COMPONENT_REFs where possible.
+ * class.c (build_simple_base_path): New fn.
+ (build_base_path): Use it for non-virtual base references.
+ (layout_class_type): Change base fields to their real type
+ after layout is done.
I think this is a hack so that later, when we use the COMPONENT_REFs, we don't
have to cast from the as-base type back to the nominal C++ type. (Of course,
this would also be cleaner with a real C++-lowering pass.)
However, I think the right thing is to have the cast; as you've discovered,
Jason's approach is lying about what's really there. Jason?
--
What |Removed |Added
----------------------------------------------------------------------------
CC| |jason at redhat dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22488