public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/6830: Virtual table layout: wrong vcall/vbase order for primary base class
@ 2002-07-03 13:07 nathan
0 siblings, 0 replies; 4+ messages in thread
From: nathan @ 2002-07-03 13:07 UTC (permalink / raw)
To: Grigory_Zagorodnev, gcc-bugs, gcc-prs, nathan, nobody
Synopsis: Virtual table layout: wrong vcall/vbase order for primary base class
Responsible-Changed-From-To: unassigned->nathan
Responsible-Changed-By: nathan
Responsible-Changed-When: Wed Jul 3 13:07:02 2002
Responsible-Changed-Why:
investigating
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6830
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: c++/6830: Virtual table layout: wrong vcall/vbase order for primary base class
@ 2002-07-03 13:27 nathan
0 siblings, 0 replies; 4+ messages in thread
From: nathan @ 2002-07-03 13:27 UTC (permalink / raw)
To: Grigory_Zagorodnev, gcc-bugs, gcc-prs, nathan
Synopsis: Virtual table layout: wrong vcall/vbase order for primary base class
State-Changed-From-To: open->closed
State-Changed-By: nathan
State-Changed-When: Wed Jul 3 13:27:45 2002
State-Changed-Why:
not a bug. see attached email
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6830
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: c++/6830: Virtual table layout: wrong vcall/vbase order for primary base class
@ 2002-07-03 13:26 Nathan Sidwell
0 siblings, 0 replies; 4+ messages in thread
From: Nathan Sidwell @ 2002-07-03 13:26 UTC (permalink / raw)
To: nathan; +Cc: gcc-prs
The following reply was made to PR c++/6830; it has been noted by GNATS.
From: Nathan Sidwell <nathan@codesourcery.com>
To: Grigory_Zagorodnev@vniief.ims.intel.com, gcc-gnats@gcc.gnu.org,
gcc-prs@gcc.gnu.org, nathan@gcc.gnu.org, gcc-bugs@gcc.gnu.org
Cc:
Subject: Re: c++/6830: Virtual table layout: wrong vcall/vbase order for primary
base class
Date: Wed, 03 Jul 2002 21:22:00 +0100
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6830
not a bug. You are misinterpreting the ABI spec.
(you do know about the -fdump-class-hierarchy flag don't you?) Anyway.
The V::g thunk in S's vtable uses a vcall offset that you should consider
part of S's vtable (not P's, the overridden class). So the vcall offset
is at a lower index than the vbase offsets.
This is the bit from 2.5.2 in the ABI (my emphasis)
Virtual call (vcall) offsets are used to perform ... These entries are
allocated in the virtual table for the *virtual* base class that is *most
immediately derived* from the base class containing the overridden.
Here the most immediately derived virtual base on the path from P->S->V is S.
The (ia32) vtable for V is and should be
12 vbase offset V to R
4 vbase offset V to S
0 offset to top
TI type info
.... primary vptr here
v::g final overrider
... start of secondary vtable (that for S)
-4 vcall offset (to V) for V::g thunk
8 vbase offset S to R
-4 offset to top
TI type info
vthunk(-4) to V::g
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* c++/6830: Virtual table layout: wrong vcall/vbase order for primary base class
@ 2002-05-27 3:36 Grigory_Zagorodnev
0 siblings, 0 replies; 4+ messages in thread
From: Grigory_Zagorodnev @ 2002-05-27 3:36 UTC (permalink / raw)
To: gcc-gnats
>Number: 6830
>Category: c++
>Synopsis: Virtual table layout: wrong vcall/vbase order for primary base class
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon May 27 03:26:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: Grigory Zagorodnev
>Release: 3.1
>Organization:
>Environment:
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ./configure
>Description:
The C++ ABI syas that...
2.5 Virtual Table Layout
2.5.2 Virtual Table Components and Order
"However, in classes sharing a virtual table with a primary base class, the
vcall and vbase offsets added by the derived class all come before the vcall
and vbase offsets required by the base class, so that the latter may be laid
out as required by the base class without regard to additions from the derived
class(es). "
In the attached testcase, P is the primary base for S. So we are following
quoted rule for vcall/vbase offsets order in it. Expected S's virtual table
layout is the following (vptr is the virtual table entry point):
vptr[-4] S's vbase offset
vptr[-3] P's vcall offset
vptr[-2] offset to top
vptr[-1] typeinfo ptr
g++ compiler violates described rule by changing order of P's vcall and S's
vbase offsets. It gives the following:
vptr[-4] P's vcall offset
vptr[-3] S's vbase offset
This happens both on ia-32 and ia-64.
PS: Hope there is enough information, use attached testcase to check the problem.
>How-To-Repeat:
1. compile testcase
g++3 -c fail.cpp
2. Run to see the output
Actual Results:
bad P's vcall offset
bad S's vbase offset
Expected Results:
Passed
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="fail.cpp"
Content-Disposition: inline; filename="fail.cpp"
#include <stdio.h>
struct P {
virtual int g (void) = 0;
};
struct R {
long long l;
};
struct S : virtual public R, public P {
virtual int g (void) { return 1; }
int i;
};
struct V : virtual public S {
int f(void){ return 1; };
int g (void) { return 1; }
};
V v;
#ifdef __ia64
# define PAD_INT_TO_VOID 4
#else
# define PAD_INT_TO_VOID 0
#endif
int main (void)
{
bool anyfail = false;
// Get S's virtual table entry point
size_t *vptr = *((size_t **)dynamic_cast<S*>(&v));
// Expected S's virtual table layout is the following:
// vptr[-1] typeinfo ptr
// vptr[-2] offset to top
// vptr[-3] P's vcall offset (note that P is the primary base for S)
// vptr[-4] S's vbase offset
if( vptr[-3] != -sizeof(void *) ) {
anyfail = true;
puts("bad P's vcall offset");
}
if( vptr[-4] != sizeof(void *) + sizeof(int) + PAD_INT_TO_VOID){
anyfail = true;
puts("bad S's vbase offset");
}
if( !anyfail )
puts("Passed");
return anyfail;
}
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2002-07-03 20:27 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-03 13:07 c++/6830: Virtual table layout: wrong vcall/vbase order for primary base class nathan
-- strict thread matches above, loose matches on Subject: below --
2002-07-03 13:27 nathan
2002-07-03 13:26 Nathan Sidwell
2002-05-27 3:36 Grigory_Zagorodnev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).