This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: GCC 3.2
Hi,
Atttached is a datatest.cxx file I abstracted from code that does this in
the cppu module of OpenOffice.org. I am not the original author of the
code (I just pulled it into a standalone version to ease testing). The
code is LGPL'd so it should be fine for inclusion if you want it.
Under gcc 2.95.X compile with
g++ -O2 -odatatest datatest.cxx
./datatest
Under gcc 3.X compile with
g++ -DADJUST_ALIGN -O2 -odatatest datatest.cxx
./datatest
It was not meant to necessarily show problems. It was meant to detect
changes from gcc 2.95.X to gcc 3.X that would impact OpenOffice.org C++ to
UNO component bridging code.
Hope this helps,
Kevin
On August 21, 2002 12:49, Benjamin Kosnik wrote:
> > As is will your tests detect any layout issues (changes in sizeof and
> > offsetof of structure members) like the datatest.cxx, I abstracted
> > from OOo code and sent to Franz? It was those changes from gcc 2.95.X
> > to gcc 3.X that made the C++ to uno bridge codeneed to use an
> > alignment
>
> No. currently it only checks for added/removed symbols and object size.
> Can you please send me your test file datatest.cxx..
>
> The goal is to get basic ABI stuff in now, and then the sizeof/alignof
> bits can go in at a later date.
>
> -benjamin
#include <stdlib.h>
#include <stdio.h>
typedef struct _Any
{
void * pType;
void * pData;
void * pReserved;
} uno_Any;
typedef _Any Any;
// Patching the gcc 3 incompatible alignment change for linux
// This pragma macro is appended to every first member of a struct,
// iff the struct inherits from a base struct and the first member
// of this structure is not a double or [unsigned] long long.
#ifdef ADJUST_ALIGN
#define CPPU_GCC3_ALIGN( base_struct ) __attribute__ ((aligned (__alignof__ (base_struct))))
#else
#define CPPU_GCC3_ALIGN( base_struct )
#endif
typedef enum {
My_BYTE,
MY_CHAR,
MY_INT,
MY_LONG,
MY_LONGLONG,
MY_FLOAT,
MY_DOUBLE
} TypeClass;
#if defined(__GNUC__) && defined(__linux__) && defined(__intel__)
#define MAX_ALIGNMENT_4
#endif
#define OFFSET_OF( s, m ) ((size_t)((char *)&((s *)16)->m -16))
#define BINTEST_VERIFY( c ) \
if (! (c)) { fprintf( stderr, "### binary compatibility test failed: " #c " [line %d]!!!\n", __LINE__ ); /* abort();*/ }
#define BINTEST_VERIFYOFFSET( s, m, n ) \
if (OFFSET_OF(s, m) != n) { fprintf( stderr, "### OFFSET_OF(" #s ", " #m ") = %d instead of expected %d!!!\n", OFFSET_OF(s, m), n ); /* abort();*/ }
#define BINTEST_VERIFYSIZE( s, n ) \
fprintf( stderr, "> sizeof(" #s ") = %d; __alignof__ (" #s ") = %d\n", sizeof(s), __alignof__ (s) ); \
if (sizeof(s) != n) { fprintf( stderr, "### sizeof(" #s ") = %d instead of expected %d!!!\n", sizeof(s), n ); /* abort();*/ }
struct C1
{
signed short n1;
};
struct C2 : public C1
{
signed long n2 CPPU_GCC3_ALIGN( C1 );
};
struct C3 : public C2
{
double d3;
signed long n3;
};
struct C4 : public C3
{
signed long n4 CPPU_GCC3_ALIGN( C3 );
double d4;
};
struct C5 : public C4
{
signed long long n5;
unsigned char b5;
};
struct C6 : public C1
{
C5 c6 CPPU_GCC3_ALIGN( C1 );
unsigned char b6;
};
struct D
{
signed short d;
signed long e;
};
struct E
{
unsigned char a;
unsigned char b;
unsigned char c;
signed short d;
signed long e;
};
struct M
{
signed long n;
signed short o;
};
struct N : public M
{
signed short p CPPU_GCC3_ALIGN( M );
};
struct N2
{
M m;
signed short p;
};
struct O : public M
{
double p;
};
struct O2 : public O
{
double p2;
};
struct P : public N
{
double p2;
};
struct empty
{
};
struct second : public empty
{
int a;
};
struct AlignSize_Impl
{
signed short nInt16;
double dDouble;
};
struct Char1
{
char c1;
};
struct Char2 : public Char1
{
char c2 CPPU_GCC3_ALIGN( Char1 );
};
struct Char3 : public Char2
{
char c3 CPPU_GCC3_ALIGN( Char2 );
};
struct Char4
{
Char3 chars;
char c;
};
class BinaryCompatible_Impl
{
public:
BinaryCompatible_Impl();
};
BinaryCompatible_Impl::BinaryCompatible_Impl()
{
#ifdef MAX_ALIGNMENT_4
// max alignment is 4
BINTEST_VERIFYOFFSET( AlignSize_Impl, dDouble, 4 );
BINTEST_VERIFYSIZE( AlignSize_Impl, 12 );
#else
// max alignment is 8
BINTEST_VERIFYOFFSET( AlignSize_Impl, dDouble, 8 );
BINTEST_VERIFYSIZE( AlignSize_Impl, 16 );
#endif
// enum
BINTEST_VERIFY( sizeof( TypeClass ) == sizeof( signed long ) );
// any
BINTEST_VERIFY( sizeof(void *) >= sizeof(signed long) );
BINTEST_VERIFY( sizeof( Any ) == sizeof( _Any ) );
BINTEST_VERIFY( sizeof( Any ) == sizeof( void * ) * 3 );
BINTEST_VERIFYOFFSET( Any, pType, 0 );
BINTEST_VERIFYOFFSET( Any, pData, 4 );
BINTEST_VERIFYOFFSET( Any, pReserved, 8 );
// struct
BINTEST_VERIFYSIZE( M, 8 );
BINTEST_VERIFYOFFSET( M, o, 4 );
BINTEST_VERIFYSIZE( N, 12 );
BINTEST_VERIFYOFFSET( N, p, 8 );
BINTEST_VERIFYSIZE( N2, 12 );
BINTEST_VERIFYOFFSET( N2, p, 8 );
BINTEST_VERIFYSIZE( O, 16 );
BINTEST_VERIFYSIZE( D, 8 );
BINTEST_VERIFYOFFSET( D, e, 4 );
BINTEST_VERIFYOFFSET( E, d, 4 );
BINTEST_VERIFYOFFSET( E, e, 8 );
BINTEST_VERIFYSIZE( C1, 2 );
BINTEST_VERIFYSIZE( C2, 8 );
BINTEST_VERIFYOFFSET( C2, n2, 4 );
#ifdef MAX_ALIGNMENT_4
BINTEST_VERIFYSIZE( C3, 20 );
BINTEST_VERIFYOFFSET( C3, d3, 8 );
BINTEST_VERIFYOFFSET( C3, n3, 16 );
BINTEST_VERIFYSIZE( C4, 32 );
BINTEST_VERIFYOFFSET( C4, n4, 20 );
BINTEST_VERIFYOFFSET( C4, d4, 24 );
BINTEST_VERIFYSIZE( C5, 44 );
BINTEST_VERIFYOFFSET( C5, n5, 32 );
BINTEST_VERIFYOFFSET( C5, b5, 40 );
BINTEST_VERIFYSIZE( C6, 52 );
BINTEST_VERIFYOFFSET( C6, c6, 4 );
BINTEST_VERIFYOFFSET( C6, b6, 48 );
#else
BINTEST_VERIFYSIZE( C3, 24 );
BINTEST_VERIFYOFFSET( C3, d3, 8 );
BINTEST_VERIFYOFFSET( C3, n3, 16 );
BINTEST_VERIFYSIZE( C4, 40 );
BINTEST_VERIFYOFFSET( C4, n4, 24 );
BINTEST_VERIFYOFFSET( C4, d4, 32 );
BINTEST_VERIFYSIZE( C5, 56 );
BINTEST_VERIFYOFFSET( C5, n5, 40 );
BINTEST_VERIFYOFFSET( C5, b5, 48 );
BINTEST_VERIFYSIZE( C6, 72 );
BINTEST_VERIFYOFFSET( C6, c6, 8 );
BINTEST_VERIFYOFFSET( C6, b6, 64 );
#endif
BINTEST_VERIFYSIZE( O2, 24 );
BINTEST_VERIFYOFFSET( O2, p2, 16 );
BINTEST_VERIFYSIZE( Char3, 3 );
BINTEST_VERIFYOFFSET( Char4, c, 3 );
#ifdef MAX_ALIGNMENT_4
// max alignment is 4
BINTEST_VERIFYSIZE( P, 20 );
#else
// alignment of P is 8, because of P[] ...
BINTEST_VERIFYSIZE( P, 24 );
BINTEST_VERIFYSIZE( second, sizeof( int ) );
#endif
}
static BinaryCompatible_Impl aTest;
int main ()
{
exit(0);
}