OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.2.2/] [gcc/] [testsuite/] [g++.old-deja/] [g++.abi/] [vtable2.C] - Diff between revs 149 and 154

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 149 Rev 154
// { dg-do run  }
// { dg-do run  }
// { dg-options "-fno-strict-aliasing" }
// { dg-options "-fno-strict-aliasing" }
// Origin: Mark Mitchell 
// Origin: Mark Mitchell 
#if defined (__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100
#if defined (__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100
#include 
#include 
struct S0
struct S0
{
{
  virtual void s0 ();
  virtual void s0 ();
};
};
struct S1 : virtual public S0
struct S1 : virtual public S0
{
{
  virtual void s1 ();
  virtual void s1 ();
};
};
struct S2 : virtual public S1
struct S2 : virtual public S1
{
{
  virtual void s1 ();
  virtual void s1 ();
  virtual void s0 ();
  virtual void s0 ();
};
};
struct S3
struct S3
{
{
  virtual void s3 ();
  virtual void s3 ();
};
};
struct S4 : public S3, virtual public S2
struct S4 : public S3, virtual public S2
{
{
  virtual void s1 ();
  virtual void s1 ();
};
};
void S0::s0 ()
void S0::s0 ()
{
{
}
}
void S1::s1 ()
void S1::s1 ()
{
{
}
}
void S2::s1 ()
void S2::s1 ()
{
{
}
}
void S2::s0 ()
void S2::s0 ()
{
{
}
}
void S3::s3 ()
void S3::s3 ()
{
{
}
}
void S4::s1 ()
void S4::s1 ()
{
{
}
}
/* The vtables should look like:
/* The vtables should look like:
   S0 primary vtable
   S0 primary vtable
     S0 offset to top
     S0 offset to top
     S0 RTTI
     S0 RTTI
     S0::s0
     S0::s0
   =================
   =================
   S1 primary vtable
   S1 primary vtable
     S0::s0 vcall offset
     S0::s0 vcall offset
     S0 vbase offset
     S0 vbase offset
     S1 offset to top
     S1 offset to top
     S1 RTTI
     S1 RTTI
     S0::s0
     S0::s0
     S1::s1
     S1::s1
   =================
   =================
   S2 primary vtable
   S2 primary vtable
     S2::s1 vcall offset
     S2::s1 vcall offset
     S1 vbase offset
     S1 vbase offset
     S2::s0 vcall offset
     S2::s0 vcall offset
     S0 vbase offset
     S0 vbase offset
     S2 offset to top
     S2 offset to top
     S2 RTTI
     S2 RTTI
     S2::s0
     S2::s0
     S2::s1
     S2::s1
   =================
   =================
   S3 primary vtable
   S3 primary vtable
     S3 offset to top
     S3 offset to top
     S3 RTTI
     S3 RTTI
     S3::s3
     S3::s3
   =================
   =================
   S4 primary vtable
   S4 primary vtable
     vbase offset for S0
     vbase offset for S0
     vbase offset for S1
     vbase offset for S1
     vbase offset for S2
     vbase offset for S2
     S4 offset to top
     S4 offset to top
     S4 RTTI
     S4 RTTI
     S3::s3
     S3::s3
     S4::s1
     S4::s1
   S2-in-S4 secondary vtable
   S2-in-S4 secondary vtable
     S1 vbase offset
     S1 vbase offset
     S4::s1 vcall offset
     S4::s1 vcall offset
     S0 vbase offset
     S0 vbase offset
     S2:s0 vcall offset
     S2:s0 vcall offset
     S2 offset to top
     S2 offset to top
     S4 RTTI
     S4 RTTI
     S2::s0
     S2::s0
     S4::s1
     S4::s1
*/
*/
// These are tricks to allow us to get raw function pointers for
// These are tricks to allow us to get raw function pointers for
// member functions.
// member functions.
extern "C" {
extern "C" {
  /* We can use weakref here without dg-require-weak, because we know
  /* We can use weakref here without dg-require-weak, because we know
     the symbols are defined, so we don't actually issue the .weak
     the symbols are defined, so we don't actually issue the .weak
     directives.  */
     directives.  */
  static void S3_s3 () __attribute__((__weakref__ ("_ZN2S32s3Ev")));
  static void S3_s3 () __attribute__((__weakref__ ("_ZN2S32s3Ev")));
  static void S4_s1 () __attribute__((__weakref__ ("_ZN2S42s1Ev")));
  static void S4_s1 () __attribute__((__weakref__ ("_ZN2S42s1Ev")));
}
}
// IA-64 uses function descriptors not function pointers in its vtables.
// IA-64 uses function descriptors not function pointers in its vtables.
#if defined __ia64__
#if defined __ia64__
#define CMP_VPTR(A, B)  (*(void **)(A) == *(void **)(B))
#define CMP_VPTR(A, B)  (*(void **)(A) == *(void **)(B))
#ifdef _LP64
#ifdef _LP64
#define INC_VPTR(A)     ((A) += 2)
#define INC_VPTR(A)     ((A) += 2)
#define INC_VDATA(A,N)  ((A) += (N))
#define INC_VDATA(A,N)  ((A) += (N))
#else
#else
#define INC_VPTR(A)     ((A) += 4)
#define INC_VPTR(A)     ((A) += 4)
#define INC_VDATA(A,N)  ((A) += 2*(N))
#define INC_VDATA(A,N)  ((A) += 2*(N))
#endif
#endif
#else
#else
#define CMP_VPTR(A, B)  (*(A) == (ptrdiff_t)(B))
#define CMP_VPTR(A, B)  (*(A) == (ptrdiff_t)(B))
#define INC_VPTR(A)     ((A) += 1)
#define INC_VPTR(A)     ((A) += 1)
#define INC_VDATA(A,N)  ((A) += (N))
#define INC_VDATA(A,N)  ((A) += (N))
#endif
#endif
int main ()
int main ()
{
{
  S4 s4;
  S4 s4;
  ptrdiff_t **vptr;
  ptrdiff_t **vptr;
  ptrdiff_t *vtbl;
  ptrdiff_t *vtbl;
  // Set vtbl to point at the beginning of S4's primary vtable.
  // Set vtbl to point at the beginning of S4's primary vtable.
  vptr = (ptrdiff_t **) &s4;
  vptr = (ptrdiff_t **) &s4;
  vtbl = *vptr;
  vtbl = *vptr;
  INC_VDATA (vtbl, -5);
  INC_VDATA (vtbl, -5);
  if (*vtbl != ((char*) (S0*) &s4) - (char*) &s4)
  if (*vtbl != ((char*) (S0*) &s4) - (char*) &s4)
    return 1;
    return 1;
  INC_VDATA (vtbl, 1);
  INC_VDATA (vtbl, 1);
  if (*vtbl != ((char*) (S1*) &s4) - (char*) &s4)
  if (*vtbl != ((char*) (S1*) &s4) - (char*) &s4)
    return 2;
    return 2;
  INC_VDATA (vtbl, 1);
  INC_VDATA (vtbl, 1);
  if (*vtbl != ((char*) (S2*) &s4) - (char*) &s4)
  if (*vtbl != ((char*) (S2*) &s4) - (char*) &s4)
    return 3;
    return 3;
  INC_VDATA (vtbl, 1);
  INC_VDATA (vtbl, 1);
  if (*vtbl != 0)
  if (*vtbl != 0)
    return 4;
    return 4;
  INC_VDATA (vtbl, 1);
  INC_VDATA (vtbl, 1);
  // Skip the RTTI entry.
  // Skip the RTTI entry.
  INC_VDATA (vtbl, 1);
  INC_VDATA (vtbl, 1);
  if (! CMP_VPTR (vtbl, &S3_s3))
  if (! CMP_VPTR (vtbl, &S3_s3))
    return 5;
    return 5;
  INC_VPTR (vtbl);
  INC_VPTR (vtbl);
  if (! CMP_VPTR (vtbl, &S4_s1))
  if (! CMP_VPTR (vtbl, &S4_s1))
    return 6;
    return 6;
  INC_VPTR (vtbl);
  INC_VPTR (vtbl);
  // The S1 vbase offset.
  // The S1 vbase offset.
  if (*vtbl != 0)
  if (*vtbl != 0)
    return 7;
    return 7;
  INC_VDATA (vtbl, 1);
  INC_VDATA (vtbl, 1);
  // The S4::s1 vcall offset is negative; once you convert to S2, you
  // The S4::s1 vcall offset is negative; once you convert to S2, you
  // have to convert to S4 to find the final overrider.
  // have to convert to S4 to find the final overrider.
  if (*vtbl != ((char*) &s4 - (char*) (S2*) &s4))
  if (*vtbl != ((char*) &s4 - (char*) (S2*) &s4))
    return 8;
    return 8;
  INC_VDATA (vtbl, 1);
  INC_VDATA (vtbl, 1);
  if (*vtbl != 0)
  if (*vtbl != 0)
    return 9;
    return 9;
  INC_VDATA (vtbl, 1);
  INC_VDATA (vtbl, 1);
  if (*vtbl != 0)
  if (*vtbl != 0)
    return 10;
    return 10;
  INC_VDATA (vtbl, 1);
  INC_VDATA (vtbl, 1);
  // Now we're at the S2 offset to top entry.
  // Now we're at the S2 offset to top entry.
  if (*vtbl != ((char*) &s4 - (char*) (S2*) &s4))
  if (*vtbl != ((char*) &s4 - (char*) (S2*) &s4))
    return 11;
    return 11;
  INC_VDATA (vtbl, 1);
  INC_VDATA (vtbl, 1);
  // Skip the RTTI entry.
  // Skip the RTTI entry.
  INC_VDATA (vtbl, 1);
  INC_VDATA (vtbl, 1);
  // Skip the remaining virtual functions -- they are thunks.
  // Skip the remaining virtual functions -- they are thunks.
  INC_VPTR (vtbl);
  INC_VPTR (vtbl);
  INC_VPTR (vtbl);
  INC_VPTR (vtbl);
}
}
#else /* !(defined (__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100) */
#else /* !(defined (__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100) */
int main ()
int main ()
{
{
}
}
#endif /* !(defined (__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100) */
#endif /* !(defined (__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100) */
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.