From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17091 invoked by alias); 28 Sep 2005 15:57:34 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 17055 invoked by uid 48); 28 Sep 2005 15:57:31 -0000 Date: Wed, 28 Sep 2005 15:57:00 -0000 Message-ID: <20050928155731.17053.qmail@sourceware.org> From: "mmitchel at gcc dot gnu dot org" To: gcc-bugs@gcc.gnu.org In-Reply-To: <20050714141428.22488.micis@gmx.de> References: <20050714141428.22488.micis@gmx.de> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug tree-optimization/22488] [4.1 Regression] push_fields_onto_fieldstack calculates offset incorrectly X-Bugzilla-Reason: CC X-SW-Source: 2005-09/txt/msg03503.txt.bz2 List-Id: ------- 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 + + 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