public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c++/8979: Layout of class with virtual inheritance problem on IA64
@ 2002-12-17 5:46 johnb
0 siblings, 0 replies; only message in thread
From: johnb @ 2002-12-17 5:46 UTC (permalink / raw)
To: gcc-gnats
>Number: 8979
>Category: c++
>Synopsis: Layout of class with virtual inheritance problem on IA64
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Dec 17 05:46:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: Eugeny Belov
>Release: gcc 3.2 on United Linux 1.0 (IA64) (no more info is there)
>Organization:
>Environment:
United Linux 1.0 on IA64 box
>Description:
I have got a testcase from Codesourcery`s ABI validation suite named virtual2.cpp, it fails with error code 8 on IA64. Here is shorter example of code.
#include <iostream>
#ifdef __ia64__
#define INT_PADDED 8
#else
#define INT_PADDED 4
#endif
typedef const ptrdiff_t* vptr_t; /* The type of a pointer to a vtable. */
template <typename DERIVED, typename BASE>
inline ptrdiff_t
base_offset_of () {
DERIVED d;
return ((char*) (BASE*) (&d)) - (char*) &d;
}
struct S {
int i;
int j;
};
struct T : virtual public S {
int k;
};
struct U3 : virtual public T, virtual public S {
};
int main ()
{
if (base_offset_of<U3,S>() != (2*sizeof(vptr_t) + INT_PADDED)) {
std::cout << "FAILED\n";
return 8;
}
std::cout << "PASSED\n";
return 0;
}
What I`ve got for U3 layout using g++ with -fdump-class-hierarchy key:
Class U3
size=32 align=8
U3 (0x2000000000372080) 0 nearly-empty
vptridx=0 vptr=((&U3::_ZTV2U3) + 32)
T (0x2000000000372100) 8 virtual canonical
subvttidx=16 vptridx=8 vbaseoffset=-24 vptr=((&U3::_ZTV2U3) + 56)
S (0x2000000000372180) 20 virtual canonical
vbaseoffset=-32
S (0x2000000000372200) 20 virtual non-canonical
vbaseoffset=-32
It looks that class S is wrong aligned by 4 bytes instead of 8 as expected. As I understood there should be 4 bytes padding after the T::k member.
>How-To-Repeat:
Compile testcase in Description field with g++ 3.2 and run it, it will print "FAILED".
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="virtual2.cpp"
Content-Disposition: inline; filename="virtual2.cpp"
/***********************************************************************
File: virtual2.cpp
Author: CodeSourcery, LLC
Date: 8/22/2000
***********************************************************************/
// Check that, when a class with a virtual base is included as a base
// class, its non-virtual size is used.
#include "abi-test.hpp"
struct S {
int i;
int j;
};
struct T : virtual public S {
int k;
};
struct U1 : virtual public S, public T {
};
struct U2 : virtual public S, virtual public T {
};
struct U3 : virtual public T, virtual public S {
};
int main (void)
{
// T is allocated first.
ASSERT_BASE_OFFSET (U1, T, 0, 1);
// And then the virtual base S.
ASSERT_BASE_OFFSET (U1, S,
(sizeof (vptr_t)
+ pad_size_to_alignment<int, vptr_t>()),
2);
// And the total size should not include two copies of S.
ABI_TEST (sizeof (U1) == sizeof (T), 3);
// Finally, allocate any direct or indirect virtual base classes
// (except the primary base clas or any indirect primary base
// classes) as we did non-virtual base classes, in inheritance graph
// order.
// U2's vtable pointer is allocated first.
// S is allocated next.
ASSERT_BASE_OFFSET (U2, S, sizeof (vptr_t), 4);
// And then the virtual base T without its virtual base.
ASSERT_BASE_OFFSET (U2, T, sizeof (vptr_t) + sizeof (S), 5);
// And the total size should not include two copies of S.
ABI_TEST (sizeof (U2) == (pad_size_to_alignment<int, vptr_t>() + 2 * sizeof (int) + 2*sizeof (vptr_t)), 6);
// U3's vtable pointer is allocated first.
// T is allocated next.
ASSERT_BASE_OFFSET (U3, T, sizeof (vptr_t), 7);
// And then the virtual base T without its virtual base.
ASSERT_BASE_OFFSET (U3, S, (2*sizeof (vptr_t) + pad_size_to_alignment<int, vptr_t>()), 8);
// And the total size should not include two copies of S.
ABI_TEST (sizeof (U3) == (pad_size_to_alignment<int, vptr_t>() + 2 * sizeof (int) + 2*sizeof (vptr_t)), 9);
return EXIT_SUCCESS;
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2002-12-17 13:46 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-17 5:46 c++/8979: Layout of class with virtual inheritance problem on IA64 johnb
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).