diff options
author | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
---|---|---|
committer | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
commit | 554fd8c5195424bdbcabf5de30fdc183aba391bd (patch) | |
tree | 976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/g++.dg/compat | |
download | cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2 cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz |
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig;
imported gcc-4.6.4 source tree from verified upstream tarball.
downloading a git-generated archive based on the 'upstream' tag
should provide you with a source tree that is binary identical
to the one extracted from the above tarball.
if you have obtained the source via the command 'git clone',
however, do note that line-endings of files in your working
directory might differ from line-endings of the respective
files in the upstream repository.
Diffstat (limited to 'gcc/testsuite/g++.dg/compat')
153 files changed, 5794 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/compat/abi/bitfield1.h b/gcc/testsuite/g++.dg/compat/abi/bitfield1.h new file mode 100644 index 000000000..09d64162f --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/abi/bitfield1.h @@ -0,0 +1,10 @@ +typedef int Int; +typedef signed int SInt; +typedef unsigned int UInt; + +struct A +{ + SInt bitS : 1; // signed + UInt bitU : 1; // unsigned + Int bit : 1; // signedness by -f{signed,unsigned}-bitfields +}; diff --git a/gcc/testsuite/g++.dg/compat/abi/bitfield1_main.C b/gcc/testsuite/g++.dg/compat/abi/bitfield1_main.C new file mode 100644 index 000000000..ce9aa1f09 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/abi/bitfield1_main.C @@ -0,0 +1,13 @@ +// { dg-options "-w -ansi -pedantic-errors -funsigned-bitfields" } + +// Copyright (C) 2001 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 15 Dec 2001 <nathan@codesourcery.com> +// Split into pieces for binary compatibility testing October 2002 + +extern void bitfield1_x (void); + +int +main () +{ + bitfield1_x (); +} diff --git a/gcc/testsuite/g++.dg/compat/abi/bitfield1_x.C b/gcc/testsuite/g++.dg/compat/abi/bitfield1_x.C new file mode 100644 index 000000000..727632af8 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/abi/bitfield1_x.C @@ -0,0 +1,16 @@ +// { dg-options "-w -ansi -pedantic-errors -funsigned-bitfields" } + +#include "bitfield1.h" + +extern void bitfield1_y (A& a); + +void bitfield1_x () +{ + A a; + + a.bitS = 1; + a.bitU = 1; + a.bit = 1; + + bitfield1_y (a); +} diff --git a/gcc/testsuite/g++.dg/compat/abi/bitfield1_y.C b/gcc/testsuite/g++.dg/compat/abi/bitfield1_y.C new file mode 100644 index 000000000..282776718 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/abi/bitfield1_y.C @@ -0,0 +1,15 @@ +// { dg-options "-w -ansi -pedantic-errors -funsigned-bitfields" } + +extern "C" void abort (void); + +#include "bitfield1.h" + +void bitfield1_y (A& a) +{ + if (a.bitS != -1) + abort (); + if (a.bitU != 1) + abort (); + if (a.bit != 1) + abort (); +} diff --git a/gcc/testsuite/g++.dg/compat/abi/bitfield2.h b/gcc/testsuite/g++.dg/compat/abi/bitfield2.h new file mode 100644 index 000000000..09d64162f --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/abi/bitfield2.h @@ -0,0 +1,10 @@ +typedef int Int; +typedef signed int SInt; +typedef unsigned int UInt; + +struct A +{ + SInt bitS : 1; // signed + UInt bitU : 1; // unsigned + Int bit : 1; // signedness by -f{signed,unsigned}-bitfields +}; diff --git a/gcc/testsuite/g++.dg/compat/abi/bitfield2_main.C b/gcc/testsuite/g++.dg/compat/abi/bitfield2_main.C new file mode 100644 index 000000000..4169843f9 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/abi/bitfield2_main.C @@ -0,0 +1,13 @@ +// { dg-options "-w -ansi -pedantic-errors -fsigned-bitfields" } + +// Copyright (C) 2001 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 15 Dec 2001 <nathan@codesourcery.com> +// Split into pieces for binary compatibility testing October 2002 + +extern void bitfield1_x (void); + +int +main () +{ + bitfield1_x (); +} diff --git a/gcc/testsuite/g++.dg/compat/abi/bitfield2_x.C b/gcc/testsuite/g++.dg/compat/abi/bitfield2_x.C new file mode 100644 index 000000000..080d21b41 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/abi/bitfield2_x.C @@ -0,0 +1,16 @@ +// { dg-options "-w -ansi -pedantic-errors -fsigned-bitfields" } + +#include "bitfield1.h" + +extern void bitfield1_y (A& a); + +void bitfield1_x () +{ + A a; + + a.bitS = 1; + a.bitU = 1; + a.bit = 1; + + bitfield1_y (a); +} diff --git a/gcc/testsuite/g++.dg/compat/abi/bitfield2_y.C b/gcc/testsuite/g++.dg/compat/abi/bitfield2_y.C new file mode 100644 index 000000000..d27578328 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/abi/bitfield2_y.C @@ -0,0 +1,15 @@ +// { dg-options "-w -ansi -pedantic-errors -fsigned-bitfields" } + +extern "C" void abort (void); + +#include "bitfield1.h" + +void bitfield1_y (A& a) +{ + if (a.bitS != -1) + abort (); + if (a.bitU != 1) + abort (); + if (a.bit != -1) + abort (); +} diff --git a/gcc/testsuite/g++.dg/compat/abi/pr38736_main.C b/gcc/testsuite/g++.dg/compat/abi/pr38736_main.C new file mode 100644 index 000000000..b9f6ac898 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/abi/pr38736_main.C @@ -0,0 +1,18 @@ +/* PR target/38736 */ +/* { dg-skip-if "attribute ((aligned))" { ! { i?86-*-* x86_64-*-* } } } */ +/* { dg-require-effective-target avx } */ + +/* Test compatibility of attribute ((aligned)) with and without -mavx. */ + +extern int aligned_x (void); +extern int aligned_y_avx (void); +extern "C" void abort (void); + +int +main () +{ + if (aligned_x () != aligned_y_avx ()) + abort (); + + return 0; +} diff --git a/gcc/testsuite/g++.dg/compat/abi/pr38736_x.C b/gcc/testsuite/g++.dg/compat/abi/pr38736_x.C new file mode 100644 index 000000000..aeab257aa --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/abi/pr38736_x.C @@ -0,0 +1,15 @@ +/* PR target/38736 */ +/* { dg-options "-O2" } */ + +struct alignment_test_struct +{ + char space[4] __attribute__((__aligned__)); +}; + +extern int aligned_x (void); + +int +aligned_x (void) +{ + return __alignof__(struct alignment_test_struct); +} diff --git a/gcc/testsuite/g++.dg/compat/abi/pr38736_y.C b/gcc/testsuite/g++.dg/compat/abi/pr38736_y.C new file mode 100644 index 000000000..bade1b292 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/abi/pr38736_y.C @@ -0,0 +1,6 @@ +/* PR target/38736 */ +/* { dg-options "-O2 -mavx" } */ + +#define aligned_x aligned_y_avx + +#include "pr38736_x.C" diff --git a/gcc/testsuite/g++.dg/compat/abi/vbase8-10.h b/gcc/testsuite/g++.dg/compat/abi/vbase8-10.h new file mode 100644 index 000000000..aee0b6b49 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/abi/vbase8-10.h @@ -0,0 +1,54 @@ +class C0 +{ public: int i0; }; +class C1 + : public C0 +{ public: int i1; }; +class C2 + : public C1 + , virtual public C0 +{ public: int i2; }; +class C3 + : public C1 + , public C2 + , virtual public C0 +{ public: int i3; }; +class C4 + : virtual public C1 + , virtual public C0 + , virtual public C3 + , public C2 +{ public: int i4; }; +class C5 + : public C3 + , virtual public C0 + , virtual public C2 +{ public: int i5; }; +class C6 + : public C1 + , public C2 + , virtual public C5 + , virtual public C3 + , virtual public C0 +{ public: int i6; }; +class C7 + : public C1 + , virtual public C5 + , virtual public C4 + , virtual public C2 + , virtual public C0 + , virtual public C6 +{ public: int i7; }; +class C8 + : virtual public C4 + , public C3 + , public C0 + , virtual public C7 + , virtual public C6 +{ public: int i8; }; +class C9 + : virtual public C0 + , public C4 + , public C8 + , public C1 + , public C6 +{ public: int i9; }; diff --git a/gcc/testsuite/g++.dg/compat/abi/vbase8-10_main.C b/gcc/testsuite/g++.dg/compat/abi/vbase8-10_main.C new file mode 100644 index 000000000..606c0fe2f --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/abi/vbase8-10_main.C @@ -0,0 +1,16 @@ +// { dg-options -w } + +// Copyright (C) 2001 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 26 Jul 2001 <nathan@codesourcery.com> +// Split into pieces for binary compatibility testing October 2002 + +// Origin stefan@space.twc.de +// Bug 3145 case 10. Horribly complicated class hierarchy + +extern void vbase8_10_x (void); + +int +main () +{ + vbase8_10_x (); +} diff --git a/gcc/testsuite/g++.dg/compat/abi/vbase8-10_x.C b/gcc/testsuite/g++.dg/compat/abi/vbase8-10_x.C new file mode 100644 index 000000000..c56d080eb --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/abi/vbase8-10_x.C @@ -0,0 +1,51 @@ +// { dg-options -w } + +#include "vbase8-10.h" + +extern void check_C0 (C0&, int); +extern void check_C1 (C1&, int); +extern void check_C2 (C2&, int); +extern void check_C3 (C3&, int); +extern void check_C4 (C4&, int); +extern void check_C5 (C5&, int); +extern void check_C6 (C6&, int); +extern void check_C7 (C7&, int); +extern void check_C8 (C8&, int); +extern void check_C9 (C9&, int); + +void +vbase8_10_x (void) +{ + C0 c0; + C1 c1; + C2 c2; + C3 c3; + C4 c4; + C5 c5; + C6 c6; + C7 c7; + C8 c8; + C9 c9; + + c0.i0 = 0; + c1.i1 = 101; + c2.i2 = 202; + c3.i3 = 303; + c4.i4 = 404; + c5.i5 = 505; + c6.i6 = 606; + c7.i7 = 707; + c8.i8 = 808; + c9.i9 = 909; + + check_C0 (c0, 0); + check_C1 (c1, 101); + check_C2 (c2, 202); + check_C3 (c3, 303); + check_C4 (c4, 404); + check_C5 (c5, 505); + check_C6 (c6, 606); + check_C7 (c7, 707); + check_C8 (c8, 808); + check_C9 (c9, 909); +} diff --git a/gcc/testsuite/g++.dg/compat/abi/vbase8-10_y.C b/gcc/testsuite/g++.dg/compat/abi/vbase8-10_y.C new file mode 100644 index 000000000..5364ed6b7 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/abi/vbase8-10_y.C @@ -0,0 +1,65 @@ +// { dg-options -w } + +extern "C" void abort (void); + +#include "vbase8-10.h" + +void check_C0 (C0 &x, int i) +{ + if (x.i0 != i) + abort (); +} + +void check_C1 (C1 &x, int i) +{ + if (x.i1 != i) + abort (); +} + +void check_C2 (C2 &x, int i) +{ + if (x.i2 != i) + abort (); +} + +void check_C3 (C3 &x, int i) +{ + if (x.i3 != i) + abort (); +} + +void check_C4 (C4 &x, int i) +{ + if (x.i4 != i) + abort (); +} + +void check_C5 (C5 &x, int i) +{ + if (x.i5 != i) + abort (); +} + +void check_C6 (C6 &x, int i) +{ + if (x.i6 != i) + abort (); +} + +void check_C7 (C7 &x, int i) +{ + if (x.i7 != i) + abort (); +} + +void check_C8 (C8 &x, int i) +{ + if (x.i8 != i) + abort (); +} + +void check_C9 (C9 &x, int i) +{ + if (x.i9 != i) + abort (); +} diff --git a/gcc/testsuite/g++.dg/compat/abi/vbase8-21.h b/gcc/testsuite/g++.dg/compat/abi/vbase8-21.h new file mode 100644 index 000000000..cd510e2ce --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/abi/vbase8-21.h @@ -0,0 +1,54 @@ +class C0 +{ public: int i0; }; +class C1 + : virtual public C0 +{ public: int i1; }; +class C2 + : virtual public C1 + , virtual public C0 +{ public: int i2; }; +class C3 + : virtual public C2 + , virtual public C1 +{ public: int i3; }; +class C4 + : virtual public C2 + , public C0 + , public C1 +{ public: int i4; }; +class C5 + : virtual public C0 + , public C2 + , virtual public C1 + , virtual public C3 + , virtual public C4 +{ public: int i5; }; +class C6 + : virtual public C1 + , virtual public C3 + , public C0 + , public C2 + , virtual public C4 +{ public: int i6; }; +class C7 + : virtual public C5 + , public C2 + , public C6 + , virtual public C0 + , public C3 +{ public: int i7; }; +class C8 + : virtual public C5 + , public C7 + , virtual public C0 + , virtual public C2 + , virtual public C6 +{ public: int i8; }; +class C9 + : virtual public C2 + , virtual public C4 + , public C1 + , virtual public C0 + , public C7 + , public C5 +{ public: int i9; }; diff --git a/gcc/testsuite/g++.dg/compat/abi/vbase8-21_main.C b/gcc/testsuite/g++.dg/compat/abi/vbase8-21_main.C new file mode 100644 index 000000000..16a0a3cd3 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/abi/vbase8-21_main.C @@ -0,0 +1,16 @@ +// { dg-options -w } + +// Copyright (C) 2001 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 26 Jul 2001 <nathan@codesourcery.com> +// Split into pieces for binary compatibility testing October 2002 + +// Origin stefan@space.twc.de +// Bug 3145 case 10. Horribly complicated class hierarchy + +extern void vbase8_21_x (void); + +int +main () +{ + vbase8_21_x (); +} diff --git a/gcc/testsuite/g++.dg/compat/abi/vbase8-21_x.C b/gcc/testsuite/g++.dg/compat/abi/vbase8-21_x.C new file mode 100644 index 000000000..818eade03 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/abi/vbase8-21_x.C @@ -0,0 +1,51 @@ +// { dg-options -w } + +#include "vbase8-21.h" + +extern void check_C0 (C0&, int); +extern void check_C1 (C1&, int); +extern void check_C2 (C2&, int); +extern void check_C3 (C3&, int); +extern void check_C4 (C4&, int); +extern void check_C5 (C5&, int); +extern void check_C6 (C6&, int); +extern void check_C7 (C7&, int); +extern void check_C8 (C8&, int); +extern void check_C9 (C9&, int); + +void +vbase8_21_x (void) +{ + C0 c0; + C1 c1; + C2 c2; + C3 c3; + C4 c4; + C5 c5; + C6 c6; + C7 c7; + C8 c8; + C9 c9; + + c0.i0 = 0; + c1.i1 = 101; + c2.i2 = 202; + c3.i3 = 303; + c4.i4 = 404; + c5.i5 = 505; + c6.i6 = 606; + c7.i7 = 707; + c8.i8 = 808; + c9.i9 = 909; + + check_C0 (c0, 0); + check_C1 (c1, 101); + check_C2 (c2, 202); + check_C3 (c3, 303); + check_C4 (c4, 404); + check_C5 (c5, 505); + check_C6 (c6, 606); + check_C7 (c7, 707); + check_C8 (c8, 808); + check_C9 (c9, 909); +} diff --git a/gcc/testsuite/g++.dg/compat/abi/vbase8-21_y.C b/gcc/testsuite/g++.dg/compat/abi/vbase8-21_y.C new file mode 100644 index 000000000..512613935 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/abi/vbase8-21_y.C @@ -0,0 +1,65 @@ +// { dg-options -w } + +extern "C" void abort (void); + +#include "vbase8-21.h" + +void check_C0 (C0 &x, int i) +{ + if (x.i0 != i) + abort (); +} + +void check_C1 (C1 &x, int i) +{ + if (x.i1 != i) + abort (); +} + +void check_C2 (C2 &x, int i) +{ + if (x.i2 != i) + abort (); +} + +void check_C3 (C3 &x, int i) +{ + if (x.i3 != i) + abort (); +} + +void check_C4 (C4 &x, int i) +{ + if (x.i4 != i) + abort (); +} + +void check_C5 (C5 &x, int i) +{ + if (x.i5 != i) + abort (); +} + +void check_C6 (C6 &x, int i) +{ + if (x.i6 != i) + abort (); +} + +void check_C7 (C7 &x, int i) +{ + if (x.i7 != i) + abort (); +} + +void check_C8 (C8 &x, int i) +{ + if (x.i8 != i) + abort (); +} + +void check_C9 (C9 &x, int i) +{ + if (x.i9 != i) + abort (); +} diff --git a/gcc/testsuite/g++.dg/compat/abi/vbase8-22.h b/gcc/testsuite/g++.dg/compat/abi/vbase8-22.h new file mode 100644 index 000000000..e19e93eae --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/abi/vbase8-22.h @@ -0,0 +1,59 @@ +class C0 +{ public: int i0; }; +class C1 + : public C0 +{ public: int i1; }; +class C2 + : public C1 + , virtual public C0 +{ public: int i2; }; +class C3 + : virtual public C0 + , virtual public C2 + , virtual public C1 +{ public: int i3; }; +class C4 + : virtual public C2 + , public C1 + , virtual public C3 + , public C0 +{ public: int i4; }; +class C5 + : virtual public C0 + , virtual public C4 + , public C1 + , virtual public C2 + , virtual public C3 +{ public: int i5; }; +class C6 + : public C0 + , virtual public C1 + , public C5 + , public C2 + , virtual public C3 + , virtual public C4 +{ public: int i6; }; +class C7 + : virtual public C1 + , public C5 + , virtual public C6 + , virtual public C4 + , virtual public C3 + , virtual public C0 +{ public: int i7; }; +class C8 + : virtual public C6 + , virtual public C1 + , virtual public C2 + , public C3 + , virtual public C4 +{ public: int i8; }; +class C9 + : public C4 + , virtual public C2 + , virtual public C8 + , public C3 + , public C1 + , public C6 + , public C5 +{ public: int i9; }; diff --git a/gcc/testsuite/g++.dg/compat/abi/vbase8-22_main.C b/gcc/testsuite/g++.dg/compat/abi/vbase8-22_main.C new file mode 100644 index 000000000..6455a2efc --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/abi/vbase8-22_main.C @@ -0,0 +1,16 @@ +// { dg-options -w } + +// Copyright (C) 2001 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 20 Nov 2001 <nathan@codesourcery.com> +// Split into pieces for binary compatibility testing October 2002 + +// Origin stefan@space.twc.de +// Bug 3145 case 22. Horribly complicated class hierarchy + +extern void vbase8_22_x (void); + +int +main () +{ + vbase8_22_x (); +} diff --git a/gcc/testsuite/g++.dg/compat/abi/vbase8-22_x.C b/gcc/testsuite/g++.dg/compat/abi/vbase8-22_x.C new file mode 100644 index 000000000..49f021adf --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/abi/vbase8-22_x.C @@ -0,0 +1,51 @@ +// { dg-options -w } + +#include "vbase8-22.h" + +extern void check_C0 (C0&, int); +extern void check_C1 (C1&, int); +extern void check_C2 (C2&, int); +extern void check_C3 (C3&, int); +extern void check_C4 (C4&, int); +extern void check_C5 (C5&, int); +extern void check_C6 (C6&, int); +extern void check_C7 (C7&, int); +extern void check_C8 (C8&, int); +extern void check_C9 (C9&, int); + +void +vbase8_22_x (void) +{ + C0 c0; + C1 c1; + C2 c2; + C3 c3; + C4 c4; + C5 c5; + C6 c6; + C7 c7; + C8 c8; + C9 c9; + + c0.i0 = 0; + c1.i1 = 101; + c2.i2 = 202; + c3.i3 = 303; + c4.i4 = 404; + c5.i5 = 505; + c6.i6 = 606; + c7.i7 = 707; + c8.i8 = 808; + c9.i9 = 909; + + check_C0 (c0, 0); + check_C1 (c1, 101); + check_C2 (c2, 202); + check_C3 (c3, 303); + check_C4 (c4, 404); + check_C5 (c5, 505); + check_C6 (c6, 606); + check_C7 (c7, 707); + check_C8 (c8, 808); + check_C9 (c9, 909); +} diff --git a/gcc/testsuite/g++.dg/compat/abi/vbase8-22_y.C b/gcc/testsuite/g++.dg/compat/abi/vbase8-22_y.C new file mode 100644 index 000000000..49ab04a87 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/abi/vbase8-22_y.C @@ -0,0 +1,65 @@ +// { dg-options -w } + +extern "C" void abort (void); + +#include "vbase8-22.h" + +void check_C0 (C0 &x, int i) +{ + if (x.i0 != i) + abort (); +} + +void check_C1 (C1 &x, int i) +{ + if (x.i1 != i) + abort (); +} + +void check_C2 (C2 &x, int i) +{ + if (x.i2 != i) + abort (); +} + +void check_C3 (C3 &x, int i) +{ + if (x.i3 != i) + abort (); +} + +void check_C4 (C4 &x, int i) +{ + if (x.i4 != i) + abort (); +} + +void check_C5 (C5 &x, int i) +{ + if (x.i5 != i) + abort (); +} + +void check_C6 (C6 &x, int i) +{ + if (x.i6 != i) + abort (); +} + +void check_C7 (C7 &x, int i) +{ + if (x.i7 != i) + abort (); +} + +void check_C8 (C8 &x, int i) +{ + if (x.i8 != i) + abort (); +} + +void check_C9 (C9 &x, int i) +{ + if (x.i9 != i) + abort (); +} diff --git a/gcc/testsuite/g++.dg/compat/abi/vbase8-4.h b/gcc/testsuite/g++.dg/compat/abi/vbase8-4.h new file mode 100644 index 000000000..b183fbe4f --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/abi/vbase8-4.h @@ -0,0 +1,57 @@ +class C0 +{ public: int i0; }; +class C1 + : virtual public C0 +{ public: int i1; }; +class C2 + : public C0 + , public C1 +{ public: int i2; }; +class C3 + : virtual public C0 + , public C1 + , public C2 +{ public: int i3; }; +class C4 + : public C2 + , public C3 + , virtual public C1 + , virtual public C0 +{ public: int i4; }; +class C5 + : virtual public C2 + , public C1 + , public C0 +{ public: int i5; }; +class C6 + : virtual public C0 + , virtual public C5 + , public C1 + , public C3 + , public C4 +{ public: int i6; }; +class C7 + : public C6 + , virtual public C0 + , public C1 + , public C2 + , virtual public C4 +{ public: int i7; }; +class C8 + : public C2 + , virtual public C6 + , virtual public C7 + , public C5 + , public C3 + , virtual public C4 +{ public: int i8; }; +class C9 + : public C5 + , virtual public C3 + , virtual public C8 + , public C0 + , public C2 + , public C7 + , public C6 + , public C4 +{ public: int i9; }; diff --git a/gcc/testsuite/g++.dg/compat/abi/vbase8-4_main.C b/gcc/testsuite/g++.dg/compat/abi/vbase8-4_main.C new file mode 100644 index 000000000..f5e5e3824 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/abi/vbase8-4_main.C @@ -0,0 +1,16 @@ +// { dg-options -w } + +// Copyright (C) 2001 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 20 Nov 2001 <nathan@codesourcery.com> +// Split into pieces for binary compatibility testing October 2002 + +// Origin stefan@space.twc.de +// Bug 3145 case 4. Horribly complicated class hierarchy + +extern void vbase8_4_x (void); + +int +main () +{ + vbase8_4_x (); +} diff --git a/gcc/testsuite/g++.dg/compat/abi/vbase8-4_x.C b/gcc/testsuite/g++.dg/compat/abi/vbase8-4_x.C new file mode 100644 index 000000000..db60cc6ee --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/abi/vbase8-4_x.C @@ -0,0 +1,51 @@ +// { dg-options -w } + +#include "vbase8-4.h" + +extern void check_C0 (C0&, int); +extern void check_C1 (C1&, int); +extern void check_C2 (C2&, int); +extern void check_C3 (C3&, int); +extern void check_C4 (C4&, int); +extern void check_C5 (C5&, int); +extern void check_C6 (C6&, int); +extern void check_C7 (C7&, int); +extern void check_C8 (C8&, int); +extern void check_C9 (C9&, int); + +void +vbase8_4_x (void) +{ + C0 c0; + C1 c1; + C2 c2; + C3 c3; + C4 c4; + C5 c5; + C6 c6; + C7 c7; + C8 c8; + C9 c9; + + c0.i0 = 0; + c1.i1 = 101; + c2.i2 = 202; + c3.i3 = 303; + c4.i4 = 404; + c5.i5 = 505; + c6.i6 = 606; + c7.i7 = 707; + c8.i8 = 808; + c9.i9 = 909; + + check_C0 (c0, 0); + check_C1 (c1, 101); + check_C2 (c2, 202); + check_C3 (c3, 303); + check_C4 (c4, 404); + check_C5 (c5, 505); + check_C6 (c6, 606); + check_C7 (c7, 707); + check_C8 (c8, 808); + check_C9 (c9, 909); +} diff --git a/gcc/testsuite/g++.dg/compat/abi/vbase8-4_y.C b/gcc/testsuite/g++.dg/compat/abi/vbase8-4_y.C new file mode 100644 index 000000000..24d5046c9 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/abi/vbase8-4_y.C @@ -0,0 +1,65 @@ +// { dg-options -w } + +extern "C" void abort (void); + +#include "vbase8-4.h" + +void check_C0 (C0 &x, int i) +{ + if (x.i0 != i) + abort (); +} + +void check_C1 (C1 &x, int i) +{ + if (x.i1 != i) + abort (); +} + +void check_C2 (C2 &x, int i) +{ + if (x.i2 != i) + abort (); +} + +void check_C3 (C3 &x, int i) +{ + if (x.i3 != i) + abort (); +} + +void check_C4 (C4 &x, int i) +{ + if (x.i4 != i) + abort (); +} + +void check_C5 (C5 &x, int i) +{ + if (x.i5 != i) + abort (); +} + +void check_C6 (C6 &x, int i) +{ + if (x.i6 != i) + abort (); +} + +void check_C7 (C7 &x, int i) +{ + if (x.i7 != i) + abort (); +} + +void check_C8 (C8 &x, int i) +{ + if (x.i8 != i) + abort (); +} + +void check_C9 (C9 &x, int i) +{ + if (x.i9 != i) + abort (); +} diff --git a/gcc/testsuite/g++.dg/compat/break/README b/gcc/testsuite/g++.dg/compat/break/README new file mode 100644 index 000000000..0b8ea0247 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/break/README @@ -0,0 +1,18 @@ +Tests in this directory are for functionality that has changed in GCC +from one release to another or that is not ABI-compliant and may change +in a future release. + +Each test header for changed behavior should indicate the version in +which the behavior changed, in order to help users of these tests to +determine whether a test failure is expected or not. + +Every test in this directory that covers behavior that is not +ABI-compliant should also be covered by a test for -Wabi to ensure that +there is a warning for the construct. + + +Copyright (C) 2002 Free Software Foundation, Inc. + +Copying and distribution of this file, with or without modification, +are permitted in any medium without royalty provided the copyright +notice and this notice are preserved. diff --git a/gcc/testsuite/g++.dg/compat/break/bitfield5.h b/gcc/testsuite/g++.dg/compat/break/bitfield5.h new file mode 100644 index 000000000..6f7f012cc --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/break/bitfield5.h @@ -0,0 +1,11 @@ +struct A { + virtual void f(); + int f1 : 1; +}; + +struct B : public A { + int f2 : 1; + int : 0; + int f3 : 4; + int f4 : 3; +}; diff --git a/gcc/testsuite/g++.dg/compat/break/bitfield5_main.C b/gcc/testsuite/g++.dg/compat/break/bitfield5_main.C new file mode 100644 index 000000000..415a8846c --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/break/bitfield5_main.C @@ -0,0 +1,14 @@ +// The offset of `B::f2' is not ABI-compliant and may change in a future +// version of GCC. +// g++.dg/abi/bitfield5.C tests this with -Wabi. +// Split into pieces for binary compatibility testing October 2002 + +#include "bitfield5.h" + +extern void bitfield5_x (void); + +int +main () +{ + bitfield5_x (); +} diff --git a/gcc/testsuite/g++.dg/compat/break/bitfield5_x.C b/gcc/testsuite/g++.dg/compat/break/bitfield5_x.C new file mode 100644 index 000000000..9be937234 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/break/bitfield5_x.C @@ -0,0 +1,13 @@ +#include "bitfield5.h" + +extern void bitfield5_y (B&); + +void bitfield5_x () +{ + B b; + + b.f3 = 7; + b.f4 = 3; + + bitfield5_y (b); +} diff --git a/gcc/testsuite/g++.dg/compat/break/bitfield5_y.C b/gcc/testsuite/g++.dg/compat/break/bitfield5_y.C new file mode 100644 index 000000000..6ee4dd008 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/break/bitfield5_y.C @@ -0,0 +1,13 @@ +extern "C" void abort (void); + +#include "bitfield5.h" + +void A::f () {} + +void bitfield5_y (B& b) +{ + if (b.f3 != 7) + abort (); + if (b.f4 != 3) + abort (); +} diff --git a/gcc/testsuite/g++.dg/compat/break/bitfield7.h b/gcc/testsuite/g++.dg/compat/break/bitfield7.h new file mode 100644 index 000000000..2060bf747 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/break/bitfield7.h @@ -0,0 +1,3 @@ +union U { + int i: 4096; +}; diff --git a/gcc/testsuite/g++.dg/compat/break/bitfield7_main.C b/gcc/testsuite/g++.dg/compat/break/bitfield7_main.C new file mode 100644 index 000000000..57bb96101 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/break/bitfield7_main.C @@ -0,0 +1,16 @@ +// { dg-options "-w" } + +// The size assigned to `U' may not be ABI-compliant and may change in a +// future version of GCC. +// g++.dg/abi/bitfield7.C tests this with -Wabi. +// Split into pieces for binary compatibility testing October 2002 + +#include "bitfield7.h" + +extern void bitfield7_x (void); + +int +main () +{ + bitfield7_x (); +} diff --git a/gcc/testsuite/g++.dg/compat/break/bitfield7_x.C b/gcc/testsuite/g++.dg/compat/break/bitfield7_x.C new file mode 100644 index 000000000..9b2a622a5 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/break/bitfield7_x.C @@ -0,0 +1,15 @@ +// { dg-options "-w" } + +#include "bitfield7.h" + +extern void bitfield7_y (U*); + +void bitfield7_x () +{ + U u[2]; + + u[0].i = 7; + u[1].i = 8; + + bitfield7_y (u); +} diff --git a/gcc/testsuite/g++.dg/compat/break/bitfield7_y.C b/gcc/testsuite/g++.dg/compat/break/bitfield7_y.C new file mode 100644 index 000000000..afa5446ae --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/break/bitfield7_y.C @@ -0,0 +1,13 @@ +// { dg-options "-w" } + +extern "C" void abort (void); + +#include "bitfield7.h" + +void bitfield7_y (U* u) +{ + if (u[0].i != 7) + abort (); + if (u[1].i != 8) + abort (); +} diff --git a/gcc/testsuite/g++.dg/compat/break/empty6.h b/gcc/testsuite/g++.dg/compat/break/empty6.h new file mode 100644 index 000000000..47a0da8b5 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/break/empty6.h @@ -0,0 +1,7 @@ +struct A {}; + +struct B { + A a; + virtual void f () {} + int i; +}; diff --git a/gcc/testsuite/g++.dg/compat/break/empty6_main.C b/gcc/testsuite/g++.dg/compat/break/empty6_main.C new file mode 100644 index 000000000..bf6d98241 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/break/empty6_main.C @@ -0,0 +1,14 @@ +// `B::a' contains empty classes which may cause base classes to be +// placed at different locations in a future version of GCC. +// g++.dg/abi/empty6.C tests this with -Wabi. +// Split into pieces for binary compatibility testing October 2002 + +#include "empty6.h" + +extern void empty6_x (void); + +int +main () +{ + empty6_x (); +} diff --git a/gcc/testsuite/g++.dg/compat/break/empty6_x.C b/gcc/testsuite/g++.dg/compat/break/empty6_x.C new file mode 100644 index 000000000..f7e25e9ab --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/break/empty6_x.C @@ -0,0 +1,12 @@ +#include "empty6.h" + +extern void empty6_y (B&); + +void empty6_x () +{ + B b; + + b.i = 7; + + empty6_y (b); +} diff --git a/gcc/testsuite/g++.dg/compat/break/empty6_y.C b/gcc/testsuite/g++.dg/compat/break/empty6_y.C new file mode 100644 index 000000000..cb3d45c9e --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/break/empty6_y.C @@ -0,0 +1,9 @@ +extern "C" void abort (void); + +#include "empty6.h" + +void empty6_y (B& b) +{ + if (b.i != 7) + abort (); +} diff --git a/gcc/testsuite/g++.dg/compat/break/vbase10.h b/gcc/testsuite/g++.dg/compat/break/vbase10.h new file mode 100644 index 000000000..f418d1e56 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/break/vbase10.h @@ -0,0 +1,12 @@ +struct A { + virtual void f(); + char c1; +}; + +struct B { + B(); + char c2; +}; + +struct C : public A, public virtual B { +}; diff --git a/gcc/testsuite/g++.dg/compat/break/vbase10_main.C b/gcc/testsuite/g++.dg/compat/break/vbase10_main.C new file mode 100644 index 000000000..a082b5dbf --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/break/vbase10_main.C @@ -0,0 +1,14 @@ +// The offset of virtual base `B' is not ABI-compliant and may change in +// a future version of GCC. +// g++.dg/abi/vbase10.C tests this with -Wabi. +// Split into pieces for binary compatibility testing October 2002 + +#include "vbase10.h" + +extern void vbase10_x (void); + +int +main () +{ + vbase10_x (); +} diff --git a/gcc/testsuite/g++.dg/compat/break/vbase10_x.C b/gcc/testsuite/g++.dg/compat/break/vbase10_x.C new file mode 100644 index 000000000..6d51d3c72 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/break/vbase10_x.C @@ -0,0 +1,13 @@ +#include "vbase10.h" + +extern void vbase10_y (C&); + +void vbase10_x () +{ + C c; + + c.c1 = 1; + c.c2 = 2; + + vbase10_y (c); +} diff --git a/gcc/testsuite/g++.dg/compat/break/vbase10_y.C b/gcc/testsuite/g++.dg/compat/break/vbase10_y.C new file mode 100644 index 000000000..70ce0075e --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/break/vbase10_y.C @@ -0,0 +1,14 @@ +extern "C" void abort (void); + +#include "vbase10.h" + +void A::f () {} +B::B() {} + +void vbase10_y (C& c) +{ + if (c.c1 != 1) + abort (); + if (c.c2 != 2) + abort (); +} diff --git a/gcc/testsuite/g++.dg/compat/break/vbase11.h b/gcc/testsuite/g++.dg/compat/break/vbase11.h new file mode 100644 index 000000000..a298f7644 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/break/vbase11.h @@ -0,0 +1,12 @@ +struct base +{ + short b; + virtual int foo(); +}; + +struct derived: virtual base +{ + int d; + virtual int foo(); + virtual int bar(); +}; diff --git a/gcc/testsuite/g++.dg/compat/break/vbase11_main.C b/gcc/testsuite/g++.dg/compat/break/vbase11_main.C new file mode 100644 index 000000000..2ac599449 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/break/vbase11_main.C @@ -0,0 +1,13 @@ +// Test case from PR 7470, which was fixed in GCC 3.2 and breaks binary +// compatibility with earlier releases. +// Split into pieces for binary compatibility testing October 2002 + +#include "vbase11.h" + +extern void vbase11_x (void); + +int +main () +{ + vbase11_x (); +} diff --git a/gcc/testsuite/g++.dg/compat/break/vbase11_x.C b/gcc/testsuite/g++.dg/compat/break/vbase11_x.C new file mode 100644 index 000000000..4b2398ae1 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/break/vbase11_x.C @@ -0,0 +1,14 @@ +#include "vbase11.h" + +extern void vbase11_y (derived&); + +int base::foo() { return 1; } +int derived::foo() { return 2; } +int derived::bar() { return 3; } + +void vbase11_x () +{ + derived d; + + vbase11_y (d); +} diff --git a/gcc/testsuite/g++.dg/compat/break/vbase11_y.C b/gcc/testsuite/g++.dg/compat/break/vbase11_y.C new file mode 100644 index 000000000..01ca62b87 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/break/vbase11_y.C @@ -0,0 +1,11 @@ +extern "C" void abort (void); + +#include "vbase11.h" + +void vbase11_y (derived& d) +{ + if (d.foo() != 2) + abort (); + if (d.bar() != 3) + abort (); +} diff --git a/gcc/testsuite/g++.dg/compat/compat.exp b/gcc/testsuite/g++.dg/compat/compat.exp new file mode 100644 index 000000000..7fb16fed9 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/compat.exp @@ -0,0 +1,129 @@ +# Copyright (C) 2002, 2004, 2007 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GCC; see the file COPYING3. If not see +# <http://www.gnu.org/licenses/>. +# +# This file was written by Janis Johnson, <janis187@us.ibm.com> + + +# Test interoperability of two compilers that follow the same ABI. +# +# Break simple tests into two pieces and see that they work when linked +# together. If an alternate compiler is specified then the two main +# pieces of each test are compiled with different compilers. The +# alternate compiler must be installed, and is specified by defining +# ALT_CXX_UNDER_TEST in the environment. + +if $tracelevel then { + strace $tracelevel +} + +global GXX_UNDER_TEST +global ld_library_path + +# Load procedures from common libraries. +load_lib standard.exp +load_lib g++.exp +load_lib target-libpath.exp + +# +# compat-use-alt-compiler -- make the alternate compiler the default +# +proc compat-use-alt-compiler { } { + global GXX_UNDER_TEST ALT_CXX_UNDER_TEST + global CXXFLAGS + global ALWAYS_CXXFLAGS + global ld_library_path alt_ld_library_path + global same_alt + + # We don't need to do this if the alternate compiler is actually + # the same as the compiler under test. + if { $same_alt == 0 } then { + set GXX_UNDER_TEST $ALT_CXX_UNDER_TEST + set CXXFLAGS "" + set ALWAYS_CXXFLAGS "" + set ld_library_path $alt_ld_library_path + set_ld_library_path_env_vars + } +} + +# +# compat-use-tst-compiler -- make compiler under test the default +# +proc compat-use-tst-compiler { } { + global GXX_UNDER_TEST save_gxx_under_test + global CXXFLAGS save_cxxflags + global ALWAYS_CXXFLAGS save_always_cxxflags + global ld_library_path save_ld_library_path + global same_alt + + # We don't need to do this if the alternate compiler is actually + # the same as the compiler under test. + + if { $same_alt == 0 } then { + set GXX_UNDER_TEST $save_gxx_under_test + set CXXFLAGS $save_cxxflags + set ALWAYS_CXXFLAGS $save_always_cxxflags + set ld_library_path $save_ld_library_path + set_ld_library_path_env_vars + } +} + +# Load the language-independent compabibility support procedures. +# This must be done after the compat-use-*-compiler definitions. +load_lib compat.exp + +g++_init + +# Save variables for the C++ compiler under test, which each test will +# change a couple of times. This must be done after calling g++-init. +set save_gxx_under_test $GXX_UNDER_TEST +set save_cxxflags $CXXFLAGS +set save_always_cxxflags $ALWAYS_CXXFLAGS +set save_ld_library_path $ld_library_path + +# Define an identifier for use with this suite to avoid name conflicts +# with other compat tests running at the same time. +set sid "cp_compat" + +# Find out whether there is an alternate compiler to test. If the +# variable is defined but is set to "same", that means we use the same +# compiler twice, which is meaningful if the two parts of COMPAT_OPTIONS +# are different. +set use_alt 0 +set same_alt 0 +set alt_ld_library_path "." +if [info exists ALT_CXX_UNDER_TEST] then { + set use_alt 1 + if [string match "same" $ALT_CXX_UNDER_TEST] then { + set same_alt 1 + } else { + if [info exists ALT_LD_LIBRARY_PATH] then { + append alt_ld_library_path ":${ALT_LD_LIBRARY_PATH}" + } + } +} + +# Main loop. +foreach src [lsort [find $srcdir/$subdir *_main.C]] { + # If we're only testing specific files and this isn't one of them, skip it. + if ![runtest_file_p $runtests $src] then { + continue + } + + compat-execute $src $sid $use_alt +} + +# Restore the original compiler under test. +compat-use-tst-compiler diff --git a/gcc/testsuite/g++.dg/compat/decimal/compat-common.h b/gcc/testsuite/g++.dg/compat/decimal/compat-common.h new file mode 100644 index 000000000..43c22d722 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/compat-common.h @@ -0,0 +1,55 @@ +/* Several of the binary compatibility tests use these macros to + allow debugging the test or tracking down a failure by getting an + indication of whether each individual check passed or failed. + When DBG is defined, each check is shown by a dot (pass) or 'F' + (fail) rather than aborting as soon as a failure is detected. */ + +#ifdef DBG +#include <stdio.h> +#define DEBUG_INIT setbuf (stdout, NULL); +#define DEBUG_FPUTS(x) fputs (x, stdout); +#define DEBUG_DOT putc ('.', stdout); +#define DEBUG_NL putc ('\n', stdout); +#define DEBUG_FAIL putc ('F', stdout); fails++; +#define DEBUG_CHECK { DEBUG_FAIL } else { DEBUG_DOT } +#define DEBUG_FINI if (fails) DEBUG_FPUTS ("failed\n") \ + else DEBUG_FPUTS ("passed\n") +#else +#define DEBUG_INIT +#define DEBUG_FPUTS(x) +#define DEBUG_DOT +#define DEBUG_NL +#define DEBUG_FAIL abort (); +#define DEBUG_CHECK abort (); +#define DEBUG_FINI +#endif + +#ifdef SKIP_COMPLEX +#ifndef SKIP_COMPLEX_INT +#define SKIP_COMPLEX_INT +#endif +#endif + +#ifndef SKIP_COMPLEX +#ifdef __GNUC__ +#define CINT(x, y) (x + y * __extension__ 1i) +#define CDBL(x, y) (x + y * __extension__ 1i) +#else +#ifdef __SUNPRO_C +/* ??? Complex support without <complex.h>. */ +#else +#include <complex.h> +#endif +#ifndef SKIP_COMPLEX_INT +#define CINT(x, y) ((_Complex int) (x + y * _Complex_I)) +#endif +#define CDBL(x, y) (x + y * _Complex_I) +#endif +#endif + +#ifdef __cplusplus +extern "C" void abort (void); +#else +extern void abort (void); +#endif +extern int fails; diff --git a/gcc/testsuite/g++.dg/compat/decimal/decimal-dummy.h b/gcc/testsuite/g++.dg/compat/decimal/decimal-dummy.h new file mode 100644 index 000000000..ec347f9b7 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/decimal-dummy.h @@ -0,0 +1,67 @@ +namespace std { +namespace decimal { + + class decimal32 + { + public: + typedef float __dec32 __attribute__((mode(SD))); + decimal32 () : __val(0.e-101DF) {} + decimal32 (__dec32 x) : __val(x) {} + __dec32 __val; + }; + + class decimal64 + { + public: + typedef float __dec64 __attribute__((mode(DD))); + decimal64 () : __val(0.e-398dd) {} + decimal64 (__dec64 x) : __val(x) {} + __dec64 __val; + }; + + class decimal128 + { + public: + typedef float __dec128 __attribute__((mode(TD))); + decimal128 () : __val(0.e-6176DL) {} + decimal128 (__dec128 x) : __val(x) {} + __dec128 __val; + }; + + inline decimal32 operator+ (decimal32 lhs, decimal32 rhs) + { + decimal32 tmp; + tmp.__val = lhs.__val + rhs.__val; + return tmp; + } + + inline decimal64 operator+ (decimal64 lhs, decimal64 rhs) + { + decimal64 tmp; + tmp.__val = lhs.__val + rhs.__val; + return tmp; + } + + inline decimal128 operator+ (decimal128 lhs, decimal128 rhs) + { + decimal128 tmp; + tmp.__val = lhs.__val + rhs.__val; + return tmp; + } + + inline bool operator!= (decimal32 lhs, decimal32 rhs) + { + return lhs.__val != rhs.__val; + } + + inline bool operator!= (decimal64 lhs, decimal64 rhs) + { + return lhs.__val != rhs.__val; + } + + inline bool operator!= (decimal128 lhs, decimal128 rhs) + { + return lhs.__val != rhs.__val; + } +} +} diff --git a/gcc/testsuite/g++.dg/compat/decimal/pass-1_main.C b/gcc/testsuite/g++.dg/compat/decimal/pass-1_main.C new file mode 100644 index 000000000..963dc3bbf --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/pass-1_main.C @@ -0,0 +1,13 @@ +/* { dg-require-effective-target dfp } */ + +/* Test passing decimal scalars by value. */ + +extern void pass_1_x (void); +int fails; + +int +main () +{ + pass_1_x (); + return 0; +} diff --git a/gcc/testsuite/g++.dg/compat/decimal/pass-1_x.C b/gcc/testsuite/g++.dg/compat/decimal/pass-1_x.C new file mode 100644 index 000000000..265a1317b --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/pass-1_x.C @@ -0,0 +1,30 @@ +typedef float dec32 __attribute__((mode(SD))); +typedef float dec64 __attribute__((mode(DD))); +typedef float dec128 __attribute__((mode(TD))); + +#include "pass_x.h" + +void +pass_1_x (void) +{ +DEBUG_INIT + +#define T(NAME) testit##NAME (); + +#ifndef SKIP_DECIMAL32 +T(d32) +#endif +#ifndef SKIP_DECIMAL64 +T(d64) +#endif +#ifndef SKIP_DECIMAL128 +T(d128) +#endif + +DEBUG_FINI + +if (fails != 0) + abort (); + +#undef T +} diff --git a/gcc/testsuite/g++.dg/compat/decimal/pass-1_y.C b/gcc/testsuite/g++.dg/compat/decimal/pass-1_y.C new file mode 100644 index 000000000..5da7f87d5 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/pass-1_y.C @@ -0,0 +1,5 @@ +typedef float dec32 __attribute__((mode(SD))); +typedef float dec64 __attribute__((mode(DD))); +typedef float dec128 __attribute__((mode(TD))); + +#include "pass_y.h" diff --git a/gcc/testsuite/g++.dg/compat/decimal/pass-2_main.C b/gcc/testsuite/g++.dg/compat/decimal/pass-2_main.C new file mode 100644 index 000000000..533e4b276 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/pass-2_main.C @@ -0,0 +1,13 @@ +/* { dg-require-effective-target dfp } */ + +/* Test passing decimal classes by value. */ + +extern void pass_2_x (void); +int fails; + +int +main () +{ + pass_2_x (); + return 0; +} diff --git a/gcc/testsuite/g++.dg/compat/decimal/pass-2_x.C b/gcc/testsuite/g++.dg/compat/decimal/pass-2_x.C new file mode 100644 index 000000000..8a67bda0e --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/pass-2_x.C @@ -0,0 +1,32 @@ +#include "decimal-dummy.h" + +#define dec32 std::decimal::decimal32 +#define dec64 std::decimal::decimal64 +#define dec128 std::decimal::decimal128 + +#include "pass_x.h" + +void +pass_2_x (void) +{ +DEBUG_INIT + +#define T(NAME) testit##NAME (); + +#ifndef SKIP_DECIMAL32 +T(d32) +#endif +#ifndef SKIP_DECIMAL64 +T(d64) +#endif +#ifndef SKIP_DECIMAL128 +T(d128) +#endif + +DEBUG_FINI + +if (fails != 0) + abort (); + +#undef T +} diff --git a/gcc/testsuite/g++.dg/compat/decimal/pass-2_y.C b/gcc/testsuite/g++.dg/compat/decimal/pass-2_y.C new file mode 100644 index 000000000..97471457d --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/pass-2_y.C @@ -0,0 +1,7 @@ +#include "decimal-dummy.h" + +#define dec32 std::decimal::decimal32 +#define dec64 std::decimal::decimal64 +#define dec128 std::decimal::decimal128 + +#include "pass_y.h" diff --git a/gcc/testsuite/g++.dg/compat/decimal/pass-3_main.C b/gcc/testsuite/g++.dg/compat/decimal/pass-3_main.C new file mode 100644 index 000000000..de09992c2 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/pass-3_main.C @@ -0,0 +1,13 @@ +/* { dg-require-effective-target dfp } */ + +/* Test passing decimal scalars and classes by value. */ + +extern void pass_3_x (void); +int fails; + +int +main () +{ + pass_3_x (); + return 0; +} diff --git a/gcc/testsuite/g++.dg/compat/decimal/pass-3_x.C b/gcc/testsuite/g++.dg/compat/decimal/pass-3_x.C new file mode 100644 index 000000000..17e4d1c8b --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/pass-3_x.C @@ -0,0 +1,30 @@ +typedef float dec32 __attribute__((mode(SD))); +typedef float dec64 __attribute__((mode(DD))); +typedef float dec128 __attribute__((mode(TD))); + +#include "pass_x.h" + +void +pass_3_x (void) +{ +DEBUG_INIT + +#define T(NAME) testit##NAME (); + +#ifndef SKIP_DECIMAL32 +T(d32) +#endif +#ifndef SKIP_DECIMAL64 +T(d64) +#endif +#ifndef SKIP_DECIMAL128 +T(d128) +#endif + +DEBUG_FINI + +if (fails != 0) + abort (); + +#undef T +} diff --git a/gcc/testsuite/g++.dg/compat/decimal/pass-3_y.C b/gcc/testsuite/g++.dg/compat/decimal/pass-3_y.C new file mode 100644 index 000000000..97471457d --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/pass-3_y.C @@ -0,0 +1,7 @@ +#include "decimal-dummy.h" + +#define dec32 std::decimal::decimal32 +#define dec64 std::decimal::decimal64 +#define dec128 std::decimal::decimal128 + +#include "pass_y.h" diff --git a/gcc/testsuite/g++.dg/compat/decimal/pass-4_main.C b/gcc/testsuite/g++.dg/compat/decimal/pass-4_main.C new file mode 100644 index 000000000..d5a0a47d4 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/pass-4_main.C @@ -0,0 +1,13 @@ +/* { dg-require-effective-target dfp } */ + +/* Test passing decimal classes and scalars by value. */ + +extern void pass_4_x (void); +int fails; + +int +main () +{ + pass_4_x (); + return 0; +} diff --git a/gcc/testsuite/g++.dg/compat/decimal/pass-4_x.C b/gcc/testsuite/g++.dg/compat/decimal/pass-4_x.C new file mode 100644 index 000000000..b0483ac27 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/pass-4_x.C @@ -0,0 +1,32 @@ +#include "decimal-dummy.h" + +#define dec32 std::decimal::decimal32 +#define dec64 std::decimal::decimal64 +#define dec128 std::decimal::decimal128 + +#include "pass_x.h" + +void +pass_4_x (void) +{ +DEBUG_INIT + +#define T(NAME) testit##NAME (); + +#ifndef SKIP_DECIMAL32 +T(d32) +#endif +#ifndef SKIP_DECIMAL64 +T(d64) +#endif +#ifndef SKIP_DECIMAL128 +T(d128) +#endif + +DEBUG_FINI + +if (fails != 0) + abort (); + +#undef T +} diff --git a/gcc/testsuite/g++.dg/compat/decimal/pass-4_y.C b/gcc/testsuite/g++.dg/compat/decimal/pass-4_y.C new file mode 100644 index 000000000..5da7f87d5 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/pass-4_y.C @@ -0,0 +1,5 @@ +typedef float dec32 __attribute__((mode(SD))); +typedef float dec64 __attribute__((mode(DD))); +typedef float dec128 __attribute__((mode(TD))); + +#include "pass_y.h" diff --git a/gcc/testsuite/g++.dg/compat/decimal/pass-5_main.C b/gcc/testsuite/g++.dg/compat/decimal/pass-5_main.C new file mode 100644 index 000000000..9b25a49c7 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/pass-5_main.C @@ -0,0 +1,13 @@ +/* { dg-require-effective-target dfp } */ + +/* Test passing decimal scalars and typedef'd classes by value. */ + +extern void pass_5_x (void); +int fails; + +int +main () +{ + pass_5_x (); + return 0; +} diff --git a/gcc/testsuite/g++.dg/compat/decimal/pass-5_x.C b/gcc/testsuite/g++.dg/compat/decimal/pass-5_x.C new file mode 100644 index 000000000..11c4d96c9 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/pass-5_x.C @@ -0,0 +1,30 @@ +typedef float dec32 __attribute__((mode(SD))); +typedef float dec64 __attribute__((mode(DD))); +typedef float dec128 __attribute__((mode(TD))); + +#include "pass_x.h" + +void +pass_5_x (void) +{ +DEBUG_INIT + +#define T(NAME) testit##NAME (); + +#ifndef SKIP_DECIMAL32 +T(d32) +#endif +#ifndef SKIP_DECIMAL64 +T(d64) +#endif +#ifndef SKIP_DECIMAL128 +T(d128) +#endif + +DEBUG_FINI + +if (fails != 0) + abort (); + +#undef T +} diff --git a/gcc/testsuite/g++.dg/compat/decimal/pass-5_y.C b/gcc/testsuite/g++.dg/compat/decimal/pass-5_y.C new file mode 100644 index 000000000..5a2c1fba0 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/pass-5_y.C @@ -0,0 +1,7 @@ +#include "decimal-dummy.h" + +typedef std::decimal::decimal32 dec32; +typedef std::decimal::decimal64 dec64; +typedef std::decimal::decimal128 dec128; + +#include "pass_y.h" diff --git a/gcc/testsuite/g++.dg/compat/decimal/pass-6_main.C b/gcc/testsuite/g++.dg/compat/decimal/pass-6_main.C new file mode 100644 index 000000000..1b686a21d --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/pass-6_main.C @@ -0,0 +1,13 @@ +/* { dg-require-effective-target dfp } */ + +/* Test passing typedef'd decimal classes and scalars by value. */ + +extern void pass_6_x (void); +int fails; + +int +main () +{ + pass_6_x (); + return 0; +} diff --git a/gcc/testsuite/g++.dg/compat/decimal/pass-6_x.C b/gcc/testsuite/g++.dg/compat/decimal/pass-6_x.C new file mode 100644 index 000000000..e59ca7f72 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/pass-6_x.C @@ -0,0 +1,32 @@ +#include "decimal-dummy.h" + +typedef std::decimal::decimal32 dec32; +typedef std::decimal::decimal64 dec64; +typedef std::decimal::decimal128 dec128; + +#include "pass_x.h" + +void +pass_6_x (void) +{ +DEBUG_INIT + +#define T(NAME) testit##NAME (); + +#ifndef SKIP_DECIMAL32 +T(d32) +#endif +#ifndef SKIP_DECIMAL64 +T(d64) +#endif +#ifndef SKIP_DECIMAL128 +T(d128) +#endif + +DEBUG_FINI + +if (fails != 0) + abort (); + +#undef T +} diff --git a/gcc/testsuite/g++.dg/compat/decimal/pass-6_y.C b/gcc/testsuite/g++.dg/compat/decimal/pass-6_y.C new file mode 100644 index 000000000..5da7f87d5 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/pass-6_y.C @@ -0,0 +1,5 @@ +typedef float dec32 __attribute__((mode(SD))); +typedef float dec64 __attribute__((mode(DD))); +typedef float dec128 __attribute__((mode(TD))); + +#include "pass_y.h" diff --git a/gcc/testsuite/g++.dg/compat/decimal/pass_x.h b/gcc/testsuite/g++.dg/compat/decimal/pass_x.h new file mode 100644 index 000000000..5b25dc9bf --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/pass_x.h @@ -0,0 +1,151 @@ +#include "compat-common.h" + +#define T(NAME, TYPE, INITVAL) \ +TYPE g01##NAME, g02##NAME, g03##NAME, g04##NAME; \ +TYPE g05##NAME, g06##NAME, g07##NAME, g08##NAME; \ +TYPE g09##NAME, g10##NAME, g11##NAME, g12##NAME; \ +TYPE g13##NAME, g14##NAME, g15##NAME, g16##NAME; \ + \ +extern void init##NAME (TYPE *p, TYPE v); \ +extern void checkg##NAME (void); \ +extern void \ +test##NAME (TYPE x01, TYPE x02, TYPE x03, TYPE x04, \ + TYPE x05, TYPE x06, TYPE x07, TYPE x08, \ + TYPE x09, TYPE x10, TYPE x11, TYPE x12, \ + TYPE x13, TYPE x14, TYPE x15, TYPE x16); \ +extern void testva##NAME (int n, ...); \ + \ +extern void \ +check##NAME (TYPE x, TYPE v) \ +{ \ + if (x != v + INITVAL) \ + DEBUG_CHECK \ +} \ + \ +extern void \ +test2_##NAME (TYPE x01, TYPE x02, TYPE x03, TYPE x04, \ + TYPE x05, TYPE x06, TYPE x07, TYPE x08) \ +{ \ + test##NAME (x01, g02##NAME, x02, g04##NAME, \ + x03, g06##NAME, x04, g08##NAME, \ + x05, g10##NAME, x06, g12##NAME, \ + x07, g14##NAME, x08, g16##NAME); \ +} \ + \ +extern void \ +testit##NAME (void) \ +{ \ + DEBUG_FPUTS (#NAME) \ + DEBUG_FPUTS (" init: ") \ + init##NAME (&g01##NAME, 1); \ + init##NAME (&g02##NAME, 2); \ + init##NAME (&g03##NAME, 3); \ + init##NAME (&g04##NAME, 4); \ + init##NAME (&g05##NAME, 5); \ + init##NAME (&g06##NAME, 6); \ + init##NAME (&g07##NAME, 7); \ + init##NAME (&g08##NAME, 8); \ + init##NAME (&g09##NAME, 9); \ + init##NAME (&g10##NAME, 10); \ + init##NAME (&g11##NAME, 11); \ + init##NAME (&g12##NAME, 12); \ + init##NAME (&g13##NAME, 13); \ + init##NAME (&g14##NAME, 14); \ + init##NAME (&g15##NAME, 15); \ + init##NAME (&g16##NAME, 16); \ + checkg##NAME (); \ + DEBUG_NL \ + DEBUG_FPUTS (#NAME) \ + DEBUG_FPUTS (" test: ") \ + test##NAME (g01##NAME, g02##NAME, g03##NAME, g04##NAME, \ + g05##NAME, g06##NAME, g07##NAME, g08##NAME, \ + g09##NAME, g10##NAME, g11##NAME, g12##NAME, \ + g13##NAME, g14##NAME, g15##NAME, g16##NAME); \ + DEBUG_NL \ + DEBUG_FPUTS (#NAME) \ + DEBUG_FPUTS (" testva: ") \ + DEBUG_NL \ + testva##NAME (1, \ + g01##NAME); \ + DEBUG_NL \ + testva##NAME (2, \ + g01##NAME, g02##NAME); \ + DEBUG_NL \ + testva##NAME (3, \ + g01##NAME, g02##NAME, g03##NAME); \ + DEBUG_NL \ + testva##NAME (4, \ + g01##NAME, g02##NAME, g03##NAME, g04##NAME); \ + DEBUG_NL \ + testva##NAME (5, \ + g01##NAME, g02##NAME, g03##NAME, g04##NAME, \ + g05##NAME); \ + DEBUG_NL \ + testva##NAME (6, \ + g01##NAME, g02##NAME, g03##NAME, g04##NAME, \ + g05##NAME, g06##NAME); \ + DEBUG_NL \ + testva##NAME (7, \ + g01##NAME, g02##NAME, g03##NAME, g04##NAME, \ + g05##NAME, g06##NAME, g07##NAME); \ + DEBUG_NL \ + testva##NAME (8, \ + g01##NAME, g02##NAME, g03##NAME, g04##NAME, \ + g05##NAME, g06##NAME, g07##NAME, g08##NAME); \ + DEBUG_NL \ + testva##NAME (9, \ + g01##NAME, g02##NAME, g03##NAME, g04##NAME, \ + g05##NAME, g06##NAME, g07##NAME, g08##NAME, \ + g09##NAME); \ + DEBUG_NL \ + testva##NAME (10, \ + g01##NAME, g02##NAME, g03##NAME, g04##NAME, \ + g05##NAME, g06##NAME, g07##NAME, g08##NAME, \ + g09##NAME, g10##NAME); \ + DEBUG_NL \ + testva##NAME (11, \ + g01##NAME, g02##NAME, g03##NAME, g04##NAME, \ + g05##NAME, g06##NAME, g07##NAME, g08##NAME, \ + g09##NAME, g10##NAME, g11##NAME); \ + DEBUG_NL \ + testva##NAME (12, \ + g01##NAME, g02##NAME, g03##NAME, g04##NAME, \ + g05##NAME, g06##NAME, g07##NAME, g08##NAME, \ + g09##NAME, g10##NAME, g11##NAME, g12##NAME); \ + DEBUG_NL \ + testva##NAME (13, \ + g01##NAME, g02##NAME, g03##NAME, g04##NAME, \ + g05##NAME, g06##NAME, g07##NAME, g08##NAME, \ + g09##NAME, g10##NAME, g11##NAME, g12##NAME, \ + g13##NAME); \ + DEBUG_NL \ + testva##NAME (14, \ + g01##NAME, g02##NAME, g03##NAME, g04##NAME, \ + g05##NAME, g06##NAME, g07##NAME, g08##NAME, \ + g09##NAME, g10##NAME, g11##NAME, g12##NAME, \ + g13##NAME, g14##NAME); \ + DEBUG_NL \ + testva##NAME (15, \ + g01##NAME, g02##NAME, g03##NAME, g04##NAME, \ + g05##NAME, g06##NAME, g07##NAME, g08##NAME, \ + g09##NAME, g10##NAME, g11##NAME, g12##NAME, \ + g13##NAME, g14##NAME, g15##NAME); \ + DEBUG_NL \ + testva##NAME (16, \ + g01##NAME, g02##NAME, g03##NAME, g04##NAME, \ + g05##NAME, g06##NAME, g07##NAME, g08##NAME, \ + g09##NAME, g10##NAME, g11##NAME, g12##NAME, \ + g13##NAME, g14##NAME, g15##NAME, g16##NAME); \ + DEBUG_NL \ + DEBUG_FPUTS (#NAME) \ + DEBUG_FPUTS (" test2: ") \ + test2_##NAME (g01##NAME, g03##NAME, g05##NAME, g07##NAME, \ + g09##NAME, g11##NAME, g13##NAME, g15##NAME); \ + DEBUG_NL \ +} + +T(d32, dec32, (dec32)1.5DF) +T(d64, dec64, (dec64)2.5DD) +T(d128, dec128, (dec128)3.5DL) + +#undef T diff --git a/gcc/testsuite/g++.dg/compat/decimal/pass_y.h b/gcc/testsuite/g++.dg/compat/decimal/pass_y.h new file mode 100644 index 000000000..f835b1983 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/pass_y.h @@ -0,0 +1,89 @@ +#include <stdarg.h> + +#include "compat-common.h" + +#ifdef SKIP_VA +const int test_va = 0; +#else +const int test_va = 1; +#endif + +#define T(NAME, TYPE, INITVAL) \ +extern TYPE g01##NAME, g02##NAME, g03##NAME, g04##NAME; \ +extern TYPE g05##NAME, g06##NAME, g07##NAME, g08##NAME; \ +extern TYPE g09##NAME, g10##NAME, g11##NAME, g12##NAME; \ +extern TYPE g13##NAME, g14##NAME, g15##NAME, g16##NAME; \ + \ +extern void check##NAME (TYPE x, TYPE v); \ + \ +extern void \ +init##NAME (TYPE *p, TYPE v) \ +{ \ + *p = v + INITVAL; \ +} \ + \ +extern void \ +checkg##NAME (void) \ +{ \ + check##NAME (g01##NAME, 1); \ + check##NAME (g02##NAME, 2); \ + check##NAME (g03##NAME, 3); \ + check##NAME (g04##NAME, 4); \ + check##NAME (g05##NAME, 5); \ + check##NAME (g06##NAME, 6); \ + check##NAME (g07##NAME, 7); \ + check##NAME (g08##NAME, 8); \ + check##NAME (g09##NAME, 9); \ + check##NAME (g10##NAME, 10); \ + check##NAME (g11##NAME, 11); \ + check##NAME (g12##NAME, 12); \ + check##NAME (g13##NAME, 13); \ + check##NAME (g14##NAME, 14); \ + check##NAME (g15##NAME, 15); \ + check##NAME (g16##NAME, 16); \ +} \ + \ +extern void \ +test##NAME (TYPE x01, TYPE x02, TYPE x03, TYPE x04, \ + TYPE x05, TYPE x06, TYPE x07, TYPE x08, \ + TYPE x09, TYPE x10, TYPE x11, TYPE x12, \ + TYPE x13, TYPE x14, TYPE x15, TYPE x16) \ +{ \ + check##NAME (x01, 1); \ + check##NAME (x02, 2); \ + check##NAME (x03, 3); \ + check##NAME (x04, 4); \ + check##NAME (x05, 5); \ + check##NAME (x06, 6); \ + check##NAME (x07, 7); \ + check##NAME (x08, 8); \ + check##NAME (x09, 9); \ + check##NAME (x10, 10); \ + check##NAME (x11, 11); \ + check##NAME (x12, 12); \ + check##NAME (x13, 13); \ + check##NAME (x14, 14); \ + check##NAME (x15, 15); \ + check##NAME (x16, 16); \ +} \ + \ +extern void \ +testva##NAME (int n, ...) \ +{ \ + int i; \ + va_list ap; \ + if (test_va) \ + { \ + va_start (ap, n); \ + for (i = 0; i < n; i++) \ + { \ + TYPE t = va_arg (ap, TYPE); \ + check##NAME (t, i+1); \ + } \ + va_end (ap); \ + } \ +} + +T(d32, dec32, (dec32)1.5DF) +T(d64, dec64, (dec64)2.5DD) +T(d128, dec128, (dec128)3.5DL) diff --git a/gcc/testsuite/g++.dg/compat/decimal/return-1_main.C b/gcc/testsuite/g++.dg/compat/decimal/return-1_main.C new file mode 100644 index 000000000..c663bb01c --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/return-1_main.C @@ -0,0 +1,13 @@ +/* { dg-require-effective-target dfp } */ + +/* Test function return values for decimal float scalars. */ + +extern void return_1_x (void); +int fails; + +int +main () +{ + return_1_x (); + return 0; +} diff --git a/gcc/testsuite/g++.dg/compat/decimal/return-1_x.C b/gcc/testsuite/g++.dg/compat/decimal/return-1_x.C new file mode 100644 index 000000000..e391bd1f1 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/return-1_x.C @@ -0,0 +1,24 @@ +typedef float dec32 __attribute__((mode(SD))); +typedef float dec64 __attribute__((mode(DD))); +typedef float dec128 __attribute__((mode(TD))); + +#include "return_x.h" + +void +return_1_x (void) +{ +DEBUG_INIT + +#define T(NAME) testit##NAME (); + +T(d32) +T(d64) +T(d128) + +DEBUG_FINI + +if (fails != 0) + abort (); + +#undef T +} diff --git a/gcc/testsuite/g++.dg/compat/decimal/return-1_y.C b/gcc/testsuite/g++.dg/compat/decimal/return-1_y.C new file mode 100644 index 000000000..0b4d4bf38 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/return-1_y.C @@ -0,0 +1,5 @@ +typedef float dec32 __attribute__((mode(SD))); +typedef float dec64 __attribute__((mode(DD))); +typedef float dec128 __attribute__((mode(TD))); + +#include "return_y.h" diff --git a/gcc/testsuite/g++.dg/compat/decimal/return-2_main.C b/gcc/testsuite/g++.dg/compat/decimal/return-2_main.C new file mode 100644 index 000000000..afa27f269 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/return-2_main.C @@ -0,0 +1,13 @@ +/* { dg-require-effective-target dfp } */ + +/* Test function return values for decimal classes. */ + +extern void return_2_x (void); +int fails; + +int +main () +{ + return_2_x (); + return 0; +} diff --git a/gcc/testsuite/g++.dg/compat/decimal/return-2_x.C b/gcc/testsuite/g++.dg/compat/decimal/return-2_x.C new file mode 100644 index 000000000..d96c01479 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/return-2_x.C @@ -0,0 +1,26 @@ +#include "decimal-dummy.h" + +#define dec32 std::decimal::decimal32 +#define dec64 std::decimal::decimal64 +#define dec128 std::decimal::decimal128 + +#include "return_x.h" + +void +return_2_x (void) +{ +DEBUG_INIT + +#define T(NAME) testit##NAME (); + +T(d32) +T(d64) +T(d128) + +DEBUG_FINI + +if (fails != 0) + abort (); + +#undef T +} diff --git a/gcc/testsuite/g++.dg/compat/decimal/return-2_y.C b/gcc/testsuite/g++.dg/compat/decimal/return-2_y.C new file mode 100644 index 000000000..c68088b30 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/return-2_y.C @@ -0,0 +1,7 @@ +#include "decimal-dummy.h" + +#define dec32 std::decimal::decimal32 +#define dec64 std::decimal::decimal64 +#define dec128 std::decimal::decimal128 + +#include "return_y.h" diff --git a/gcc/testsuite/g++.dg/compat/decimal/return-3_main.C b/gcc/testsuite/g++.dg/compat/decimal/return-3_main.C new file mode 100644 index 000000000..468f3fc0c --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/return-3_main.C @@ -0,0 +1,13 @@ +/* { dg-require-effective-target dfp } */ + +/* Test function return values for decimal float scalars and classes. */ + +extern void return_3_x (void); +int fails; + +int +main () +{ + return_3_x (); + return 0; +} diff --git a/gcc/testsuite/g++.dg/compat/decimal/return-3_x.C b/gcc/testsuite/g++.dg/compat/decimal/return-3_x.C new file mode 100644 index 000000000..52e599c76 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/return-3_x.C @@ -0,0 +1,24 @@ +typedef float dec32 __attribute__((mode(SD))); +typedef float dec64 __attribute__((mode(DD))); +typedef float dec128 __attribute__((mode(TD))); + +#include "return_x.h" + +void +return_3_x (void) +{ +DEBUG_INIT + +#define T(NAME) testit##NAME (); + +T(d32) +T(d64) +T(d128) + +DEBUG_FINI + +if (fails != 0) + abort (); + +#undef T +} diff --git a/gcc/testsuite/g++.dg/compat/decimal/return-3_y.C b/gcc/testsuite/g++.dg/compat/decimal/return-3_y.C new file mode 100644 index 000000000..c68088b30 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/return-3_y.C @@ -0,0 +1,7 @@ +#include "decimal-dummy.h" + +#define dec32 std::decimal::decimal32 +#define dec64 std::decimal::decimal64 +#define dec128 std::decimal::decimal128 + +#include "return_y.h" diff --git a/gcc/testsuite/g++.dg/compat/decimal/return-4_main.C b/gcc/testsuite/g++.dg/compat/decimal/return-4_main.C new file mode 100644 index 000000000..365d8becd --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/return-4_main.C @@ -0,0 +1,13 @@ +/* { dg-require-effective-target dfp } */ + +/* Test function return values for decimal float classes and scalars. */ + +extern void return_4_x (void); +int fails; + +int +main () +{ + return_4_x (); + return 0; +} diff --git a/gcc/testsuite/g++.dg/compat/decimal/return-4_x.C b/gcc/testsuite/g++.dg/compat/decimal/return-4_x.C new file mode 100644 index 000000000..b9d28fa5b --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/return-4_x.C @@ -0,0 +1,26 @@ +#include "decimal-dummy.h" + +#define dec32 std::decimal::decimal32 +#define dec64 std::decimal::decimal64 +#define dec128 std::decimal::decimal128 + +#include "return_x.h" + +void +return_4_x (void) +{ +DEBUG_INIT + +#define T(NAME) testit##NAME (); + +T(d32) +T(d64) +T(d128) + +DEBUG_FINI + +if (fails != 0) + abort (); + +#undef T +} diff --git a/gcc/testsuite/g++.dg/compat/decimal/return-4_y.C b/gcc/testsuite/g++.dg/compat/decimal/return-4_y.C new file mode 100644 index 000000000..0b4d4bf38 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/return-4_y.C @@ -0,0 +1,5 @@ +typedef float dec32 __attribute__((mode(SD))); +typedef float dec64 __attribute__((mode(DD))); +typedef float dec128 __attribute__((mode(TD))); + +#include "return_y.h" diff --git a/gcc/testsuite/g++.dg/compat/decimal/return-5_main.C b/gcc/testsuite/g++.dg/compat/decimal/return-5_main.C new file mode 100644 index 000000000..2c3348327 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/return-5_main.C @@ -0,0 +1,14 @@ +/* { dg-require-effective-target dfp } */ + +/* Test function return values for decimal float scalars and typedef'd + classes. */ + +extern void return_5_x (void); +int fails; + +int +main () +{ + return_5_x (); + return 0; +} diff --git a/gcc/testsuite/g++.dg/compat/decimal/return-5_x.C b/gcc/testsuite/g++.dg/compat/decimal/return-5_x.C new file mode 100644 index 000000000..a2bb6173b --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/return-5_x.C @@ -0,0 +1,24 @@ +typedef float dec32 __attribute__((mode(SD))); +typedef float dec64 __attribute__((mode(DD))); +typedef float dec128 __attribute__((mode(TD))); + +#include "return_x.h" + +void +return_5_x (void) +{ +DEBUG_INIT + +#define T(NAME) testit##NAME (); + +T(d32) +T(d64) +T(d128) + +DEBUG_FINI + +if (fails != 0) + abort (); + +#undef T +} diff --git a/gcc/testsuite/g++.dg/compat/decimal/return-5_y.C b/gcc/testsuite/g++.dg/compat/decimal/return-5_y.C new file mode 100644 index 000000000..0f780167a --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/return-5_y.C @@ -0,0 +1,7 @@ +#include "decimal-dummy.h" + +typedef std::decimal::decimal32 dec32; +typedef std::decimal::decimal64 dec64; +typedef std::decimal::decimal128 dec128; + +#include "return_y.h" diff --git a/gcc/testsuite/g++.dg/compat/decimal/return-6_main.C b/gcc/testsuite/g++.dg/compat/decimal/return-6_main.C new file mode 100644 index 000000000..94526bdcb --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/return-6_main.C @@ -0,0 +1,14 @@ +/* { dg-require-effective-target dfp } */ + +/* Test function return values for typedef'd decimal float classes + and scalars. */ + +extern void return_6_x (void); +int fails; + +int +main () +{ + return_6_x (); + return 0; +} diff --git a/gcc/testsuite/g++.dg/compat/decimal/return-6_x.C b/gcc/testsuite/g++.dg/compat/decimal/return-6_x.C new file mode 100644 index 000000000..e0a487dbe --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/return-6_x.C @@ -0,0 +1,26 @@ +#include "decimal-dummy.h" + +typedef std::decimal::decimal32 dec32; +typedef std::decimal::decimal64 dec64; +typedef std::decimal::decimal128 dec128; + +#include "return_x.h" + +void +return_6_x (void) +{ +DEBUG_INIT + +#define T(NAME) testit##NAME (); + +T(d32) +T(d64) +T(d128) + +DEBUG_FINI + +if (fails != 0) + abort (); + +#undef T +} diff --git a/gcc/testsuite/g++.dg/compat/decimal/return-6_y.C b/gcc/testsuite/g++.dg/compat/decimal/return-6_y.C new file mode 100644 index 000000000..0b4d4bf38 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/return-6_y.C @@ -0,0 +1,5 @@ +typedef float dec32 __attribute__((mode(SD))); +typedef float dec64 __attribute__((mode(DD))); +typedef float dec128 __attribute__((mode(TD))); + +#include "return_y.h" diff --git a/gcc/testsuite/g++.dg/compat/decimal/return_x.h b/gcc/testsuite/g++.dg/compat/decimal/return_x.h new file mode 100644 index 000000000..401adfb5c --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/return_x.h @@ -0,0 +1,90 @@ +#include "compat-common.h" + +#ifdef SKIP_VA +const int test_va = 0; +#else +const int test_va = 1; +#endif + +#define T(NAME, TYPE, INITVAL) \ +TYPE g01##NAME, g02##NAME, g03##NAME, g04##NAME; \ +TYPE g05##NAME, g06##NAME, g07##NAME, g08##NAME; \ +TYPE g09##NAME, g10##NAME, g11##NAME, g12##NAME; \ +TYPE g13##NAME, g14##NAME, g15##NAME, g16##NAME; \ + \ +extern void init##NAME (TYPE *p, TYPE v); \ +extern void checkg##NAME (void); \ +extern TYPE test0##NAME (void); \ +extern TYPE test1##NAME (TYPE); \ +extern TYPE testva##NAME (int n, ...); \ + \ +extern void \ +check##NAME (TYPE x, TYPE v) \ +{ \ + if (x != v) \ + DEBUG_CHECK \ +} \ + \ +extern void \ +testit##NAME (void) \ +{ \ + TYPE rslt; \ + DEBUG_FPUTS (#NAME) \ + DEBUG_FPUTS (" init: ") \ + init##NAME (&g01##NAME, 1); \ + init##NAME (&g02##NAME, 2); \ + init##NAME (&g03##NAME, 3); \ + init##NAME (&g04##NAME, 4); \ + init##NAME (&g05##NAME, 5); \ + init##NAME (&g06##NAME, 6); \ + init##NAME (&g07##NAME, 7); \ + init##NAME (&g08##NAME, 8); \ + init##NAME (&g09##NAME, 9); \ + init##NAME (&g10##NAME, 10); \ + init##NAME (&g11##NAME, 11); \ + init##NAME (&g12##NAME, 12); \ + init##NAME (&g13##NAME, 13); \ + init##NAME (&g14##NAME, 14); \ + init##NAME (&g15##NAME, 15); \ + init##NAME (&g16##NAME, 16); \ + checkg##NAME (); \ + DEBUG_NL \ + DEBUG_FPUTS (#NAME) \ + DEBUG_FPUTS (" test0: ") \ + rslt = test0##NAME (); \ + check##NAME (rslt, g01##NAME); \ + DEBUG_NL \ + DEBUG_FPUTS (#NAME) \ + DEBUG_FPUTS (" test1: ") \ + rslt = test1##NAME (g01##NAME); \ + check##NAME (rslt, g01##NAME); \ + if (test_va) \ + { \ + DEBUG_NL \ + DEBUG_FPUTS (#NAME) \ + DEBUG_FPUTS (" testva: ") \ + rslt = testva##NAME (1, g01##NAME); \ + check##NAME (rslt, g01##NAME); \ + rslt = testva##NAME (5, g01##NAME, g02##NAME, g03##NAME, \ + g04##NAME, g05##NAME); \ + check##NAME (rslt, g05##NAME); \ + rslt = testva##NAME (9, g01##NAME, g02##NAME, g03##NAME, \ + g04##NAME, g05##NAME, g06##NAME, \ + g07##NAME, g08##NAME, g09##NAME); \ + check##NAME (rslt, g09##NAME); \ + rslt = testva##NAME (16, g01##NAME, g02##NAME, g03##NAME, \ + g04##NAME, g05##NAME, g06##NAME, \ + g07##NAME, g08##NAME, g09##NAME, \ + g10##NAME, g11##NAME, g12##NAME, \ + g13##NAME, g14##NAME, g15##NAME, \ + g16##NAME); \ + check##NAME (rslt, g16##NAME); \ + } \ + DEBUG_NL \ +} + +T(d32, dec32, (dec32)1.5DF); +T(d64, dec64, (dec64)2.5DD); +T(d128, dec128, (dec128)3.5DL); + +#undef T diff --git a/gcc/testsuite/g++.dg/compat/decimal/return_y.h b/gcc/testsuite/g++.dg/compat/decimal/return_y.h new file mode 100644 index 000000000..285526e2e --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/decimal/return_y.h @@ -0,0 +1,67 @@ +#include <stdarg.h> + +#include "compat-common.h" + +#define T(NAME, TYPE, INITVAL) \ +extern TYPE g01##NAME, g02##NAME, g03##NAME, g04##NAME; \ +extern TYPE g05##NAME, g06##NAME, g07##NAME, g08##NAME; \ +extern TYPE g09##NAME, g10##NAME, g11##NAME, g12##NAME; \ +extern TYPE g13##NAME, g14##NAME, g15##NAME, g16##NAME; \ + \ +extern void check##NAME (TYPE x, TYPE v); \ + \ +extern void \ +init##NAME (TYPE *p, TYPE v) \ +{ \ + *p = v + INITVAL; \ +} \ + \ +extern void \ +checkg##NAME (void) \ +{ \ + check##NAME (g01##NAME, 1+INITVAL); \ + check##NAME (g02##NAME, 2+INITVAL); \ + check##NAME (g03##NAME, 3+INITVAL); \ + check##NAME (g04##NAME, 4+INITVAL); \ + check##NAME (g05##NAME, 5+INITVAL); \ + check##NAME (g06##NAME, 6+INITVAL); \ + check##NAME (g07##NAME, 7+INITVAL); \ + check##NAME (g08##NAME, 8+INITVAL); \ + check##NAME (g09##NAME, 9+INITVAL); \ + check##NAME (g10##NAME, 10+INITVAL); \ + check##NAME (g11##NAME, 11+INITVAL); \ + check##NAME (g12##NAME, 12+INITVAL); \ + check##NAME (g13##NAME, 13+INITVAL); \ + check##NAME (g14##NAME, 14+INITVAL); \ + check##NAME (g15##NAME, 15+INITVAL); \ + check##NAME (g16##NAME, 16+INITVAL); \ +} \ + \ +extern TYPE \ +test0##NAME (void) \ +{ \ + return g01##NAME; \ +} \ + \ +extern TYPE \ +test1##NAME (TYPE x01) \ +{ \ + return x01; \ +} \ + \ +extern TYPE \ +testva##NAME (int n, ...) \ +{ \ + int i; \ + TYPE rslt; \ + va_list ap; \ + va_start (ap, n); \ + for (i = 0; i < n; i++) \ + rslt = va_arg (ap, TYPE); \ + va_end (ap); \ + return rslt; \ +} + +T(d32, dec32, (dec32)1.5) +T(d64, dec64, (dec64)2.5) +T(d128, dec128, (dec128)3.5) diff --git a/gcc/testsuite/g++.dg/compat/eh/ctor1.h b/gcc/testsuite/g++.dg/compat/eh/ctor1.h new file mode 100644 index 000000000..e83476f2d --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/eh/ctor1.h @@ -0,0 +1,10 @@ +struct Foo +{ + ~Foo (); +}; + +struct Bar +{ + ~Bar (); + Foo f; +}; diff --git a/gcc/testsuite/g++.dg/compat/eh/ctor1_main.C b/gcc/testsuite/g++.dg/compat/eh/ctor1_main.C new file mode 100644 index 000000000..a188b46da --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/eh/ctor1_main.C @@ -0,0 +1,13 @@ +// Copyright (C) 2001 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 26 Dec 2001 <nathan@nathan@codesourcery.com> +// PR 411 + +// Split into pieces for binary compatibility testing October 2002 + +extern void ctor1_x (void); + +int +main () +{ + ctor1_x (); +} diff --git a/gcc/testsuite/g++.dg/compat/eh/ctor1_x.C b/gcc/testsuite/g++.dg/compat/eh/ctor1_x.C new file mode 100644 index 000000000..d74a52087 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/eh/ctor1_x.C @@ -0,0 +1,22 @@ +extern "C" void abort (void); +extern "C" void exit (int); + +#include "ctor1.h" + +bool was_f_in_Bar_destroyed=false; + +void ctor1_x () +{ + try + { + Bar f; + } + catch(int i) + { + if(was_f_in_Bar_destroyed) + { + exit (0); + } + } + abort (); +} diff --git a/gcc/testsuite/g++.dg/compat/eh/ctor1_y.C b/gcc/testsuite/g++.dg/compat/eh/ctor1_y.C new file mode 100644 index 000000000..260ab1c34 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/eh/ctor1_y.C @@ -0,0 +1,13 @@ +extern bool was_f_in_Bar_destroyed; + +#include "ctor1.h" + +Foo::~Foo() +{ + was_f_in_Bar_destroyed=true; +} + +Bar::~Bar() +{ + throw 1; +} diff --git a/gcc/testsuite/g++.dg/compat/eh/ctor2.h b/gcc/testsuite/g++.dg/compat/eh/ctor2.h new file mode 100644 index 000000000..c6b9f40f8 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/eh/ctor2.h @@ -0,0 +1,22 @@ +struct VBase +{ + virtual void f () {} + VBase(); + ~VBase(); +}; + +struct StreamBase +{ + virtual ~StreamBase() {} +}; + +struct Stream : public virtual VBase, public StreamBase +{ + Stream(); + virtual ~Stream() {} +}; + +struct DerivedStream : public Stream +{ + DerivedStream(); +}; diff --git a/gcc/testsuite/g++.dg/compat/eh/ctor2_main.C b/gcc/testsuite/g++.dg/compat/eh/ctor2_main.C new file mode 100644 index 000000000..58836e26e --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/eh/ctor2_main.C @@ -0,0 +1,12 @@ +// PR c++/4460 +// Test that the cleanup for fully-constructed subobjects when a +// constructor throws gets the right address for a virtual base. + +// Split into pieces for binary compatibility testing October 2002 + +extern void ctor2_x (void); + +int main () +{ + ctor2_x (); +} diff --git a/gcc/testsuite/g++.dg/compat/eh/ctor2_x.C b/gcc/testsuite/g++.dg/compat/eh/ctor2_x.C new file mode 100644 index 000000000..3fa1a53ac --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/eh/ctor2_x.C @@ -0,0 +1,19 @@ +extern "C" void exit (int); +extern "C" void abort (void); + +#include "ctor2.h" + +int r; + +void ctor2_x () { + + try + { + DerivedStream str; + } + catch (...) { } + + if (r != 0) + abort (); + exit (0); +} diff --git a/gcc/testsuite/g++.dg/compat/eh/ctor2_y.C b/gcc/testsuite/g++.dg/compat/eh/ctor2_y.C new file mode 100644 index 000000000..00ba92000 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/eh/ctor2_y.C @@ -0,0 +1,20 @@ +extern int r; +void *p; + +#include "ctor2.h" + +VBase::VBase () +{ + p = this; +} + +VBase::~VBase () +{ + if (p != this) r = 1; +} + +Stream::Stream () {} +DerivedStream::DerivedStream () +{ + throw 1; +} diff --git a/gcc/testsuite/g++.dg/compat/eh/dtor1.h b/gcc/testsuite/g++.dg/compat/eh/dtor1.h new file mode 100644 index 000000000..0dfa793e0 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/eh/dtor1.h @@ -0,0 +1,7 @@ +struct A { + ~A(); +}; + +struct B: public A { + ~B(); +}; diff --git a/gcc/testsuite/g++.dg/compat/eh/dtor1_main.C b/gcc/testsuite/g++.dg/compat/eh/dtor1_main.C new file mode 100644 index 000000000..962fa6427 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/eh/dtor1_main.C @@ -0,0 +1,14 @@ +// PR c++/411 + +// Test that a fully-constructed base is destroyed before transferring +// control to the handler of a function-try-block. + +// Split into pieces for binary compatibility testing October 2002 + +extern void dtor1_x (void); + +int +main () +{ + dtor1_x (); +} diff --git a/gcc/testsuite/g++.dg/compat/eh/dtor1_x.C b/gcc/testsuite/g++.dg/compat/eh/dtor1_x.C new file mode 100644 index 000000000..f7f4cc8a7 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/eh/dtor1_x.C @@ -0,0 +1,14 @@ +extern "C" void exit (int); +extern "C" void abort (void); + +#include "dtor1.h" + +int r; + +void dtor1_x () +{ + { B b; } + if (r != 0) + abort (); + exit (0); +} diff --git a/gcc/testsuite/g++.dg/compat/eh/dtor1_y.C b/gcc/testsuite/g++.dg/compat/eh/dtor1_y.C new file mode 100644 index 000000000..a1ec41a27 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/eh/dtor1_y.C @@ -0,0 +1,18 @@ +extern int r; +int ad; + +#include "dtor1.h" + +A::~A () { ++ad; } + +B::~B () +try + { + throw 1; + } +catch (...) + { + if (!ad) + r = 1; + return; + } diff --git a/gcc/testsuite/g++.dg/compat/eh/filter1.h b/gcc/testsuite/g++.dg/compat/eh/filter1.h new file mode 100644 index 000000000..1f5f0c936 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/eh/filter1.h @@ -0,0 +1,5 @@ +struct a +{ + a(); + ~a(); +}; diff --git a/gcc/testsuite/g++.dg/compat/eh/filter1_main.C b/gcc/testsuite/g++.dg/compat/eh/filter1_main.C new file mode 100644 index 000000000..2a8fca42c --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/eh/filter1_main.C @@ -0,0 +1,11 @@ +// Test that cleanups get run when a catch filter fails to match. + +// Split into pieces for binary compatibility testing October 2002 + +extern void filter1_x (void); + +int +main () +{ + filter1_x (); +} diff --git a/gcc/testsuite/g++.dg/compat/eh/filter1_x.C b/gcc/testsuite/g++.dg/compat/eh/filter1_x.C new file mode 100644 index 000000000..b3789aa15 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/eh/filter1_x.C @@ -0,0 +1,21 @@ +#include "filter1.h" + +extern "C" void exit (int); +extern "C" void abort (void); +extern void ex_test (void); + +void +filter1_x () +{ + try + { + ex_test (); + } + catch (...) + { + } + abort (); +} + +a::a() { } +a::~a() { exit (0); } diff --git a/gcc/testsuite/g++.dg/compat/eh/filter1_y.C b/gcc/testsuite/g++.dg/compat/eh/filter1_y.C new file mode 100644 index 000000000..48de0877d --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/eh/filter1_y.C @@ -0,0 +1,17 @@ +#include "filter1.h" + +struct e1 {}; +struct e2 {}; + +void +ex_test () +{ + a aa; + try + { + throw e1 (); + } + catch (e2 &) + { + } +} diff --git a/gcc/testsuite/g++.dg/compat/eh/filter2_main.C b/gcc/testsuite/g++.dg/compat/eh/filter2_main.C new file mode 100644 index 000000000..866199c6b --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/eh/filter2_main.C @@ -0,0 +1,12 @@ +// Test that terminate gets run when a catch filter fails to match while +// running destructors. Original bug depended on a::~a being inlined. + +// Split into pieces for binary compatibility testing October 2002 + +extern void filter2_x (void); + +int +main () +{ + filter2_x (); +} diff --git a/gcc/testsuite/g++.dg/compat/eh/filter2_x.C b/gcc/testsuite/g++.dg/compat/eh/filter2_x.C new file mode 100644 index 000000000..287ffc7bd --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/eh/filter2_x.C @@ -0,0 +1,22 @@ +#include <exception> +#include <cstdlib> + +extern "C" void abort (void); + +extern void my_terminate (void); +extern void ex_test (void); + +void +filter2_x () +{ + std::set_terminate (my_terminate); + + try + { + ex_test (); + } + catch (...) + { + } + abort (); +} diff --git a/gcc/testsuite/g++.dg/compat/eh/filter2_y.C b/gcc/testsuite/g++.dg/compat/eh/filter2_y.C new file mode 100644 index 000000000..87c6fea10 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/eh/filter2_y.C @@ -0,0 +1,39 @@ +#include <exception> +#include <cstdlib> + +struct e1 {}; +struct e2 {}; + +struct a +{ + a () { } + + ~a () + { + try + { + throw e1(); + } + catch (e2 &) + { + } + } +}; + +void +ex_test () +{ + a aa; + try + { + throw e1 (); + } + catch (e2 &) + { + } +} + +void my_terminate () +{ + std::exit (0); +} diff --git a/gcc/testsuite/g++.dg/compat/eh/new1_main.C b/gcc/testsuite/g++.dg/compat/eh/new1_main.C new file mode 100644 index 000000000..ee4cad8e5 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/eh/new1_main.C @@ -0,0 +1,13 @@ +// PR c++/5757 +// Test that when a constructor throws in a new-expression, we pass the +// right pointer to operator delete. + +// Split into pieces for binary compatibility testing October 2002 + +extern void new1_x (void); + +int +main () +{ + new1_x (); +} diff --git a/gcc/testsuite/g++.dg/compat/eh/new1_x.C b/gcc/testsuite/g++.dg/compat/eh/new1_x.C new file mode 100644 index 000000000..121287170 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/eh/new1_x.C @@ -0,0 +1,29 @@ +#include <new> +#include <cstddef> + +extern "C" void exit (int); +extern "C" void abort (void); + +extern void * operator new[] (std::size_t s) throw (std::bad_alloc); +extern void operator delete[] (void *p) throw (); + +struct A +{ + A() { throw 1; } + ~A() {} +}; + +int ret = 1; + +void +new1_x () +{ + try + { + A *p = new A[4]; + } + catch (...) {} + if (ret != 0) + abort (); + exit (0); +} diff --git a/gcc/testsuite/g++.dg/compat/eh/new1_y.C b/gcc/testsuite/g++.dg/compat/eh/new1_y.C new file mode 100644 index 000000000..fbe0e2145 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/eh/new1_y.C @@ -0,0 +1,19 @@ +#include <new> +#include <cstddef> + +extern int ret; + +void *ptr; +void * operator new[] (std::size_t s) throw (std::bad_alloc) +{ + ptr = operator new (s); + return ptr; +} + +void operator delete[] (void *p) throw () +{ + if (p == ptr) + ret = 0; + operator delete (p); +} + diff --git a/gcc/testsuite/g++.dg/compat/eh/nrv1.h b/gcc/testsuite/g++.dg/compat/eh/nrv1.h new file mode 100644 index 000000000..853ea3914 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/eh/nrv1.h @@ -0,0 +1,5 @@ +struct A +{ + A(); + ~A(); +}; diff --git a/gcc/testsuite/g++.dg/compat/eh/nrv1_main.C b/gcc/testsuite/g++.dg/compat/eh/nrv1_main.C new file mode 100644 index 000000000..3b76b5c88 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/eh/nrv1_main.C @@ -0,0 +1,12 @@ +// PR c++/5636 +// Bug: the named return value optimization interfered with EH cleanups. + +// Split into pieces for binary compatibility testing October 2002 + +extern void nrv1_x (void); + +int +main () +{ + nrv1_x (); +} diff --git a/gcc/testsuite/g++.dg/compat/eh/nrv1_x.C b/gcc/testsuite/g++.dg/compat/eh/nrv1_x.C new file mode 100644 index 000000000..0647de889 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/eh/nrv1_x.C @@ -0,0 +1,21 @@ +extern "C" void exit (int); +extern "C" void abort (void); + +#include "nrv1.h" + +extern A f (void); + +int c, d; + +void nrv1_x () +{ + try + { A a = f(); } + catch (...) { } + if (d < c) + abort (); + exit (0); +} + +A::A() { ++c; } +A::~A() { ++d; } diff --git a/gcc/testsuite/g++.dg/compat/eh/nrv1_y.C b/gcc/testsuite/g++.dg/compat/eh/nrv1_y.C new file mode 100644 index 000000000..5a43af7c2 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/eh/nrv1_y.C @@ -0,0 +1,8 @@ +#include "nrv1.h" + +A f() +{ + A nrv; + throw 42; + return nrv; +} diff --git a/gcc/testsuite/g++.dg/compat/eh/spec3.h b/gcc/testsuite/g++.dg/compat/eh/spec3.h new file mode 100644 index 000000000..a042c1004 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/eh/spec3.h @@ -0,0 +1,8 @@ +class Base {}; + +struct A : virtual public Base +{ + A(); +}; + +struct B {}; diff --git a/gcc/testsuite/g++.dg/compat/eh/spec3_main.C b/gcc/testsuite/g++.dg/compat/eh/spec3_main.C new file mode 100644 index 000000000..3f0e919b2 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/eh/spec3_main.C @@ -0,0 +1,12 @@ +// PR c++/4381 +// Test that exception-specs work properly for classes with virtual bases. + +// Split into pieces for binary compatibility testing October 2002 + +extern void spec3_x (void); + +int +main () +{ + spec3_x (); +} diff --git a/gcc/testsuite/g++.dg/compat/eh/spec3_x.C b/gcc/testsuite/g++.dg/compat/eh/spec3_x.C new file mode 100644 index 000000000..b8e5fbeaa --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/eh/spec3_x.C @@ -0,0 +1,9 @@ +#include "spec3.h" + +extern void func () throw (B,A); + +void spec3_x (void) +{ + try { func(); } + catch (A& a) { } +} diff --git a/gcc/testsuite/g++.dg/compat/eh/spec3_y.C b/gcc/testsuite/g++.dg/compat/eh/spec3_y.C new file mode 100644 index 000000000..fef6b368c --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/eh/spec3_y.C @@ -0,0 +1,8 @@ +#include "spec3.h" + +A::A() {} + +void func() throw (B,A) +{ + throw A(); +} diff --git a/gcc/testsuite/g++.dg/compat/eh/template1.h b/gcc/testsuite/g++.dg/compat/eh/template1.h new file mode 100644 index 000000000..93999a11d --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/eh/template1.h @@ -0,0 +1,15 @@ +class A {}; + +template <class T> +struct B +{ + typedef A E; +}; + +template <class T> +struct C +{ + typedef B<T> D; + typedef typename D::E E; + void f() throw(E); +}; diff --git a/gcc/testsuite/g++.dg/compat/eh/template1_main.C b/gcc/testsuite/g++.dg/compat/eh/template1_main.C new file mode 100644 index 000000000..2d169808c --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/eh/template1_main.C @@ -0,0 +1,12 @@ +// Test whether exception specifier dependent on template parameter +// is accepted during template decl processing. + +// Split into pieces for binary compatibility testing October 2002 + +extern void template1_x (void); + +int +main () +{ + template1_x (); +} diff --git a/gcc/testsuite/g++.dg/compat/eh/template1_x.C b/gcc/testsuite/g++.dg/compat/eh/template1_x.C new file mode 100644 index 000000000..5a18be789 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/eh/template1_x.C @@ -0,0 +1,21 @@ +extern "C" void exit (int); +extern "C" void abort (void); + +#include "template1.h" + +void template1_x () +{ + int caught = 0; + try + { + C<int> x; + x.f(); + } + catch (A) + { + ++caught; + } + if (caught != 1) + abort (); + exit (0); +} diff --git a/gcc/testsuite/g++.dg/compat/eh/template1_y.C b/gcc/testsuite/g++.dg/compat/eh/template1_y.C new file mode 100644 index 000000000..19425375c --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/eh/template1_y.C @@ -0,0 +1,8 @@ +#include "template1.h" + +template<class T> void C<T>::f (void) throw (E) +{ + throw E(); +} + +template class C<int>; diff --git a/gcc/testsuite/g++.dg/compat/eh/unexpected1_main.C b/gcc/testsuite/g++.dg/compat/eh/unexpected1_main.C new file mode 100644 index 000000000..1658db77e --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/eh/unexpected1_main.C @@ -0,0 +1,12 @@ +// PR 3719 +// Test that an unexpected handler can rethrow to categorize. + +// Split into pieces for binary compatibility testing October 2002 + +extern void unexpected1_x (); + +int +main () +{ + unexpected1_x (); +} diff --git a/gcc/testsuite/g++.dg/compat/eh/unexpected1_x.C b/gcc/testsuite/g++.dg/compat/eh/unexpected1_x.C new file mode 100644 index 000000000..61361a68d --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/eh/unexpected1_x.C @@ -0,0 +1,26 @@ +#include <exception> + +struct One { }; +struct Two { }; + +extern "C" void abort (); +extern void doit (void) throw (Two); +extern void handle_unexpected (void); + +void +unexpected1_x () +{ + std::set_unexpected (handle_unexpected); + + try + { + doit (); + } + catch (Two &) + { + } + catch (...) + { + abort (); + } +} diff --git a/gcc/testsuite/g++.dg/compat/eh/unexpected1_y.C b/gcc/testsuite/g++.dg/compat/eh/unexpected1_y.C new file mode 100644 index 000000000..0c42c4579 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/eh/unexpected1_y.C @@ -0,0 +1,21 @@ +struct One { }; +struct Two { }; + +void +handle_unexpected () +{ + try + { + throw; + } + catch (One &) + { + throw Two (); + } +} + +void +doit () throw (Two) +{ + throw One (); +} diff --git a/gcc/testsuite/g++.dg/compat/init/array5_main.C b/gcc/testsuite/g++.dg/compat/init/array5_main.C new file mode 100644 index 000000000..96b2cc4b1 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/init/array5_main.C @@ -0,0 +1,14 @@ +// Copyright (C) 2002 Free Software Foundation +// Contributed by Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net> +// Split into pieces for binary compatibility testing October 2002 + +// Incorrect construction and destruction of multi-dimensional +// array of class. + +extern void array5_x (void); + +int +main () +{ + array5_x (); +} diff --git a/gcc/testsuite/g++.dg/compat/init/array5_x.C b/gcc/testsuite/g++.dg/compat/init/array5_x.C new file mode 100644 index 000000000..dc138772c --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/init/array5_x.C @@ -0,0 +1,33 @@ +extern "C" void abort (void); + +extern int count; +extern int num; + +struct A +{ + A(); + ~A(); +}; + +struct Array +{ + A array[2][2][2]; +}; + +void +array5_x () +{ + for (num = 0; num <= 8; ++num) + { + count = 0; + try + { + Array A; + } + catch (...) + { + } + if (count != 0) + abort(); + } +} diff --git a/gcc/testsuite/g++.dg/compat/init/array5_y.C b/gcc/testsuite/g++.dg/compat/init/array5_y.C new file mode 100644 index 000000000..64b295ed5 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/init/array5_y.C @@ -0,0 +1,20 @@ +int count; +int num; + +struct A +{ + A(); + ~A(); +}; + +A::A() +{ + if (count == num) + throw ""; + count++; +} + +A::~A() +{ + count--; +} diff --git a/gcc/testsuite/g++.dg/compat/init/byval1.h b/gcc/testsuite/g++.dg/compat/init/byval1.h new file mode 100644 index 000000000..2876b76ed --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/init/byval1.h @@ -0,0 +1,6 @@ +struct C +{ + int m; + C(); + ~C(); +}; diff --git a/gcc/testsuite/g++.dg/compat/init/byval1_main.C b/gcc/testsuite/g++.dg/compat/init/byval1_main.C new file mode 100644 index 000000000..acefaab14 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/init/byval1_main.C @@ -0,0 +1,12 @@ +// PR c++/3948 +// Test that the destructor call for a value parameter gets the +// right address. +// Split into pieces for binary compatibility testing October 2002 + +extern void byval1_x (void); + +int +main () +{ + byval1_x (); +} diff --git a/gcc/testsuite/g++.dg/compat/init/byval1_x.C b/gcc/testsuite/g++.dg/compat/init/byval1_x.C new file mode 100644 index 000000000..248dbe763 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/init/byval1_x.C @@ -0,0 +1,15 @@ +#include "byval1.h" + +extern "C" void abort (void); +extern void Foo (C c); +extern int r; + +void +byval1_x () +{ + C c; + + Foo (c); + if (r != 0) + abort (); +} diff --git a/gcc/testsuite/g++.dg/compat/init/byval1_y.C b/gcc/testsuite/g++.dg/compat/init/byval1_y.C new file mode 100644 index 000000000..6e217e84e --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/init/byval1_y.C @@ -0,0 +1,14 @@ +#include "byval1.h" + +void *p[2]; + +int i; +int r; + +C::C() { p[i++] = this; } +C::~C() { if (p[--i] != this) r = 1; } + +void Foo (C c) +{ + p[i++] = &c; +} diff --git a/gcc/testsuite/g++.dg/compat/init/dtor1.h b/gcc/testsuite/g++.dg/compat/init/dtor1.h new file mode 100644 index 000000000..77e21c12e --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/init/dtor1.h @@ -0,0 +1,30 @@ +struct B +{ + int x; + B (int); + ~B (); +}; + +struct C1 : public B { + C1 (int); +}; + +struct C2 : public B { + C2 (int); +}; + +struct D : public B { + D (int); +}; + +struct E : public B { + E (int); +}; + +struct A + : public C1, C2, virtual public D, virtual public E +{ + A (); + B x1; + B x2; +}; diff --git a/gcc/testsuite/g++.dg/compat/init/dtor1_main.C b/gcc/testsuite/g++.dg/compat/init/dtor1_main.C new file mode 100644 index 000000000..788687840 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/init/dtor1_main.C @@ -0,0 +1,9 @@ +// Split into pieces for binary compatibility testing October 2002 + +extern void dtor1_x (void); + +int +main () +{ + dtor1_x (); +} diff --git a/gcc/testsuite/g++.dg/compat/init/dtor1_x.C b/gcc/testsuite/g++.dg/compat/init/dtor1_x.C new file mode 100644 index 000000000..8a4727cfb --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/init/dtor1_x.C @@ -0,0 +1,7 @@ +#include "dtor1.h" + +void +dtor1_x (void) +{ + A a; +} diff --git a/gcc/testsuite/g++.dg/compat/init/dtor1_y.C b/gcc/testsuite/g++.dg/compat/init/dtor1_y.C new file mode 100644 index 000000000..27610fc1e --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/init/dtor1_y.C @@ -0,0 +1,18 @@ +#include "dtor1.h" + +extern "C" void abort (); + +int d = 5; + +B::B (int i) : x (i) { } +B::~B () { if (d-- != x) abort (); } + +C1::C1 (int i) : B (i) {} + +C2::C2 (int i) : B (i) {} + +D::D (int i) : B (i) {} + +E::E (int i) : B (i) {} + +A::A () : D (0), E (1), C1 (2), C2 (3), x1(4), x2(5) {} diff --git a/gcc/testsuite/g++.dg/compat/init/elide1.h b/gcc/testsuite/g++.dg/compat/init/elide1.h new file mode 100644 index 000000000..481e7308b --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/init/elide1.h @@ -0,0 +1,5 @@ +struct A { + A (); + A (const A&); + ~A (); +}; diff --git a/gcc/testsuite/g++.dg/compat/init/elide1_main.C b/gcc/testsuite/g++.dg/compat/init/elide1_main.C new file mode 100644 index 000000000..c08d02fff --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/init/elide1_main.C @@ -0,0 +1,25 @@ +// Test that the destructor for a temporary passed by value isn't run +// until end of full-expression, as per [class.copy]: + +// Whenever a temporary class object is copied using a copy constructor, +// and this object and the copy have the same cv-unqualified type, an +// implementation is permitted to treat the original and the copy as two +// different ways of referring to the same object and not perform a copy +// at all, even if the class copy constructor or destructor have side +// effects.... In these cases, the +// object is destroyed at the later of times when the original and the +// copy would have been destroyed without the optimization. + +// Here, the temporary would be destroyed later than the parm, so either we +// must suppress the optimization in this case or destroy value parms in the +// caller. + +// Split into pieces for binary compatibility testing October 2002 + +extern void elide1_x (void); + +int +main () +{ + elide1_x (); +} diff --git a/gcc/testsuite/g++.dg/compat/init/elide1_x.C b/gcc/testsuite/g++.dg/compat/init/elide1_x.C new file mode 100644 index 000000000..dbc287e4e --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/init/elide1_x.C @@ -0,0 +1,15 @@ +#include "elide1.h" + +extern "C" void abort (void); +extern void f (A); +extern int d; + +void +elide1_x (void) +{ + int r; + f (A ()), r = d; + + if (r >= d || !d) + abort (); +} diff --git a/gcc/testsuite/g++.dg/compat/init/elide1_y.C b/gcc/testsuite/g++.dg/compat/init/elide1_y.C new file mode 100644 index 000000000..e767d0808 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/init/elide1_y.C @@ -0,0 +1,9 @@ +#include "elide1.h" + +int d; + +A::A () { } +A::A (const A&) { } +A::~A() { ++d; } + +void f (A a) { } diff --git a/gcc/testsuite/g++.dg/compat/init/init-ref2_main.C b/gcc/testsuite/g++.dg/compat/init/init-ref2_main.C new file mode 100644 index 000000000..73782829e --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/init/init-ref2_main.C @@ -0,0 +1,11 @@ +// Submitted by Jason Merrill <jason_merrill@redhat.com> +// Test for proper handling of local static references. +// Split into pieces for binary compatibility testing October 2002 + +extern void init_ref2_x (void); + +int +main () +{ + init_ref2_x (); +} diff --git a/gcc/testsuite/g++.dg/compat/init/init-ref2_x.C b/gcc/testsuite/g++.dg/compat/init/init-ref2_x.C new file mode 100644 index 000000000..7fbec89b6 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/init/init-ref2_x.C @@ -0,0 +1,22 @@ +extern "C" void abort (void); +extern void g (void); +extern void h (void); + +int r; +int c; +int f () +{ + // Test that we only initialize i once. + if (++c > 1) + ++r; + return 42; +} + +void +init_ref2_x (void) +{ + g (); + h (); + if (r != 0) + abort (); +} diff --git a/gcc/testsuite/g++.dg/compat/init/init-ref2_y.C b/gcc/testsuite/g++.dg/compat/init/init-ref2_y.C new file mode 100644 index 000000000..23e66b2f9 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/init/init-ref2_y.C @@ -0,0 +1,24 @@ +extern int f (void); +extern int r; + +const int *p; + +void g () +{ + static const int &i = f(); + + // Test that i points to the same place in both calls. + if (p && p != &i) + ++r; + // Test that if so, it points to static data. + if (i != 42) + ++r; + + p = &i; +} + +void h () +{ + int arr[] = { 1, 1, 1, 1, 1, 1, 1 }; + g (); +} diff --git a/gcc/testsuite/g++.dg/compat/struct-layout-1.exp b/gcc/testsuite/g++.dg/compat/struct-layout-1.exp new file mode 100644 index 000000000..7fa89470e --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/struct-layout-1.exp @@ -0,0 +1,167 @@ +# Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008 +# Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GCC; see the file COPYING3. If not see +# <http://www.gnu.org/licenses/>. +# +# This file was written by Jakub Jelinek, <jakub@redhat.com> +# Based on compat.exp writte by Janis Johnson, <janis187@us.ibm.com> + + +# Test interoperability of two compilers that follow the same ABI. +# +# Break simple tests into two pieces and see that they work when linked +# together. If an alternate compiler is specified then the two main +# pieces of each test are compiled with different compilers. The +# alternate compiler must be installed, and is specified by defining +# ALT_CXX_UNDER_TEST in the environment. +# +# struct-layout-1 are generated structure layout interoperability tests, +# so a generator first needs to be compiled on host, run there and the +# generated tests then compiled on build and executed on target. + +if $tracelevel then { + strace $tracelevel +} + +global GXX_UNDER_TEST +global ld_library_path + +# Load procedures from common libraries. +load_lib standard.exp +load_lib g++.exp +load_lib target-libpath.exp + +# +# compat-use-alt-compiler -- make the alternate compiler the default +# +proc compat-use-alt-compiler { } { + global GXX_UNDER_TEST ALT_CXX_UNDER_TEST + global CXXFLAGS + global ALWAYS_CXXFLAGS + global ld_library_path alt_ld_library_path + global same_alt + + # We don't need to do this if the alternate compiler is actually + # the same as the compiler under test. + if { $same_alt == 0 } then { + set GXX_UNDER_TEST $ALT_CXX_UNDER_TEST + set CXXFLAGS "" + set ALWAYS_CXXFLAGS "" + set ld_library_path $alt_ld_library_path + set_ld_library_path_env_vars + } +} + +# +# compat-use-tst-compiler -- make compiler under test the default +# +proc compat-use-tst-compiler { } { + global GXX_UNDER_TEST save_gxx_under_test + global CXXFLAGS save_cxxflags + global ALWAYS_CXXFLAGS save_always_cxxflags + global ld_library_path save_ld_library_path + global same_alt + + # We don't need to do this if the alternate compiler is actually + # the same as the compiler under test. + + if { $same_alt == 0 } then { + set GXX_UNDER_TEST $save_gxx_under_test + set CXXFLAGS $save_cxxflags + set ALWAYS_CXXFLAGS $save_always_cxxflags + set ld_library_path $save_ld_library_path + set_ld_library_path_env_vars + } +} + +# Load the language-independent compabibility support procedures. +# This must be done after the compat-use-*-compiler definitions. +load_lib compat.exp + +g++_init + +# Save variables for the C++ compiler under test, which each test will +# change a couple of times. This must be done after calling g++-init. +set save_gxx_under_test $GXX_UNDER_TEST +set save_cxxflags $CXXFLAGS +set save_always_cxxflags $ALWAYS_CXXFLAGS +set save_ld_library_path $ld_library_path + +# Define an identifier for use with this suite to avoid name conflicts +# with other compat tests running at the same time. +set sid "cp_compat" + +# Find out whether there is an alternate compiler to test. If the +# variable is defined but is set to "same", that means we use the same +# compiler twice, which is meaningful if the two parts of COMPAT_OPTIONS +# are different. +set use_alt 0 +set same_alt 0 +set alt_ld_library_path "." +if [info exists ALT_CXX_UNDER_TEST] then { + set use_alt 1 + if [string match "same" $ALT_CXX_UNDER_TEST] then { + set same_alt 1 + } else { + if [info exists ALT_LD_LIBRARY_PATH] then { + append alt_ld_library_path ":${ALT_LD_LIBRARY_PATH}" + } + } +} + +set tstobjdir "$tmpdir/g++.dg-struct-layout-1" +set generator "$tmpdir/g++.dg-struct-layout-1_generate.exe" + +set generator_src "$srcdir/$subdir/struct-layout-1_generate.c" +set generator_src "$generator_src $srcdir/$subdir/../../gcc.dg/compat/generate-random.c" +set generator_src "$generator_src $srcdir/$subdir/../../gcc.dg/compat/generate-random_r.c" +set generator_cmd "-o $generator $generator_src" + +# Temporarily switch to the environment of the host compiler. +restore_ld_library_path_env_vars +set status [remote_exec build "$HOSTCC $HOSTCFLAGS $generator_cmd"] +set status [lindex $status 0] +set_ld_library_path_env_vars +if { $status == 0 } then { + file delete -force $tstobjdir + file mkdir $tstobjdir + set generator_args "-s $srcdir/$subdir -d $tstobjdir" + if [info exists env(RUN_ALL_COMPAT_TESTS) ] then { + set generator_args "$generator_args -n 15000" + } + if [check_effective_target_short_enums] then { + set generator_args "-e $generator_args" + } + set status [remote_exec host "$generator $generator_args"] + set status [lindex $status 0] + if { $status == 0 } then { + foreach src [lsort [find $tstobjdir *_main.C]] { + # If we're only testing specific files and this isn't one + # of them, skip it. + if ![runtest_file_p $runtests $src] then { + continue + } + + compat-execute $src $sid $use_alt + } + } else { + warning "Could not execute g++.dg/compat/struct-layout-1 generator" + } +} else { + warning "Could not compile g++.dg/compat/struct-layout-1 generator" +} + +# Restore the original compiler under test. +compat-use-tst-compiler diff --git a/gcc/testsuite/g++.dg/compat/struct-layout-1.h b/gcc/testsuite/g++.dg/compat/struct-layout-1.h new file mode 100644 index 000000000..2b93a72c4 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/struct-layout-1.h @@ -0,0 +1,502 @@ +#include <limits.h> +#include <stdarg.h> +#include <stdbool.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include "../../gcc.dg/compat/compat-common.h" + +#ifndef SKIP_ATTRIBUTE +# include "../../gcc.dg/compat/vector-defs.h" +#else +typedef int qi; +typedef int hi; +typedef int si; +typedef int di; +typedef float sf; +typedef float df; +typedef int v8qi; +typedef int v16qi; +typedef int v2hi; +typedef int v4hi; +typedef int v8hi; +typedef int v2si; +typedef int v4si; +typedef int v1di; +typedef int v2di; +typedef int v2sf; +typedef int v4sf; +typedef int v16sf; +typedef int v2df; +typedef int u8qi; +typedef int u16qi; +typedef int u2hi; +typedef int u4hi; +typedef int u8hi; +typedef int u2si; +typedef int u4si; +typedef int u1di; +typedef int u2di; +typedef int u2sf; +typedef int u4sf; +typedef int u16sf; +typedef int u2df; +#endif +#if (defined __i386__ || defined __x86_64__) && !defined SKIP_ATTRIBUTE +# ifdef __MMX__ +typedef int __m64 __attribute__ ((__vector_size__ (8))); +# else +typedef int __m64; +# endif +# ifdef __SSE__ +typedef float __m128 __attribute__ ((__vector_size__ (16))); +# else +typedef int __m128; +# endif +#else +typedef int __m64; +typedef int __m128; +#endif +#if defined (__uClinux__) +/* The maximum achievable alignment on uClinux is usually 16 bytes. */ +#define v16sf v4sf +#define u16sf u4sf +#endif + +#define FLDS_MAX 32 +extern struct Info +{ + int nfields, nbitfields; + void *sp, *a0p, *a3p; + void *flds[FLDS_MAX]; + size_t sz, sizes[FLDS_MAX]; + size_t als, ala0, ala3, aligns[FLDS_MAX]; +} info; + +extern int intarray[256]; +extern int fn0 (void), fn1 (void), fn2 (void), fn3 (void), fn4 (void); +extern int fn5 (void), fn6 (void), fn7 (void), fn8 (void), fn9 (void); + +#ifdef DBG +#define FAIL(n, m) printf ("fail %d.%d\n", n, m), ++fails +#else +#define FAIL(n, m) ++fails +#endif + +#ifdef SKIP_ATTRIBUTE +# define __attribute__(x) +#endif +#define atal __attribute__((aligned)) +#define atpa __attribute__((packed)) +#define atalpa __attribute__((aligned, packed)) +#define atpaal __attribute__((packed, aligned)) +#define atal1 __attribute__((aligned (1))) +#define atal2 __attribute__((aligned (2))) +#define atal4 __attribute__((aligned (4))) +#define atal8 __attribute__((aligned (8))) +#define atal16 __attribute__((aligned (16))) +#define atal1pa __attribute__((aligned (1), packed)) +#define atal2pa __attribute__((aligned (2), packed)) +#define atal4pa __attribute__((aligned (4), packed)) +#define atal8pa __attribute__((aligned (8), packed)) +#define atal16pa __attribute__((aligned (16), packed)) +#define atpaal1 __attribute__((packed, aligned (1))) +#define atpaal2 __attribute__((packed, aligned (2))) +#define atpaal4 __attribute__((packed, aligned (4))) +#define atpaal8 __attribute__((packed, aligned (8))) +#define atpaal16 __attribute__((packed, aligned (16))) + +#if UCHAR_MAX == 255 && USHORT_MAX == 65535 && UINT_MAX == 4294967295U \ + && ULLONG_MAX == 18446744073709551615ULL +/* For ILP32 and LP64 targets, assume float is at least 32-bit + and double plus long double at least 64-bit. */ +# define atalx1 atal1 +# define atalx2 atal2 +# define atalx4 atal4 +# define atalx8 atal8 +# define atalx16 atal16 +# define atalx1pa atal1pa +# define atalx2pa atal2pa +# define atalx4pa atal4pa +# define atalx8pa atal8pa +# define atalx16pa atal16pa +# define atpaalx1 atpaal1 +# define atpaalx2 atpaal2 +# define atpaalx4 atpaal4 +# define atpaalx8 atpaal8 +# define atpaalx16 atpaal16 +# if ULONG_MAX > 4294967295UL +# define ataly8 atal8 +# define ataly8pa atal8pa +# define atpaaly8 atpaal8 +# define ataly16 atal16 +# define ataly16pa atal16pa +# define atpaaly16 atpaal16 +# else +# define ataly8 +# define ataly8pa +# define atpaaly8 +# define ataly16 +# define ataly16pa +# define atpaaly16 +# endif +#else +# define atalx1 +# define atalx2 +# define atalx4 +# define atalx8 +# define atalx16 +# define atalx1pa +# define atalx2pa +# define atalx4pa +# define atalx8pa +# define atalx16pa +# define atpaalx1 +# define atpaalx2 +# define atpaalx4 +# define atpaalx8 +# define atpaalx16 +# define ataly8 +# define ataly8pa +# define atpaaly8 +# define ataly16 +# define ataly16pa +# define atpaaly16 +#endif + +#define atQI __attribute__((mode (QI))) +#define atHI __attribute__((mode (HI))) +#define atSI __attribute__((mode (SI))) +#define atDI __attribute__((mode (DI))) + +enum E0 { e0_0 }; +enum E1 { e1_0, e1_1 }; +enum E2 { e2_m3 = -3, e2_m2, e2_m1, e2_0, e2_1, e2_2, e2_3 }; +enum E3 { e3_m127 = -127, e3_m126, e3_m125, e3_0 = 0, e3_125 = 125, e3_126, e3_127 }; +enum E4 { e4_0, e4_1, e4_2, e4_3, e4_253 = 253, e4_254, e4_255 }; +enum E5 { e5_m32767 = -32767, e5_m32766, e5_m32765, e5_0 = 0, e5_32765 = 32765, e5_32766, e5_32767 }; +enum E6 { e6_0, e6_1, e6_2, e6_3, e6_65533 = 65533, e6_65534, e6_65535 }; +enum E7 { e7_m2147483647 = -2147483647, e7_m2147483646, e7_m2147483645, + e7_0, e7_2147483645 = 2147483645, e7_2147483646, e7_2147483647 }; +enum E8 { e8_0, e8_1, e8_2, e8_3, e8_4294967293 = 4294967293U, e8_4294967294, e8_4294967295 }; +enum E9 { e9_m1099511627775 = -1099511627775LL, e9_m1099511627774, e9_m1099511627773, + e9_0, e9_1099511627773 = 1099511627773LL, e9_1099511627774, e9_1099511627775 }; + +typedef char Tchar; +typedef signed char Tschar; +typedef unsigned char Tuchar; +typedef short int Tshort; +typedef unsigned short int Tushort; +typedef int Tint; +typedef unsigned int Tuint; +typedef long int Tlong; +typedef unsigned long int Tulong; +typedef long long int Tllong; +typedef unsigned long long int Tullong; +typedef float Tfloat; +typedef double Tdouble; +typedef long double Tldouble; +typedef _Complex float Tcfloat; +typedef _Complex double Tcdouble; +typedef _Complex long double Tcldouble; +typedef bool Tbool; +typedef enum E0 TE0; +typedef enum E1 TE1; +typedef enum E2 TE2; +typedef enum E3 TE3; +typedef enum E4 TE4; +typedef enum E5 TE5; +typedef enum E6 TE6; +typedef enum E7 TE7; +typedef enum E8 TE8; +typedef enum E9 TE9; +typedef void *Tptr; +typedef char *Tcptr; +typedef int *Tiptr; +typedef char Talchar atal; +typedef signed char Talschar atal; +typedef unsigned char Taluchar atal; +typedef short int Talshort atal; +typedef unsigned short int Talushort atal; +typedef int Talint atal; +typedef unsigned int Taluint atal; +typedef long int Tallong atal; +typedef unsigned long int Talulong atal; +typedef long long int Talllong atal; +typedef unsigned long long int Talullong atal; +typedef float Talfloat atal; +typedef double Taldouble atal; +typedef long double Talldouble atal; +typedef _Complex float Talcfloat atal; +typedef _Complex double Talcdouble atal; +typedef _Complex long double Talcldouble atal; +typedef bool Talbool atal; +typedef enum E0 TalE0 atal; +typedef enum E1 TalE1 atal; +typedef enum E2 TalE2 atal; +typedef enum E3 TalE3 atal; +typedef enum E4 TalE4 atal; +typedef enum E5 TalE5 atal; +typedef enum E6 TalE6 atal; +typedef enum E7 TalE7 atal; +typedef enum E8 TalE8 atal; +typedef enum E9 TalE9 atal; +typedef void *Talptr atal; +typedef char *Talcptr atal; +typedef int *Taliptr atal; +typedef char Tal1char atal1; +typedef signed char Tal1schar atal1; +typedef unsigned char Tal1uchar atal1; +typedef short int Tal1short atal1; +typedef unsigned short int Tal1ushort atal1; +typedef int Tal1int atal1; +typedef unsigned int Tal1uint atal1; +typedef long int Tal1long atal1; +typedef unsigned long int Tal1ulong atal1; +typedef long long int Tal1llong atal1; +typedef unsigned long long int Tal1ullong atal1; +typedef float Tal1float atal1; +typedef double Tal1double atal1; +typedef long double Tal1ldouble atal1; +typedef _Complex float Tal1cfloat atal1; +typedef _Complex double Tal1cdouble atal1; +typedef _Complex long double Tal1cldouble atal1; +typedef bool Tal1bool atal1; +typedef enum E0 Tal1E0 atal1; +typedef enum E1 Tal1E1 atal1; +typedef enum E2 Tal1E2 atal1; +typedef enum E3 Tal1E3 atal1; +typedef enum E4 Tal1E4 atal1; +typedef enum E5 Tal1E5 atal1; +typedef enum E6 Tal1E6 atal1; +typedef enum E7 Tal1E7 atal1; +typedef enum E8 Tal1E8 atal1; +typedef enum E9 Tal1E9 atal1; +typedef void *Tal1ptr atal1; +typedef char *Tal1cptr atal1; +typedef int *Tal1iptr atal1; +typedef char Tal2char atal2; +typedef signed char Tal2schar atal2; +typedef unsigned char Tal2uchar atal2; +typedef short int Tal2short atal2; +typedef unsigned short int Tal2ushort atal2; +typedef int Tal2int atal2; +typedef unsigned int Tal2uint atal2; +typedef long int Tal2long atal2; +typedef unsigned long int Tal2ulong atal2; +typedef long long int Tal2llong atal2; +typedef unsigned long long int Tal2ullong atal2; +typedef float Tal2float atal2; +typedef double Tal2double atal2; +typedef long double Tal2ldouble atal2; +typedef _Complex float Tal2cfloat atal2; +typedef _Complex double Tal2cdouble atal2; +typedef _Complex long double Tal2cldouble atal2; +typedef bool Tal2bool atal2; +typedef enum E0 Tal2E0 atal2; +typedef enum E1 Tal2E1 atal2; +typedef enum E2 Tal2E2 atal2; +typedef enum E3 Tal2E3 atal2; +typedef enum E4 Tal2E4 atal2; +typedef enum E5 Tal2E5 atal2; +typedef enum E6 Tal2E6 atal2; +typedef enum E7 Tal2E7 atal2; +typedef enum E8 Tal2E8 atal2; +typedef enum E9 Tal2E9 atal2; +typedef void *Tal2ptr atal2; +typedef char *Tal2cptr atal2; +typedef int *Tal2iptr atal2; +typedef char Tal4char atal4; +typedef signed char Tal4schar atal4; +typedef unsigned char Tal4uchar atal4; +typedef short int Tal4short atal4; +typedef unsigned short int Tal4ushort atal4; +typedef int Tal4int atal4; +typedef unsigned int Tal4uint atal4; +typedef long int Tal4long atal4; +typedef unsigned long int Tal4ulong atal4; +typedef long long int Tal4llong atal4; +typedef unsigned long long int Tal4ullong atal4; +typedef float Tal4float atal4; +typedef double Tal4double atal4; +typedef long double Tal4ldouble atal4; +typedef _Complex float Tal4cfloat atal4; +typedef _Complex double Tal4cdouble atal4; +typedef _Complex long double Tal4cldouble atal4; +typedef bool Tal4bool atal4; +typedef enum E0 Tal4E0 atal4; +typedef enum E1 Tal4E1 atal4; +typedef enum E2 Tal4E2 atal4; +typedef enum E3 Tal4E3 atal4; +typedef enum E4 Tal4E4 atal4; +typedef enum E5 Tal4E5 atal4; +typedef enum E6 Tal4E6 atal4; +typedef enum E7 Tal4E7 atal4; +typedef enum E8 Tal4E8 atal4; +typedef enum E9 Tal4E9 atal4; +typedef void *Tal4ptr atal4; +typedef char *Tal4cptr atal4; +typedef int *Tal4iptr atal4; +typedef char Tal8char atal8; +typedef signed char Tal8schar atal8; +typedef unsigned char Tal8uchar atal8; +typedef short int Tal8short atal8; +typedef unsigned short int Tal8ushort atal8; +typedef int Tal8int atal8; +typedef unsigned int Tal8uint atal8; +typedef long int Tal8long atal8; +typedef unsigned long int Tal8ulong atal8; +typedef long long int Tal8llong atal8; +typedef unsigned long long int Tal8ullong atal8; +typedef float Tal8float atal8; +typedef double Tal8double atal8; +typedef long double Tal8ldouble atal8; +typedef _Complex float Tal8cfloat atal8; +typedef _Complex double Tal8cdouble atal8; +typedef _Complex long double Tal8cldouble atal8; +typedef bool Tal8bool atal8; +typedef enum E0 Tal8E0 atal8; +typedef enum E1 Tal8E1 atal8; +typedef enum E2 Tal8E2 atal8; +typedef enum E3 Tal8E3 atal8; +typedef enum E4 Tal8E4 atal8; +typedef enum E5 Tal8E5 atal8; +typedef enum E6 Tal8E6 atal8; +typedef enum E7 Tal8E7 atal8; +typedef enum E8 Tal8E8 atal8; +typedef enum E9 Tal8E9 atal8; +typedef void *Tal8ptr atal8; +typedef char *Tal8cptr atal8; +typedef int *Tal8iptr atal8; +typedef char Tal16char atal16; +typedef signed char Tal16schar atal16; +typedef unsigned char Tal16uchar atal16; +typedef short int Tal16short atal16; +typedef unsigned short int Tal16ushort atal16; +typedef int Tal16int atal16; +typedef unsigned int Tal16uint atal16; +typedef long int Tal16long atal16; +typedef unsigned long int Tal16ulong atal16; +typedef long long int Tal16llong atal16; +typedef unsigned long long int Tal16ullong atal16; +typedef float Tal16float atal16; +typedef double Tal16double atal16; +typedef long double Tal16ldouble atal16; +typedef _Complex float Tal16cfloat atal16; +typedef _Complex double Tal16cdouble atal16; +typedef _Complex long double Tal16cldouble atal16; +typedef bool Tal16bool atal16; +typedef enum E0 Tal16E0 atal16; +typedef enum E1 Tal16E1 atal16; +typedef enum E2 Tal16E2 atal16; +typedef enum E3 Tal16E3 atal16; +typedef enum E4 Tal16E4 atal16; +typedef enum E5 Tal16E5 atal16; +typedef enum E6 Tal16E6 atal16; +typedef enum E7 Tal16E7 atal16; +typedef enum E8 Tal16E8 atal16; +typedef enum E9 Tal16E9 atal16; +typedef void *Tal16ptr atal16; +typedef char *Tal16cptr atal16; +typedef int *Tal16iptr atal16; +typedef char Talx1char atalx1; +typedef signed char Talx1schar atalx1; +typedef unsigned char Talx1uchar atalx1; +typedef short int Talx1short atalx1; +typedef unsigned short int Talx1ushort atalx1; +typedef int Talx1int atalx1; +typedef unsigned int Talx1uint atalx1; +typedef long int Talx1long atalx1; +typedef unsigned long int Talx1ulong atalx1; +typedef long long int Talx1llong atalx1; +typedef unsigned long long int Talx1ullong atalx1; +typedef float Talx1float atalx1; +typedef double Talx1double atalx1; +typedef long double Talx1ldouble atalx1; +typedef _Complex float Talx1cfloat atalx1; +typedef _Complex double Talx1cdouble atalx1; +typedef _Complex long double Talx1cldouble atalx1; +typedef bool Talx1bool atalx1; +typedef enum E0 Talx1E0 atalx1; +typedef enum E1 Talx1E1 atalx1; +typedef enum E2 Talx1E2 atalx1; +typedef enum E3 Talx1E3 atalx1; +typedef enum E4 Talx1E4 atalx1; +typedef enum E5 Talx1E5 atalx1; +typedef enum E6 Talx1E6 atalx1; +typedef enum E7 Talx1E7 atalx1; +typedef enum E8 Talx1E8 atalx1; +typedef enum E9 Talx1E9 atalx1; +typedef void *Talx1ptr atalx1; +typedef char *Talx1cptr atalx1; +typedef int *Talx1iptr atalx1; +typedef short int Talx2short atalx2; +typedef unsigned short int Talx2ushort atalx2; +typedef int Talx2int atalx2; +typedef unsigned int Talx2uint atalx2; +typedef long int Talx2long atalx2; +typedef unsigned long int Talx2ulong atalx2; +typedef long long int Talx2llong atalx2; +typedef unsigned long long int Talx2ullong atalx2; +typedef float Talx2float atalx2; +typedef double Talx2double atalx2; +typedef long double Talx2ldouble atalx2; +typedef _Complex float Talx2cfloat atalx2; +typedef _Complex double Talx2cdouble atalx2; +typedef _Complex long double Talx2cldouble atalx2; +typedef enum E0 Talx2E0 atalx2; +typedef enum E1 Talx2E1 atalx2; +typedef enum E2 Talx2E2 atalx2; +typedef enum E3 Talx2E3 atalx2; +typedef enum E4 Talx2E4 atalx2; +typedef enum E5 Talx2E5 atalx2; +typedef enum E6 Talx2E6 atalx2; +typedef enum E7 Talx2E7 atalx2; +typedef enum E8 Talx2E8 atalx2; +typedef enum E9 Talx2E9 atalx2; +typedef void *Talx2ptr atalx2; +typedef char *Talx2cptr atalx2; +typedef int *Talx2iptr atalx2; +typedef int Talx4int atalx4; +typedef unsigned int Talx4uint atalx4; +typedef long int Talx4long atalx4; +typedef unsigned long int Talx4ulong atalx4; +typedef long long int Talx4llong atalx4; +typedef unsigned long long int Talx4ullong atalx4; +typedef float Talx4float atalx4; +typedef double Talx4double atalx4; +typedef long double Talx4ldouble atalx4; +typedef _Complex float Talx4cfloat atalx4; +typedef _Complex double Talx4cdouble atalx4; +typedef _Complex long double Talx4cldouble atalx4; +typedef enum E0 Talx4E0 atalx4; +typedef enum E1 Talx4E1 atalx4; +typedef enum E2 Talx4E2 atalx4; +typedef enum E3 Talx4E3 atalx4; +typedef enum E4 Talx4E4 atalx4; +typedef enum E5 Talx4E5 atalx4; +typedef enum E6 Talx4E6 atalx4; +typedef enum E7 Talx4E7 atalx4; +typedef enum E8 Talx4E8 atalx4; +typedef enum E9 Talx4E9 atalx4; +typedef void *Talx4ptr atalx4; +typedef char *Talx4cptr atalx4; +typedef int *Talx4iptr atalx4; +typedef long int Taly8long ataly8; +typedef unsigned long int Taly8ulong ataly8; +typedef long long int Talx8llong atalx8; +typedef unsigned long long int Talx8ullong atalx8; +typedef double Talx8double atalx8; +typedef long double Talx8ldouble atalx8; +typedef _Complex float Talx8cfloat atalx8; +typedef _Complex double Talx8cdouble atalx8; +typedef _Complex long double Talx8cldouble atalx8; +typedef void *Taly8ptr ataly8; +typedef char *Taly8cptr ataly8; +typedef int *Taly8iptr ataly8; +typedef _Complex double Talx16cdouble atalx16; +typedef _Complex long double Talx16cldouble atalx16; +typedef int (*Tfnptr) (void); + +#define T(n, fields, ops) TX(n, struct, , fields, ({ ops });) +#define U(n, fields, ops) TX(n, union, , fields, ({ ops });) diff --git a/gcc/testsuite/g++.dg/compat/struct-layout-1_generate.c b/gcc/testsuite/g++.dg/compat/struct-layout-1_generate.c new file mode 100644 index 000000000..b6846a918 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/struct-layout-1_generate.c @@ -0,0 +1,1665 @@ +/* Structure layout test generator. + Copyright (C) 2004, 2005, 2007, 2008, 2009 Free Software Foundation, Inc. + Contributed by Jakub Jelinek <jakub@redhat.com>. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +<http://www.gnu.org/licenses/>. */ + + +/* Compile with gcc -o struct-layout-1_generate{,.c} generate_random{,_r}.c */ + +/* N.B. -- This program cannot use libiberty as that will not work + when testing an installed compiler. */ +#include <limits.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <stddef.h> +/* We use our own pseudo-random number generator, so that it gives the same + values on all hosts. */ +#include "../../gcc.dg/compat/generate-random.h" + +#if LLONG_MAX != 9223372036854775807LL && __LONG_LONG_MAX__ != 9223372036854775807LL +# error Need 64-bit long long +#endif + +#if defined __MSVCRT__ +#define COMPAT_PRLL "I64" +#else +#define COMPAT_PRLL "ll" +#endif + +const char *dg_options[] = { +"/* { dg-options \"%s-I%s\" } */\n", +"/* { dg-options \"%s-I%s -mno-mmx -Wno-abi\" { target i?86-*-* x86_64-*-* } } */\n", +"/* { dg-options \"%s-I%s -fno-common\" { target hppa*-*-hpux* powerpc*-*-darwin* *-*-mingw32* *-*-cygwin* } } */\n", +"/* { dg-options \"%s-I%s -mno-mmx -fno-common -Wno-abi\" { target i?86-*-darwin* x86_64-*-darwin* } } */\n", +"/* { dg-options \"%s-I%s -mno-base-addresses\" { target mmix-*-* } } */\n", +"/* { dg-options \"%s-I%s -mlongcalls -mtext-section-literals\" { target xtensa*-*-* } } */\n" +#define NDG_OPTIONS (sizeof (dg_options) / sizeof (dg_options[0])) +}; + +typedef unsigned int hashval_t; + +enum TYPE +{ + TYPE_INT, + TYPE_UINT, + TYPE_FLOAT, + TYPE_SENUM, + TYPE_UENUM, + TYPE_PTR, + TYPE_FNPTR, + TYPE_OTHER +}; + +struct types +{ + const char *name; + enum TYPE type; + unsigned long long int maxval; + char bitfld; +}; + +struct types base_types[] = { +/* As we don't know whether char will be signed or not, just limit ourselves + to unsigned values less than maximum signed char value. */ +{ "char", TYPE_UINT, 127, 'C' }, +{ "signed char", TYPE_INT, 127, 'C' }, +{ "unsigned char", TYPE_UINT, 255, 'C' }, +{ "short int", TYPE_INT, 32767, 'S' }, +{ "unsigned short int", TYPE_UINT, 65535, 'S' }, +{ "int", TYPE_INT, 2147483647, 'I' }, +{ "unsigned int", TYPE_UINT, 4294967295U, 'I' }, +{ "long int", TYPE_INT, 9223372036854775807LL, 'L' }, +{ "unsigned long int", TYPE_UINT, 18446744073709551615ULL, 'L' }, +{ "long long int", TYPE_INT, 9223372036854775807LL, 'Q' }, +{ "unsigned long long int", TYPE_UINT, 18446744073709551615ULL, 'Q' }, +{ "bool", TYPE_UINT, 1, 'B' }, +{ "void *", TYPE_PTR, 0, 0 }, +{ "char *", TYPE_PTR, 0, 0 }, +{ "int *", TYPE_PTR, 0, 0 }, +{ "float", TYPE_FLOAT, 0, 0 }, +{ "double", TYPE_FLOAT, 0, 0 }, +{ "long double", TYPE_FLOAT, 0, 0 }, +#define NTYPES1 18 +{ "Tchar", TYPE_UINT, 127, 'C' }, +{ "Tschar", TYPE_INT, 127, 'C' }, +{ "Tuchar", TYPE_UINT, 255, 'C' }, +{ "Tshort", TYPE_INT, 32767, 'S' }, +{ "Tushort", TYPE_UINT, 65535, 'S' }, +{ "Tint", TYPE_INT, 2147483647, 'I' }, +{ "Tuint", TYPE_UINT, 4294967295U, 'I' }, +{ "Tlong", TYPE_INT, 9223372036854775807LL, 'L' }, +{ "Tulong", TYPE_UINT, 18446744073709551615ULL, 'L' }, +{ "Tllong", TYPE_INT, 9223372036854775807LL, 'Q' }, +{ "Tullong", TYPE_UINT, 18446744073709551615ULL, 'Q' }, +{ "Tbool", TYPE_UINT, 1, 'B' }, +{ "size_t", TYPE_UINT, 18446744073709551615ULL, 0 }, +{ "Tptr", TYPE_PTR, 0, 0 }, +{ "Tcptr", TYPE_PTR, 0, 0 }, +{ "Tiptr", TYPE_PTR, 0, 0 }, +{ "Tfnptr", TYPE_FNPTR, 0, 0 }, +{ "Tfloat", TYPE_FLOAT, 0, 0 }, +{ "Tdouble", TYPE_FLOAT, 0, 0 }, +{ "Tldouble", TYPE_FLOAT, 0, 0 }, +{ "enum E0", TYPE_UENUM, 0, ' ' }, +{ "enum E1", TYPE_UENUM, 1, ' ' }, +{ "enum E2", TYPE_SENUM, 3, ' ' }, +{ "enum E3", TYPE_SENUM, 127, ' ' }, +{ "enum E4", TYPE_UENUM, 255, ' ' }, +{ "enum E5", TYPE_SENUM, 32767, ' ' }, +{ "enum E6", TYPE_UENUM, 65535, ' ' }, +{ "enum E7", TYPE_SENUM, 2147483647, ' ' }, +{ "enum E8", TYPE_UENUM, 4294967295U, ' ' }, +{ "enum E9", TYPE_SENUM, 1099511627775LL, ' ' }, +{ "TE0", TYPE_UENUM, 0, ' ' }, +{ "TE1", TYPE_UENUM, 1, ' ' }, +{ "TE2", TYPE_SENUM, 3, ' ' }, +{ "TE3", TYPE_SENUM, 127, ' ' }, +{ "TE4", TYPE_UENUM, 255, ' ' }, +{ "TE5", TYPE_SENUM, 32767, ' ' }, +{ "TE6", TYPE_UENUM, 65535, ' ' }, +{ "TE7", TYPE_SENUM, 2147483647, ' ' }, +{ "TE8", TYPE_UENUM, 4294967295U, ' ' }, +{ "TE9", TYPE_SENUM, 1099511627775LL, ' ' }, +/* vector-defs.h typedefs */ +{ "qi", TYPE_INT, 127, 0 }, +{ "hi", TYPE_INT, 32767, 0 }, +{ "si", TYPE_INT, 2147483647, 0 }, +{ "di", TYPE_INT, 9223372036854775807LL, 0 }, +{ "sf", TYPE_FLOAT, 0, 0 }, +{ "df", TYPE_FLOAT, 0, 0 } +#define NTYPES2 (sizeof (base_types) / sizeof (base_types[0])) +}; +struct types vector_types[] = { +/* vector-defs.h typedefs */ +{ "v8qi", TYPE_OTHER, 0, 0 }, +{ "v16qi", TYPE_OTHER, 0, 0 }, +{ "v2hi", TYPE_OTHER, 0, 0 }, +{ "v4hi", TYPE_OTHER, 0, 0 }, +{ "v8hi", TYPE_OTHER, 0, 0 }, +{ "v2si", TYPE_OTHER, 0, 0 }, +{ "v4si", TYPE_OTHER, 0, 0 }, +{ "v1di", TYPE_OTHER, 0, 0 }, +{ "v2di", TYPE_OTHER, 0, 0 }, +{ "v2sf", TYPE_OTHER, 0, 0 }, +{ "v4sf", TYPE_OTHER, 0, 0 }, +{ "v16sf", TYPE_OTHER, 0, 0 }, +{ "v2df", TYPE_OTHER, 0, 0 }, +{ "u8qi", TYPE_OTHER, 0, 0 }, +{ "u16qi", TYPE_OTHER, 0, 0 }, +{ "u2hi", TYPE_OTHER, 0, 0 }, +{ "u4hi", TYPE_OTHER, 0, 0 }, +{ "u8hi", TYPE_OTHER, 0, 0 }, +{ "u2si", TYPE_OTHER, 0, 0 }, +{ "u4si", TYPE_OTHER, 0, 0 }, +{ "u1di", TYPE_OTHER, 0, 0 }, +{ "u2di", TYPE_OTHER, 0, 0 }, +{ "u2sf", TYPE_OTHER, 0, 0 }, +{ "u4sf", TYPE_OTHER, 0, 0 }, +{ "u16sf", TYPE_OTHER, 0, 0 }, +{ "u2df", TYPE_OTHER, 0, 0 }, +{ "__m64", TYPE_OTHER, 0, 0 }, +{ "__m128", TYPE_OTHER, 0, 0 } +#define NVTYPES2 (sizeof (vector_types) / sizeof (vector_types[0])) +}; +struct types attrib_types[] = { +{ "Talchar", TYPE_UINT, 127, 'C' }, +{ "Talschar", TYPE_INT, 127, 'C' }, +{ "Taluchar", TYPE_UINT, 255, 'C' }, +{ "Talshort", TYPE_INT, 32767, 'S' }, +{ "Talushort", TYPE_UINT, 65535, 'S' }, +{ "Talint", TYPE_INT, 2147483647, 'I' }, +{ "Taluint", TYPE_UINT, 4294967295U, 'I' }, +{ "Tallong", TYPE_INT, 9223372036854775807LL, 'L' }, +{ "Talulong", TYPE_UINT, 18446744073709551615ULL, 'L' }, +{ "Talllong", TYPE_INT, 9223372036854775807LL, 'Q' }, +{ "Talullong", TYPE_UINT, 18446744073709551615ULL, 'Q' }, +{ "Talbool", TYPE_UINT, 1, 'B' }, +{ "Talptr", TYPE_PTR, 0, 0 }, +{ "Talcptr", TYPE_PTR, 0, 0 }, +{ "Taliptr", TYPE_PTR, 0, 0 }, +{ "Talfloat", TYPE_FLOAT, 0, 0 }, +{ "Taldouble", TYPE_FLOAT, 0, 0 }, +{ "Talldouble", TYPE_FLOAT, 0, 0 }, +{ "TalE0", TYPE_UENUM, 0, ' ' }, +{ "TalE1", TYPE_UENUM, 1, ' ' }, +{ "TalE2", TYPE_SENUM, 3, ' ' }, +{ "TalE3", TYPE_SENUM, 127, ' ' }, +{ "TalE4", TYPE_UENUM, 255, ' ' }, +{ "TalE5", TYPE_SENUM, 32767, ' ' }, +{ "TalE6", TYPE_UENUM, 65535, ' ' }, +{ "TalE7", TYPE_SENUM, 2147483647, ' ' }, +{ "TalE8", TYPE_UENUM, 4294967295U, ' ' }, +{ "TalE9", TYPE_SENUM, 1099511627775LL, ' ' }, +{ "Tal1char", TYPE_UINT, 127, 'C' }, +{ "Tal1schar", TYPE_INT, 127, 'C' }, +{ "Tal1uchar", TYPE_UINT, 255, 'C' }, +{ "Tal1short", TYPE_INT, 32767, 'S' }, +{ "Tal1ushort", TYPE_UINT, 65535, 'S' }, +{ "Tal1int", TYPE_INT, 2147483647, 'I' }, +{ "Tal1uint", TYPE_UINT, 4294967295U, 'I' }, +{ "Tal1long", TYPE_INT, 9223372036854775807LL, 'L' }, +{ "Tal1ulong", TYPE_UINT, 18446744073709551615ULL, 'L' }, +{ "Tal1llong", TYPE_INT, 9223372036854775807LL, 'Q' }, +{ "Tal1ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' }, +{ "Tal1bool", TYPE_UINT, 1, 'B' }, +{ "Tal1ptr", TYPE_PTR, 0, 0 }, +{ "Tal1cptr", TYPE_PTR, 0, 0 }, +{ "Tal1iptr", TYPE_PTR, 0, 0 }, +{ "Tal1float", TYPE_FLOAT, 0, 0 }, +{ "Tal1double", TYPE_FLOAT, 0, 0 }, +{ "Tal1ldouble", TYPE_FLOAT, 0, 0 }, +{ "Tal1E0", TYPE_UENUM, 0, ' ' }, +{ "Tal1E1", TYPE_UENUM, 1, ' ' }, +{ "Tal1E2", TYPE_SENUM, 3, ' ' }, +{ "Tal1E3", TYPE_SENUM, 127, ' ' }, +{ "Tal1E4", TYPE_UENUM, 255, ' ' }, +{ "Tal1E5", TYPE_SENUM, 32767, ' ' }, +{ "Tal1E6", TYPE_UENUM, 65535, ' ' }, +{ "Tal1E7", TYPE_SENUM, 2147483647, ' ' }, +{ "Tal1E8", TYPE_UENUM, 4294967295U, ' ' }, +{ "Tal1E9", TYPE_SENUM, 1099511627775LL, ' ' }, +{ "Tal2char", TYPE_UINT, 127, 'C' }, +{ "Tal2schar", TYPE_INT, 127, 'C' }, +{ "Tal2uchar", TYPE_UINT, 255, 'C' }, +{ "Tal2short", TYPE_INT, 32767, 'S' }, +{ "Tal2ushort", TYPE_UINT, 65535, 'S' }, +{ "Tal2int", TYPE_INT, 2147483647, 'I' }, +{ "Tal2uint", TYPE_UINT, 4294967295U, 'I' }, +{ "Tal2long", TYPE_INT, 9223372036854775807LL, 'L' }, +{ "Tal2ulong", TYPE_UINT, 18446744073709551615ULL, 'L' }, +{ "Tal2llong", TYPE_INT, 9223372036854775807LL, 'Q' }, +{ "Tal2ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' }, +{ "Tal2bool", TYPE_UINT, 1, 'B' }, +{ "Tal2ptr", TYPE_PTR, 0, 0 }, +{ "Tal2cptr", TYPE_PTR, 0, 0 }, +{ "Tal2iptr", TYPE_PTR, 0, 0 }, +{ "Tal2float", TYPE_FLOAT, 0, 0 }, +{ "Tal2double", TYPE_FLOAT, 0, 0 }, +{ "Tal2ldouble", TYPE_FLOAT, 0, 0 }, +{ "Tal2E0", TYPE_UENUM, 0, ' ' }, +{ "Tal2E1", TYPE_UENUM, 1, ' ' }, +{ "Tal2E2", TYPE_SENUM, 3, ' ' }, +{ "Tal2E3", TYPE_SENUM, 127, ' ' }, +{ "Tal2E4", TYPE_UENUM, 255, ' ' }, +{ "Tal2E5", TYPE_SENUM, 32767, ' ' }, +{ "Tal2E6", TYPE_UENUM, 65535, ' ' }, +{ "Tal2E7", TYPE_SENUM, 2147483647, ' ' }, +{ "Tal2E8", TYPE_UENUM, 4294967295U, ' ' }, +{ "Tal2E9", TYPE_SENUM, 1099511627775LL, ' ' }, +{ "Tal4char", TYPE_UINT, 127, 'C' }, +{ "Tal4schar", TYPE_INT, 127, 'C' }, +{ "Tal4uchar", TYPE_UINT, 255, 'C' }, +{ "Tal4short", TYPE_INT, 32767, 'S' }, +{ "Tal4ushort", TYPE_UINT, 65535, 'S' }, +{ "Tal4int", TYPE_INT, 2147483647, 'I' }, +{ "Tal4uint", TYPE_UINT, 4294967295U, 'I' }, +{ "Tal4long", TYPE_INT, 9223372036854775807LL, 'L' }, +{ "Tal4ulong", TYPE_UINT, 18446744073709551615ULL, 'L' }, +{ "Tal4llong", TYPE_INT, 9223372036854775807LL, 'Q' }, +{ "Tal4ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' }, +{ "Tal4bool", TYPE_UINT, 1, 'B' }, +{ "Tal4ptr", TYPE_PTR, 0, 0 }, +{ "Tal4cptr", TYPE_PTR, 0, 0 }, +{ "Tal4iptr", TYPE_PTR, 0, 0 }, +{ "Tal4float", TYPE_FLOAT, 0, 0 }, +{ "Tal4double", TYPE_FLOAT, 0, 0 }, +{ "Tal4ldouble", TYPE_FLOAT, 0, 0 }, +{ "Tal4E0", TYPE_UENUM, 0, ' ' }, +{ "Tal4E1", TYPE_UENUM, 1, ' ' }, +{ "Tal4E2", TYPE_SENUM, 3, ' ' }, +{ "Tal4E3", TYPE_SENUM, 127, ' ' }, +{ "Tal4E4", TYPE_UENUM, 255, ' ' }, +{ "Tal4E5", TYPE_SENUM, 32767, ' ' }, +{ "Tal4E6", TYPE_UENUM, 65535, ' ' }, +{ "Tal4E7", TYPE_SENUM, 2147483647, ' ' }, +{ "Tal4E8", TYPE_UENUM, 4294967295U, ' ' }, +{ "Tal4E9", TYPE_SENUM, 1099511627775LL, ' ' }, +{ "Tal8char", TYPE_UINT, 127, 'C' }, +{ "Tal8schar", TYPE_INT, 127, 'C' }, +{ "Tal8uchar", TYPE_UINT, 255, 'C' }, +{ "Tal8short", TYPE_INT, 32767, 'S' }, +{ "Tal8ushort", TYPE_UINT, 65535, 'S' }, +{ "Tal8int", TYPE_INT, 2147483647, 'I' }, +{ "Tal8uint", TYPE_UINT, 4294967295U, 'I' }, +{ "Tal8long", TYPE_INT, 9223372036854775807LL, 'L' }, +{ "Tal8ulong", TYPE_UINT, 18446744073709551615ULL, 'L' }, +{ "Tal8llong", TYPE_INT, 9223372036854775807LL, 'Q' }, +{ "Tal8ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' }, +{ "Tal8bool", TYPE_UINT, 1, 'B' }, +{ "Tal8ptr", TYPE_PTR, 0, 0 }, +{ "Tal8cptr", TYPE_PTR, 0, 0 }, +{ "Tal8iptr", TYPE_PTR, 0, 0 }, +{ "Tal8float", TYPE_FLOAT, 0, 0 }, +{ "Tal8double", TYPE_FLOAT, 0, 0 }, +{ "Tal8ldouble", TYPE_FLOAT, 0, 0 }, +{ "Tal8E0", TYPE_UENUM, 0, ' ' }, +{ "Tal8E1", TYPE_UENUM, 1, ' ' }, +{ "Tal8E2", TYPE_SENUM, 3, ' ' }, +{ "Tal8E3", TYPE_SENUM, 127, ' ' }, +{ "Tal8E4", TYPE_UENUM, 255, ' ' }, +{ "Tal8E5", TYPE_SENUM, 32767, ' ' }, +{ "Tal8E6", TYPE_UENUM, 65535, ' ' }, +{ "Tal8E7", TYPE_SENUM, 2147483647, ' ' }, +{ "Tal8E8", TYPE_UENUM, 4294967295U, ' ' }, +{ "Tal8E9", TYPE_SENUM, 1099511627775LL, ' ' }, +{ "Tal16char", TYPE_UINT, 127, 'C' }, +{ "Tal16schar", TYPE_INT, 127, 'C' }, +{ "Tal16uchar", TYPE_UINT, 255, 'C' }, +{ "Tal16short", TYPE_INT, 32767, 'S' }, +{ "Tal16ushort", TYPE_UINT, 65535, 'S' }, +{ "Tal16int", TYPE_INT, 2147483647, 'I' }, +{ "Tal16uint", TYPE_UINT, 4294967295U, 'I' }, +{ "Tal16long", TYPE_INT, 9223372036854775807LL, 'L' }, +{ "Tal16ulong", TYPE_UINT, 18446744073709551615ULL, 'L' }, +{ "Tal16llong", TYPE_INT, 9223372036854775807LL, 'Q' }, +{ "Tal16ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' }, +{ "Tal16bool", TYPE_UINT, 1, 'B' }, +{ "Tal16ptr", TYPE_PTR, 0, 0 }, +{ "Tal16cptr", TYPE_PTR, 0, 0 }, +{ "Tal16iptr", TYPE_PTR, 0, 0 }, +{ "Tal16float", TYPE_FLOAT, 0, 0 }, +{ "Tal16double", TYPE_FLOAT, 0, 0 }, +{ "Tal16ldouble", TYPE_FLOAT, 0, 0 }, +{ "Tal16E0", TYPE_UENUM, 0, ' ' }, +{ "Tal16E1", TYPE_UENUM, 1, ' ' }, +{ "Tal16E2", TYPE_SENUM, 3, ' ' }, +{ "Tal16E3", TYPE_SENUM, 127, ' ' }, +{ "Tal16E4", TYPE_UENUM, 255, ' ' }, +{ "Tal16E5", TYPE_SENUM, 32767, ' ' }, +{ "Tal16E6", TYPE_UENUM, 65535, ' ' }, +{ "Tal16E7", TYPE_SENUM, 2147483647, ' ' }, +{ "Tal16E8", TYPE_UENUM, 4294967295U, ' ' }, +{ "Tal16E9", TYPE_SENUM, 1099511627775LL, ' ' } +#define NATYPES2 (sizeof (attrib_types) / sizeof (attrib_types[0])) +}; + +struct types bitfld_types[NTYPES2]; +int n_bitfld_types; +struct types aligned_bitfld_types[NATYPES2]; +int n_aligned_bitfld_types; + +const char *attributes[] = { +"atal", +"atpa", +"atal1", +"atal2", +"atal4", +"atal8", +"atal16", +#define NATTRIBS1 7 +"atalpa", +"atpaal", +"atal1pa", +"atal2pa", +"atal4pa", +"atal8pa", +"atal16pa", +"atpaal1", +"atpaal2", +"atpaal4", +"atpaal8", +"atpaal16" +#define NATTRIBS2 (sizeof (attributes) / sizeof (attributes[0])) +}; + +enum ETYPE +{ + ETYPE_TYPE, + ETYPE_ARRAY, + ETYPE_BITFLD, + ETYPE_STRUCT, + ETYPE_UNION, + ETYPE_STRUCT_ARRAY, + ETYPE_UNION_ARRAY +}; + +struct entry +{ +#ifdef __GNUC__ + enum ETYPE etype : 8; +#else + unsigned char etype; +#endif + unsigned short len; + unsigned char arr_len; + struct types *type; + const char *attrib; + /* Used to chain together entries in the hash table. */ + struct entry *next; +}; +struct types attrib_array_types[] = { +{ "Talx1char", TYPE_UINT, 127, 'C' }, +{ "Talx1schar", TYPE_INT, 127, 'C' }, +{ "Talx1uchar", TYPE_UINT, 255, 'C' }, +{ "Talx1short", TYPE_INT, 32767, 'S' }, +{ "Talx1ushort", TYPE_UINT, 65535, 'S' }, +{ "Talx1int", TYPE_INT, 2147483647, 'I' }, +{ "Talx1uint", TYPE_UINT, 4294967295U, 'I' }, +{ "Talx1long", TYPE_INT, 9223372036854775807LL, 'L' }, +{ "Talx1ulong", TYPE_UINT, 18446744073709551615ULL, 'L' }, +{ "Talx1llong", TYPE_INT, 9223372036854775807LL, 'Q' }, +{ "Talx1ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' }, +{ "Talx1bool", TYPE_UINT, 1, 'B' }, +{ "Talx1ptr", TYPE_PTR, 0, 0 }, +{ "Talx1cptr", TYPE_PTR, 0, 0 }, +{ "Talx1iptr", TYPE_PTR, 0, 0 }, +{ "Talx1float", TYPE_FLOAT, 0, 0 }, +{ "Talx1double", TYPE_FLOAT, 0, 0 }, +{ "Talx1ldouble", TYPE_FLOAT, 0, 0 }, +{ "Talx1E0", TYPE_UENUM, 0, ' ' }, +{ "Talx1E1", TYPE_UENUM, 1, ' ' }, +{ "Talx1E2", TYPE_SENUM, 3, ' ' }, +{ "Talx1E3", TYPE_SENUM, 127, ' ' }, +{ "Talx1E4", TYPE_UENUM, 255, ' ' }, +{ "Talx1E5", TYPE_SENUM, 32767, ' ' }, +{ "Talx1E6", TYPE_UENUM, 65535, ' ' }, +{ "Talx1E7", TYPE_SENUM, 2147483647, ' ' }, +{ "Talx1E8", TYPE_UENUM, 4294967295U, ' ' }, +{ "Talx1E9", TYPE_SENUM, 1099511627775LL, ' ' }, +{ "Talx2short", TYPE_INT, 32767, 'S' }, +{ "Talx2ushort", TYPE_UINT, 65535, 'S' }, +{ "Talx2int", TYPE_INT, 2147483647, 'I' }, +{ "Talx2uint", TYPE_UINT, 4294967295U, 'I' }, +{ "Talx2long", TYPE_INT, 9223372036854775807LL, 'L' }, +{ "Talx2ulong", TYPE_UINT, 18446744073709551615ULL, 'L' }, +{ "Talx2llong", TYPE_INT, 9223372036854775807LL, 'Q' }, +{ "Talx2ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' }, +{ "Talx2ptr", TYPE_PTR, 0, 0 }, +{ "Talx2cptr", TYPE_PTR, 0, 0 }, +{ "Talx2iptr", TYPE_PTR, 0, 0 }, +{ "Talx2float", TYPE_FLOAT, 0, 0 }, +{ "Talx2double", TYPE_FLOAT, 0, 0 }, +{ "Talx2ldouble", TYPE_FLOAT, 0, 0 }, +{ "Talx2E0", TYPE_UENUM, 0, ' ' }, +{ "Talx2E1", TYPE_UENUM, 1, ' ' }, +{ "Talx2E2", TYPE_SENUM, 3, ' ' }, +{ "Talx2E3", TYPE_SENUM, 127, ' ' }, +{ "Talx2E4", TYPE_UENUM, 255, ' ' }, +{ "Talx2E5", TYPE_SENUM, 32767, ' ' }, +{ "Talx2E6", TYPE_UENUM, 65535, ' ' }, +{ "Talx2E7", TYPE_SENUM, 2147483647, ' ' }, +{ "Talx2E8", TYPE_UENUM, 4294967295U, ' ' }, +{ "Talx2E9", TYPE_SENUM, 1099511627775LL, ' ' }, +{ "Talx4int", TYPE_INT, 2147483647, 'I' }, +{ "Talx4uint", TYPE_UINT, 4294967295U, 'I' }, +{ "Talx4long", TYPE_INT, 9223372036854775807LL, 'L' }, +{ "Talx4ulong", TYPE_UINT, 18446744073709551615ULL, 'L' }, +{ "Talx4llong", TYPE_INT, 9223372036854775807LL, 'Q' }, +{ "Talx4ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' }, +{ "Talx4ptr", TYPE_PTR, 0, 0 }, +{ "Talx4cptr", TYPE_PTR, 0, 0 }, +{ "Talx4iptr", TYPE_PTR, 0, 0 }, +{ "Talx4float", TYPE_FLOAT, 0, 0 }, +{ "Talx4double", TYPE_FLOAT, 0, 0 }, +{ "Talx4ldouble", TYPE_FLOAT, 0, 0 }, +{ "Talx4E0", TYPE_UENUM, 0, ' ' }, +{ "Talx4E1", TYPE_UENUM, 1, ' ' }, +{ "Talx4E2", TYPE_SENUM, 3, ' ' }, +{ "Talx4E3", TYPE_SENUM, 127, ' ' }, +{ "Talx4E4", TYPE_UENUM, 255, ' ' }, +{ "Talx4E5", TYPE_SENUM, 32767, ' ' }, +{ "Talx4E6", TYPE_UENUM, 65535, ' ' }, +{ "Talx4E7", TYPE_SENUM, 2147483647, ' ' }, +{ "Talx4E8", TYPE_UENUM, 4294967295U, ' ' }, +{ "Talx4E9", TYPE_SENUM, 1099511627775LL, ' ' }, +{ "Taly8long", TYPE_INT, 9223372036854775807LL, 'L' }, +{ "Taly8ulong", TYPE_UINT, 18446744073709551615ULL, 'L' }, +{ "Talx8llong", TYPE_INT, 9223372036854775807LL, 'Q' }, +{ "Talx8ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' }, +{ "Taly8ptr", TYPE_PTR, 0, 0 }, +{ "Taly8cptr", TYPE_PTR, 0, 0 }, +{ "Taly8iptr", TYPE_PTR, 0, 0 }, +{ "Talx8double", TYPE_FLOAT, 0, 0 }, +{ "Talx8ldouble", TYPE_FLOAT, 0, 0 } +#define NAATYPES2 (sizeof (attrib_array_types) / sizeof (attrib_array_types[0])) +}; + +/* A prime number giving the number of slots in the hash table. */ +#define HASH_SIZE 32749 +static struct entry *hash_table[HASH_SIZE]; + +static int idx, limidx, output_one, short_enums; +static const char *destdir; +static const char *srcdir; +static const char *srcdir_safe; +FILE *outfile; + +void +switchfiles (int fields) +{ + static int filecnt; + static char *destbuf, *destptr; + int i; + + ++filecnt; + if (outfile) + fclose (outfile); + if (output_one) + { + outfile = stdout; + return; + } + if (destbuf == NULL) + { + size_t len = strlen (destdir); + destbuf = malloc (len + 20); + if (!destbuf) + abort (); + memcpy (destbuf, destdir, len); + if (!len || destbuf[len - 1] != '/') + destbuf[len++] = '/'; + destptr = destbuf + len; + } + sprintf (destptr, "t%03d_main.C", filecnt); + outfile = fopen (destbuf, "w"); + if (outfile == NULL) + { + fail: + fputs ("failed to create test files\n", stderr); + exit (1); + } + for (i = 0; i < NDG_OPTIONS; i++) + fprintf (outfile, dg_options[i], "", srcdir_safe); + fprintf (outfile, "\n\ +#include \"struct-layout-1.h\"\n\ +\n\ +#define TX(n, type, attrs, fields, ops) extern void test##n (void);\n\ +#include \"t%03d_test.h\"\n\ +#undef TX\n\ +\n\ +int main (void)\n\ +{\n\ +#define TX(n, type, attrs, fields, ops) test##n ();\n\ +#include \"t%03d_test.h\"\n\ +#undef TX\n\ + if (fails)\n\ + {\n\ + fflush (stdout);\n\ + abort ();\n\ + }\n\ + exit (0);\n\ +}\n", filecnt, filecnt); + fclose (outfile); + sprintf (destptr, "t%03d_x.C", filecnt); + outfile = fopen (destbuf, "w"); + if (outfile == NULL) + goto fail; + for (i = 0; i < NDG_OPTIONS; i++) + fprintf (outfile, dg_options[i], "-w ", srcdir_safe); + fprintf (outfile, "\n\ +#include \"struct-layout-1_x1.h\"\n\ +#include \"t%03d_test.h\"\n\ +#include \"struct-layout-1_x2.h\"\n\ +#include \"t%03d_test.h\"\n", filecnt, filecnt); + fclose (outfile); + sprintf (destptr, "t%03d_y.C", filecnt); + outfile = fopen (destbuf, "w"); + if (outfile == NULL) + goto fail; + for (i = 0; i < NDG_OPTIONS; i++) + fprintf (outfile, dg_options[i], "-w ", srcdir_safe); + fprintf (outfile, "\n\ +#include \"struct-layout-1_y1.h\"\n\ +#include \"t%03d_test.h\"\n\ +#include \"struct-layout-1_y2.h\"\n\ +#include \"t%03d_test.h\"\n", filecnt, filecnt); + fclose (outfile); + sprintf (destptr, "t%03d_test.h", filecnt); + outfile = fopen (destbuf, "w"); + if (outfile == NULL) + goto fail; + if (fields <= 2) + limidx = idx + 300; + else if (fields <= 4) + limidx = idx + 200; + else if (fields <= 6) + limidx = idx + 100; + else + limidx = idx + 50; +} + +unsigned long long int +getrandll (void) +{ + unsigned long long int ret; + ret = generate_random () & 0xffffff; + ret |= (generate_random () & 0xffffffLL) << 24; + ret |= ((unsigned long long int) generate_random ()) << 48; + return ret; +} + +int +subfield (struct entry *e, char *letter) +{ + int i, type; + char buf[20]; + const char *p; + switch (e[0].etype) + { + case ETYPE_STRUCT: + case ETYPE_UNION: + case ETYPE_STRUCT_ARRAY: + case ETYPE_UNION_ARRAY: + type = e[0].attrib ? 1 + (generate_random () & 3) : 0; + if (e[0].etype == ETYPE_STRUCT || e[0].etype == ETYPE_STRUCT_ARRAY) + p = "struct"; + else + p = "union"; + if (e[0].etype == ETYPE_STRUCT_ARRAY || e[0].etype == ETYPE_UNION_ARRAY) + { + if (e[0].arr_len == 255) + snprintf (buf, 20, "%c[]", *letter); + else + snprintf (buf, 20, "%c[%d]", *letter, e[0].arr_len); + /* If this is an array type, do not put aligned attributes on + elements. Aligning elements to a value greater than their + size will result in a compiler error. */ + if (type == 1 + && ((strncmp (e[0].attrib, "atal", 4) == 0) + || strncmp (e[0].attrib, "atpaal", 6) == 0)) + type = 2; + } + else + { + buf[0] = *letter; + buf[1] = '\0'; + } + ++*letter; + switch (type) + { + case 0: + case 3: + case 4: + fprintf (outfile, "%s{", p); + break; + case 1: + fprintf (outfile, "%s %s{", e[0].attrib, p); + break; + case 2: + fprintf (outfile, "%s %s{", p, e[0].attrib); + break; + } + + for (i = 1; i <= e[0].len; ) + i += subfield (e + i, letter); + + switch (type) + { + case 0: + case 1: + case 2: + fprintf (outfile, "}%s;", buf); + break; + case 3: + fprintf (outfile, "}%s %s;", e[0].attrib, buf); + break; + case 4: + fprintf (outfile, "}%s %s;", buf, e[0].attrib); + break; + } + return 1 + e[0].len; + case ETYPE_TYPE: + case ETYPE_ARRAY: + if (e[0].etype == ETYPE_ARRAY) + { + if (e[0].arr_len == 255) + snprintf (buf, 20, "%c[]", *letter); + else + snprintf (buf, 20, "%c[%d]", *letter, e[0].arr_len); + } + else + { + buf[0] = *letter; + buf[1] = '\0'; + } + ++*letter; + if (e[0].attrib) + { + /* If this is an array type, do not put aligned attributes on + elements. Aligning elements to a value greater than their + size will result in a compiler error. */ + if (e[0].etype == ETYPE_ARRAY + && ((strncmp (e[0].attrib, "atal", 4) == 0) + || strncmp (e[0].attrib, "atpaal", 6) == 0)) + type = 2; + else + type = generate_random () % 3; + switch (type) + { + case 0: + fprintf (outfile, "%s %s %s;", e[0].attrib, e[0].type->name, + buf); + break; + case 1: + fprintf (outfile, "%s %s %s;", e[0].type->name, e[0].attrib, + buf); + break; + case 2: + fprintf (outfile, "%s %s %s;", e[0].type->name, buf, + e[0].attrib); + break; + } + } + else + fprintf (outfile, "%s %s;", e[0].type->name, buf); + return 1; + case ETYPE_BITFLD: + if (e[0].len == 0) + { + if (e[0].attrib) + switch (generate_random () % 3) + { + case 0: + fprintf (outfile, "%s %s:0;", e[0].attrib, e[0].type->name); + break; + case 1: + fprintf (outfile, "%s %s:0;", e[0].type->name, e[0].attrib); + break; + case 2: + fprintf (outfile, "%s:0 %s;", e[0].type->name, e[0].attrib); + break; + } + else + fprintf (outfile, "%s:0;", e[0].type->name); + ++*letter; + return 1; + } + snprintf (buf, 20, "%d", e[0].len); + if (e[0].attrib) + switch (generate_random () % 3) + { + case 0: + fprintf (outfile, "%s %s %c:%s;", e[0].attrib, e[0].type->name, + *letter, buf); + break; + case 1: + fprintf (outfile, "%s %s %c:%s;", e[0].type->name, e[0].attrib, + *letter, buf); + break; + case 2: + fprintf (outfile, "%s %c:%s %s;", e[0].type->name, *letter, + buf, e[0].attrib); + break; + } + else + fprintf (outfile, "%s %c:%s;", e[0].type->name, *letter, buf); + ++*letter; + return 1; + default: + abort (); + } +} + +char namebuf[1024]; + +void +output_FNB (char mode, struct entry *e) +{ + unsigned long long int l1, l2, m; + int signs = 0; + const char *p, *q; + + if (e->type->type == TYPE_OTHER) + { + if (mode == 'B') + abort (); + fprintf (outfile, "N(%d,%s)", idx, namebuf); + return; + } + fprintf (outfile, "%c(%d,%s,", mode, idx, namebuf); + l1 = getrandll (); + l2 = getrandll (); + switch (e->type->type) + { + case TYPE_INT: + signs = generate_random () & 3; + m = e->type->maxval; + if (mode == 'B') + m &= e->len > 1 ? (1ULL << (e->len - 1)) - 1 : 1; + l1 &= m; + l2 &= m; + fprintf (outfile, "%s%" COMPAT_PRLL "u%s,%s%" COMPAT_PRLL "u%s", + (signs & 1) ? "-" : "", l1, l1 > 2147483647 ? "LL" : "", + (signs & 2) ? "-" : "", l2, l2 > 2147483647 ? "LL" : ""); + break; + case TYPE_UINT: + m = e->type->maxval; + if (mode == 'B') + m &= (1ULL << e->len) - 1; + l1 &= m; + l2 &= m; + fprintf (outfile,"%" COMPAT_PRLL "uU%s,%" COMPAT_PRLL "uU%s", + l1, l1 > 4294967295U ? "LL" : "", + l2, l2 > 4294967295U ? "LL" : ""); + break; + case TYPE_FLOAT: + l1 &= 0xffffff; + l2 &= 0xffffff; + signs = generate_random () & 3; + fprintf (outfile, "%s%f,%s%f", (signs & 1) ? "-" : "", + ((double) l1) / 64, (signs & 2) ? "-" : "", ((double) l2) / 64); + break; + case TYPE_UENUM: + if (e->type->maxval == 0) + fputs ("e0_0,e0_0", outfile); + else if (e->type->maxval == 1) + fprintf (outfile, "e1_%" COMPAT_PRLL "d,e1_%" COMPAT_PRLL "d", + l1 & 1, l2 & 1); + else + { + p = strchr (e->type->name, '\0'); + while (--p >= e->type->name && *p >= '0' && *p <= '9'); + p++; + l1 %= 7; + l2 %= 7; + if (l1 > 3) + l1 += e->type->maxval - 6; + if (l2 > 3) + l2 += e->type->maxval - 6; + fprintf (outfile, "e%s_%" COMPAT_PRLL "d,e%s_%" COMPAT_PRLL "d", + p, l1, p, l2); + } + break; + case TYPE_SENUM: + p = strchr (e->type->name, '\0'); + while (--p >= e->type->name && *p >= '0' && *p <= '9'); + p++; + l1 %= 7; + l2 %= 7; + fprintf (outfile, "e%s_%s%" COMPAT_PRLL "d,e%s_%s%" COMPAT_PRLL "d", + p, l1 < 3 ? "m" : "", + l1 == 3 ? 0LL : e->type->maxval - (l1 & 3), + p, l2 < 3 ? "m" : "", + l2 == 3 ? 0LL : e->type->maxval - (l2 & 3)); + break; + case TYPE_PTR: + l1 %= 256; + l2 %= 256; + fprintf (outfile, + "(%s)&intarray[%" COMPAT_PRLL "d], (%s)&intarray[%" COMPAT_PRLL "d]", + e->type->name, l1, e->type->name, l2); + break; + case TYPE_FNPTR: + l1 %= 10; + l2 %= 10; + fprintf (outfile, + "fn%" COMPAT_PRLL "d,fn%" COMPAT_PRLL "d", l1, l2); + break; + default: + abort (); + } + fputs (")", outfile); +} + +int +subvalues (struct entry *e, char *p, char *letter) +{ + int i, j; + char *q; + if (p >= namebuf + sizeof (namebuf) - 32) + abort (); + p[0] = *letter; + p[1] = '\0'; + q = p + 1; + switch (e[0].etype) + { + case ETYPE_STRUCT_ARRAY: + case ETYPE_UNION_ARRAY: + if (e[0].arr_len == 0 || e[0].arr_len == 255) + { + *letter += 1 + e[0].len; + return 1 + e[0].len; + } + i = generate_random () % e[0].arr_len; + snprintf (p, sizeof (namebuf) - (p - namebuf) - 1, + "%c[%d]", *letter, i); + q = strchr (p, '\0'); + /* FALLTHROUGH */ + case ETYPE_STRUCT: + case ETYPE_UNION: + *q++ = '.'; + ++*letter; + for (i = 1; i <= e[0].len; ) + { + i += subvalues (e + i, q, letter); + if (e[0].etype == ETYPE_UNION || e[0].etype == ETYPE_UNION_ARRAY) + { + *letter += e[0].len - i + 1; + break; + } + } + return 1 + e[0].len; + case ETYPE_TYPE: + ++*letter; + output_FNB ('F', e); + return 1; + case ETYPE_ARRAY: + if (e[0].arr_len == 0 || e[0].arr_len == 255) + { + ++*letter; + return 1; + } + i = generate_random () % e[0].arr_len; + snprintf (p, sizeof (namebuf) - (p - namebuf), + "%c[%d]", *letter, i); + output_FNB ('F', e); + if ((generate_random () & 7) == 0) + { + j = generate_random () % e[0].arr_len; + if (i != j) + { + snprintf (p, sizeof (namebuf) - (p - namebuf), + "%c[%d]", *letter, j); + output_FNB ('F', e); + } + } + ++*letter; + return 1; + case ETYPE_BITFLD: + ++*letter; + if (e[0].len != 0) + output_FNB ('B', e); + return 1; + } +} + +/* DERIVED FROM: +-------------------------------------------------------------------- +lookup2.c, by Bob Jenkins, December 1996, Public Domain. +hash(), hash2(), hash3, and mix() are externally useful functions. +Routines to test the hash are included if SELF_TEST is defined. +You can use this free for any purpose. It has no warranty. +-------------------------------------------------------------------- +*/ + +/* +-------------------------------------------------------------------- +mix -- mix 3 32-bit values reversibly. +For every delta with one or two bit set, and the deltas of all three + high bits or all three low bits, whether the original value of a,b,c + is almost all zero or is uniformly distributed, +* If mix() is run forward or backward, at least 32 bits in a,b,c + have at least 1/4 probability of changing. +* If mix() is run forward, every bit of c will change between 1/3 and + 2/3 of the time. (Well, 22/100 and 78/100 for some 2-bit deltas.) +mix() was built out of 36 single-cycle latency instructions in a + structure that could supported 2x parallelism, like so: + a -= b; + a -= c; x = (c>>13); + b -= c; a ^= x; + b -= a; x = (a<<8); + c -= a; b ^= x; + c -= b; x = (b>>13); + ... + Unfortunately, superscalar Pentiums and Sparcs can't take advantage + of that parallelism. They've also turned some of those single-cycle + latency instructions into multi-cycle latency instructions. Still, + this is the fastest good hash I could find. There were about 2^^68 + to choose from. I only looked at a billion or so. +-------------------------------------------------------------------- +*/ +/* same, but slower, works on systems that might have 8 byte hashval_t's */ +#define mix(a,b,c) \ +{ \ + a -= b; a -= c; a ^= (c>>13); \ + b -= c; b -= a; b ^= (a<< 8); \ + c -= a; c -= b; c ^= ((b&0xffffffff)>>13); \ + a -= b; a -= c; a ^= ((c&0xffffffff)>>12); \ + b -= c; b -= a; b = (b ^ (a<<16)) & 0xffffffff; \ + c -= a; c -= b; c = (c ^ (b>> 5)) & 0xffffffff; \ + a -= b; a -= c; a = (a ^ (c>> 3)) & 0xffffffff; \ + b -= c; b -= a; b = (b ^ (a<<10)) & 0xffffffff; \ + c -= a; c -= b; c = (c ^ (b>>15)) & 0xffffffff; \ +} + +/* +-------------------------------------------------------------------- +hash() -- hash a variable-length key into a 32-bit value + k : the key (the unaligned variable-length array of bytes) + len : the length of the key, counting by bytes + level : can be any 4-byte value +Returns a 32-bit value. Every bit of the key affects every bit of +the return value. Every 1-bit and 2-bit delta achieves avalanche. +About 36+6len instructions. + +The best hash table sizes are powers of 2. There is no need to do +mod a prime (mod is sooo slow!). If you need less than 32 bits, +use a bitmask. For example, if you need only 10 bits, do + h = (h & hashmask(10)); +In which case, the hash table should have hashsize(10) elements. + +If you are hashing n strings (ub1 **)k, do it like this: + for (i=0, h=0; i<n; ++i) h = hash( k[i], len[i], h); + +By Bob Jenkins, 1996. bob_jenkins@burtleburtle.net. You may use this +code any way you wish, private, educational, or commercial. It's free. + +See http://burtleburtle.net/bob/hash/evahash.html +Use for hash table lookup, or anything where one collision in 2^32 is +acceptable. Do NOT use for cryptographic purposes. +-------------------------------------------------------------------- +*/ + +static hashval_t +iterative_hash (const void *k_in /* the key */, + register size_t length /* the length of the key */, + register hashval_t initval /* the previous hash, or + an arbitrary value */) +{ + register const unsigned char *k = (const unsigned char *)k_in; + register hashval_t a,b,c,len; + + /* Set up the internal state */ + len = length; + a = b = 0x9e3779b9; /* the golden ratio; an arbitrary value */ + c = initval; /* the previous hash value */ + + /*---------------------------------------- handle most of the key */ + while (len >= 12) + { + a += (k[0] +((hashval_t)k[1]<<8) +((hashval_t)k[2]<<16) +((hashval_t)k[3]<<24)); + b += (k[4] +((hashval_t)k[5]<<8) +((hashval_t)k[6]<<16) +((hashval_t)k[7]<<24)); + c += (k[8] +((hashval_t)k[9]<<8) +((hashval_t)k[10]<<16)+((hashval_t)k[11]<<24)); + mix(a,b,c); + k += 12; len -= 12; + } + + /*------------------------------------- handle the last 11 bytes */ + c += length; + switch(len) /* all the case statements fall through */ + { + case 11: c+=((hashval_t)k[10]<<24); + case 10: c+=((hashval_t)k[9]<<16); + case 9 : c+=((hashval_t)k[8]<<8); + /* the first byte of c is reserved for the length */ + case 8 : b+=((hashval_t)k[7]<<24); + case 7 : b+=((hashval_t)k[6]<<16); + case 6 : b+=((hashval_t)k[5]<<8); + case 5 : b+=k[4]; + case 4 : a+=((hashval_t)k[3]<<24); + case 3 : a+=((hashval_t)k[2]<<16); + case 2 : a+=((hashval_t)k[1]<<8); + case 1 : a+=k[0]; + /* case 0: nothing left to add */ + } + mix(a,b,c); + /*-------------------------------------------- report the result */ + return c; +} + +hashval_t +e_hash (const void *a) +{ + const struct entry *e = a; + hashval_t ret = 0; + int i; + + if (e[0].etype != ETYPE_STRUCT && e[0].etype != ETYPE_UNION) + abort (); + for (i = 0; i <= e[0].len; ++i) + { + int attriblen; + ret = iterative_hash (&e[i], offsetof (struct entry, attrib), ret); + attriblen = e[i].attrib ? strlen (e[i].attrib) : -1; + ret = iterative_hash (&attriblen, sizeof (int), ret); + if (e[i].attrib) + ret = iterative_hash (e[i].attrib, attriblen, ret); + } + return ret; +} + +int +e_eq (const void *a, const void *b) +{ + const struct entry *ea = a, *eb = b; + int i; + if (ea[0].etype != ETYPE_STRUCT && ea[0].etype != ETYPE_UNION) + abort (); + if (ea[0].len != eb[0].len) + return 0; + for (i = 0; i <= ea[0].len; ++i) + { + if (ea[i].etype != eb[i].etype + || ea[i].len != eb[i].len + || ea[i].arr_len != eb[i].arr_len + || ea[i].type != eb[i].type) + return 0; + if ((ea[i].attrib == NULL) ^ (eb[i].attrib == NULL)) + return 0; + if (ea[i].attrib && strcmp (ea[i].attrib, eb[i].attrib) != 0) + return 0; + } + return 1; +} + +static int +e_exists (const struct entry *e) +{ + struct entry *h; + hashval_t hval; + + hval = e_hash (e); + for (h = hash_table[hval % HASH_SIZE]; h; h = h->next) + if (e_eq (e, h)) + return 1; + return 0; +} + +static void +e_insert (struct entry *e) +{ + hashval_t hval; + + hval = e_hash (e); + e->next = hash_table[hval % HASH_SIZE]; + hash_table[hval % HASH_SIZE] = e; +} + +void +output (struct entry *e) +{ + int i; + char c; + struct entry *n; + + if (e[0].etype != ETYPE_STRUCT && e[0].etype != ETYPE_UNION) + abort (); + + if (e_exists (e)) + return; + + n = (struct entry *) malloc ((e[0].len + 1) * sizeof (struct entry)); + memcpy (n, e, (e[0].len + 1) * sizeof (struct entry)); + e_insert (n); + + if (idx == limidx) + switchfiles (e[0].len); + + if (e[0].etype == ETYPE_STRUCT) + fprintf (outfile, "T(%d,", idx); + else + fprintf (outfile, "U(%d,", idx); + c = 'a'; + for (i = 1; i <= e[0].len; ) + i += subfield (e + i, &c); + fputs (",", outfile); + c = 'a'; + for (i = 1; i <= e[0].len; ) + { + i += subvalues (e + i, namebuf, &c); + if (e[0].etype == ETYPE_UNION) + break; + } + fputs (")\n", outfile); + if (output_one && idx == limidx) + exit (0); + ++idx; +} + +enum FEATURE +{ + FEATURE_VECTOR = 1, + FEATURE_ALIGNEDPACKED = 2, + FEATURE_ZEROARRAY = 4, + FEATURE_ZEROBITFLD = 8, + ALL_FEATURES = FEATURE_VECTOR | FEATURE_ZEROARRAY + | FEATURE_ALIGNEDPACKED | FEATURE_ZEROBITFLD +}; + +void +singles (enum FEATURE features) +{ + struct entry e[2]; + int i; + memset (e, 0, sizeof (e)); + e[0].etype = ETYPE_STRUCT; + output (e); + e[0].etype = ETYPE_UNION; + output (e); + e[0].len = 1; + for (i = 0; i < NTYPES2; ++i) + { + e[0].etype = ETYPE_STRUCT; + e[1].etype = ETYPE_TYPE; + e[1].type = &base_types[i]; + output (e); + e[0].etype = ETYPE_UNION; + output (e); + } + if (features & FEATURE_VECTOR) + for (i = 0; i < NVTYPES2; ++i) + { + e[0].etype = ETYPE_STRUCT; + e[1].etype = ETYPE_TYPE; + e[1].type = &vector_types[i]; + output (e); + e[0].etype = ETYPE_UNION; + output (e); + } +} + +void +choose_type (enum FEATURE features, struct entry *e, int r, int in_array) +{ + int i; + + i = NTYPES2 - NTYPES1; + if (features & FEATURE_VECTOR) + i += NVTYPES2; + if ((r & 3) == 0) + { + if (in_array) + i += NAATYPES2; + else + i += NATYPES2; + } + r >>= 2; + r %= i; + if (r < NTYPES2 - NTYPES1) + e->type = &base_types[r + NTYPES1]; + r -= NTYPES2 - NTYPES1; + if (e->type == NULL && (features & FEATURE_VECTOR)) + { + if (r < NVTYPES2) + e->type = &vector_types[r]; + r -= NVTYPES2; + } + if (e->type == NULL && !in_array) + { + if (r < NATYPES2) + e->type = &attrib_types[r]; + r -= NATYPES2; + } + if (e->type == NULL && in_array) + { + if (r < NAATYPES2) + e->type = &attrib_array_types[r]; + r -= NAATYPES2; + } + if (e->type == NULL) + abort (); +} + +/* This is from gcc.c-torture/execute/builtin-bitops-1.c. */ +static int +my_ffsll (unsigned long long x) +{ + int i; + if (x == 0) + return 0; + /* We've tested LLONG_MAX for 64 bits so this should be safe. */ + for (i = 0; i < 64; i++) + if (x & (1ULL << i)) + break; + return i + 1; +} + +void +generate_fields (enum FEATURE features, struct entry *e, struct entry *parent, + int len) +{ + int r, i, j, ret = 1, n, incr, sametype; + + for (n = 0; n < len; n += incr) + { + r = generate_random (); + /* 50% ETYPE_TYPE base_types NTYPES1 + 12.5% ETYPE_TYPE other + 12.5% ETYPE_ARRAY + 12.5% ETYPE_BITFLD + 12.5% ETYPE_STRUCT|ETYPE_UNION|ETYPE_STRUCT_ARRAY|ETYPE_UNION_ARRAY */ + i = (r & 7); + r >>= 3; + incr = 1; + switch (i) + { + case 0: + case 1: + case 2: + case 3: + e[n].etype = ETYPE_TYPE; + e[n].type = &base_types[r % NTYPES1]; + break; + case 4: + e[n].etype = ETYPE_TYPE; + choose_type (features, &e[n], r, 0); + break; + case 5: + e[n].etype = ETYPE_ARRAY; + i = r & 1; + r >>= 1; + if (i) + e[n].type = &base_types[r % NTYPES1]; + else + choose_type (features, &e[n], r, 1); + r = generate_random (); + if ((features & FEATURE_ZEROARRAY) && (r & 3) == 0) + { + e[n].arr_len = 0; + if (n == len - 1 && (r & 4) + && (parent->etype == ETYPE_STRUCT + || parent->etype == ETYPE_STRUCT_ARRAY)) + { + int k; + for (k = 0; k < n; ++k) + if (e[k].etype != ETYPE_BITFLD || e[k].len) + { + e[n].arr_len = 255; + break; + } + } + } + else if ((r & 3) != 3) + e[n].arr_len = (r >> 2) & 7; + else + e[n].arr_len = (r >> 2) & 31; + break; + case 6: + sametype = 1; + switch (r & 7) + { + case 0: + case 1: + case 2: + break; + case 3: + case 4: + case 5: + incr = 1 + (r >> 3) % (len - n); + break; + case 6: + case 7: + sametype = 0; + incr = 1 + (r >> 3) % (len - n); + break; + } + for (j = n; j < n + incr; ++j) + { + int mi, ma; + + e[j].etype = ETYPE_BITFLD; + if (j == n || !sametype) + { + int k; + r = generate_random (); + k = r & 3; + r >>= 2; + if (!k) + e[j].type + = &aligned_bitfld_types[r % n_aligned_bitfld_types]; + else + e[j].type + = &bitfld_types[r % n_bitfld_types]; + } + else + e[j].type = e[n].type; + r = generate_random (); + mi = 0; + ma = 0; + switch (e[j].type->bitfld) + { + case 'C': ma = 8; break; + case 'S': ma = 16; break; + case 'I': ma = 32; break; + case 'L': + case 'Q': ma = 64; break; + case 'B': ma = 1; break; + case ' ': + if (e[j].type->type == TYPE_UENUM) + mi = my_ffsll (e[j].type->maxval + 1) - 1; + else if (e[j].type->type == TYPE_SENUM) + mi = my_ffsll (e[j].type->maxval + 1); + else + abort (); + if (!mi) + mi = 1; + if (mi > 32) + ma = 64; + else if (mi > 16 || !short_enums) + ma = 32; + else if (mi > 8) + ma = 16; + else + ma = 8; + break; + default: + abort (); + } + e[j].len = ma + 1; + if (sametype && (r & 3) == 0 && ma > 1) + { + int sum = 0, k; + for (k = n; k < j; ++k) + sum += e[k].len; + sum %= ma; + e[j].len = sum ? ma - sum : ma; + } + r >>= 2; + if (!sametype && (r & 7) == 0) + ma *= 8; + r >>= 3; + if (! (features & FEATURE_ZEROBITFLD) && mi == 0) + mi = 1; + if (e[j].len < mi || e[j].len > ma) + e[j].len = mi + (r % (ma + 1 - mi)); + r >>= 6; + if ((features & FEATURE_ZEROBITFLD) && (r & 3) == 0 + && mi == 0) + e[j].len = 0; + } + break; + case 7: + switch (r & 7) + { + case 0: + case 1: + case 2: + e[n].etype = ETYPE_STRUCT; + break; + case 3: + case 4: + e[n].etype = ETYPE_UNION; + break; + case 5: + case 6: + e[n].etype = ETYPE_STRUCT_ARRAY; + break; + case 7: + e[n].etype = ETYPE_UNION_ARRAY; + break; + } + r >>= 3; + e[n].len = r % (len - n); + incr = 1 + e[n].len; + generate_fields (features, &e[n + 1], &e[n], e[n].len); + if (e[n].etype == ETYPE_STRUCT_ARRAY + || e[n].etype == ETYPE_UNION_ARRAY) + { + r = generate_random (); + if ((features & FEATURE_ZEROARRAY) && (r & 3) == 0) + { + e[n].arr_len = 0; + if (n + incr == len && (r & 4) + && (parent->etype == ETYPE_STRUCT + || parent->etype == ETYPE_STRUCT_ARRAY)) + { + int k; + for (k = 0; k < n; ++k) + if (e[k].etype != ETYPE_BITFLD || e[k].len) + { + e[n].arr_len = 255; + break; + } + } + } + else if ((r & 3) != 3) + e[n].arr_len = (r >> 2) & 7; + else + e[n].arr_len = (r >> 2) & 31; + } + break; + } + r = generate_random (); + if ((r & 7) == 0) + { + r >>= 3; + i = (features & FEATURE_ALIGNEDPACKED) ? NATTRIBS2 : NATTRIBS1; + e[n].attrib = attributes[r % i]; + if (! (features & FEATURE_ALIGNEDPACKED) + && strcmp (e[n].attrib, "atpa") == 0 + && ((e[n].type >= &attrib_types[0] + && e[n].type < &attrib_types[NATYPES2]) + || (e[n].type >= &attrib_array_types[0] + && e[n].type < &attrib_array_types[NAATYPES2]) + || (e[n].type >= &aligned_bitfld_types[0] + && e[n].type < &aligned_bitfld_types[n_aligned_bitfld_types]))) + e[n].attrib = NULL; + } + } +} + +void +generate_random_tests (enum FEATURE features, int len) +{ + struct entry e[len + 1]; + int i, r; + if (len > 'z' - 'a' + 1) + abort (); + memset (e, 0, sizeof (e)); + r = generate_random (); + if ((r & 7) == 0) + e[0].etype = ETYPE_UNION; + else + e[0].etype = ETYPE_STRUCT; + r >>= 3; + e[0].len = len; + generate_fields (features, &e[1], &e[0], len); + output (e); +} + +struct { const char *name; enum FEATURE f; } +features[] = { +{ "normal", 0 }, +{ "vector", FEATURE_VECTOR }, +{ "[0] :0", FEATURE_ZEROARRAY | FEATURE_ZEROBITFLD }, +{ "vector [0]", + FEATURE_VECTOR | FEATURE_ZEROARRAY }, +{ "aligned packed vector [0] :0", + FEATURE_VECTOR | FEATURE_ZEROARRAY + | FEATURE_ALIGNEDPACKED | FEATURE_ZEROBITFLD }, +}; + +int +main (int argc, char **argv) +{ + int i, j, count, c, n = 3000; + char *optarg; + + if (sizeof (int) != 4 || sizeof (long long) != 8) + return 1; + + i = 1; + while (i < argc) + { + c = '\0'; + if (argv[i][0] == '-' && argv[i][2] == '\0') + c = argv[i][1]; + optarg = argv[i + 1]; + if (!optarg) + goto usage; + switch (c) + { + case 'n': + n = atoi (optarg); + break; + case 'd': + destdir = optarg; + break; + case 's': + srcdir = optarg; + break; + case 'i': + output_one = 1; + limidx = atoi (optarg); + break; + case 'e': + short_enums = 1; + i--; + break; + default: + fprintf (stderr, "unrecognized option %s\n", argv[i]); + goto usage; + } + i += 2; + } + + if (output_one) + { + outfile = fopen ("/dev/null", "w"); + if (outfile == NULL) + { + fputs ("could not open /dev/null", stderr); + return 1; + } + n = limidx + 1; + } + + if (destdir == NULL && !output_one) + { + usage: + fprintf (stderr, "Usage:\n\ +%s [-e] [-s srcdir -d destdir] [-n count] [-i idx]\n\ +Either -s srcdir -d destdir or -i idx must be used\n", argv[0]); + return 1; + } + + if (srcdir == NULL && !output_one) + goto usage; + + if (srcdir != NULL) + { + const char *s = srcdir; + char *ss, *t; + t = ss = malloc (strlen (srcdir) + 1); + if (!ss) + abort (); + do { + if (*s == '\\') + *t++ = '/'; + else + *t++ = *s; + } while (*s++); + srcdir_safe = ss; + } + + for (i = 0; i < NTYPES2; ++i) + if (base_types[i].bitfld) + bitfld_types[n_bitfld_types++] = base_types[i]; + for (i = 0; i < NATYPES2; ++i) + if (attrib_types[i].bitfld) + aligned_bitfld_types[n_aligned_bitfld_types++] = attrib_types[i]; + for (i = 0; i < sizeof (features) / sizeof (features[0]); ++i) + { + int startidx = idx; + if (! output_one) + limidx = idx; + if (!i) + count = 200; + else + count = 20; + for (j = 1; j <= 9; ++j) + while (idx < startidx + j * count) + generate_random_tests (features[i].f, j); + while (idx < startidx + count * 10) + generate_random_tests (features[i].f, 10 + (generate_random () % 16)); + } + for (i = 0; n > 3000 && i < sizeof (features) / sizeof (features[0]); ++i) + { + int startidx; + startidx = idx; + if (! output_one) + limidx = idx; + singles (features[i].f); + if (!i) + { + count = 1000; + while (idx < startidx + 1000) + generate_random_tests (features[i].f, 1); + } + else + { + startidx = idx; + count = 100; + while (idx < startidx + 100) + generate_random_tests (features[i].f, 1); + } + startidx = idx; + for (j = 2; j <= 9; ++j) + while (idx < startidx + (j - 1) * count) + generate_random_tests (features[i].f, j); + while (idx < startidx + count * 9) + generate_random_tests (features[i].f, 10 + (generate_random () % 16)); + } + if (! output_one) + limidx = idx; + while (idx < n) + generate_random_tests (ALL_FEATURES, 1 + (generate_random () % 25)); + fclose (outfile); + return 0; +} diff --git a/gcc/testsuite/g++.dg/compat/struct-layout-1_x1.h b/gcc/testsuite/g++.dg/compat/struct-layout-1_x1.h new file mode 100644 index 000000000..e14433e03 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/struct-layout-1_x1.h @@ -0,0 +1,68 @@ +#include "struct-layout-1.h" + +struct Info info; +int fails; +int intarray[256]; +int fn0 (void) { return 0; } +int fn1 (void) { return 1; } +int fn2 (void) { return 2; } +int fn3 (void) { return 3; } +int fn4 (void) { return 4; } +int fn5 (void) { return 5; } +int fn6 (void) { return 6; } +int fn7 (void) { return 7; } +int fn8 (void) { return 8; } +int fn9 (void) { return 9; } + +/* This macro is intended for fields where their + addresses/sizes/alignments and value passing should be checked. */ +#define F(n, x, v, w) \ + info.flds[i] = &s##n.x; \ + info.sizes[i] = sizeof (s##n.x); \ + info.aligns[i] = __alignof__ (s##n.x); \ + s##n.x = v; \ + a##n[2].x = w; \ + ++i; +/* This macro is for fields where just their addresses/sizes/alignments + should be checked. */ +#define N(n, x) \ + info.flds[i] = &s##n.x; \ + info.sizes[i] = sizeof (s##n.x); \ + info.aligns[i] = __alignof__ (s##n.x); \ + ++i; +/* This macro is for fields where just value passing should be checked. */ +#define B(n, x, v, w) \ + s##n.x = v; \ + a##n[2].x = w; \ + ++j; +#define TX(n, type, attrs, fields, ops) \ +type S##n { fields } attrs; \ +type S##n s##n; \ +extern type S##n a##n[5]; \ +extern type S##n check##n (type S##n, type S##n *, \ + type S##n); \ +extern void check##n##va (int i, ...); \ +extern void checkx##n (type S##n); \ +void test##n (void) \ +{ \ + int i, j; \ + memset (&s##n, '\0', sizeof (s##n)); \ + memset (a##n, '\0', sizeof (a##n)); \ + memset (&info, '\0', sizeof (info)); \ + info.sp = &s##n; \ + info.a0p = &a##n[0]; \ + info.a3p = &a##n[3]; \ + info.sz = sizeof (s##n); \ + info.als = __alignof__ (s##n); \ + info.ala0 = __alignof__ (a##n[0]); \ + info.ala3 = __alignof__ (a##n[3]); \ + if (((long) (__SIZE_TYPE__) &a##n[3]) & (info.als - 1)) \ + FAIL (n, 1); \ + i = 0; j = 0; \ + ops \ + info.nfields = i; \ + info.nbitfields = j; \ + checkx##n (check##n (s##n, &a##n[1], a##n[2])); \ + check##n##va (1, 1.0, s##n, 2LL, a##n[2], a##n[2]); \ + check##n##va (2, s##n, s##n, 2.0L, a##n[2], s##n); \ +} diff --git a/gcc/testsuite/g++.dg/compat/struct-layout-1_x2.h b/gcc/testsuite/g++.dg/compat/struct-layout-1_x2.h new file mode 100644 index 000000000..907a2c959 --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/struct-layout-1_x2.h @@ -0,0 +1,14 @@ +#undef F +#undef N +#undef B +#undef TX +#define F(n, x, v, w) \ + if (arg.x != s##n.x) FAIL (n, 30); +#define N(n, x) +#define B(n, x, v, w) \ + if (arg.x != s##n.x) FAIL (n, 30); +#define TX(n, type, attrs, fields, ops) \ +void checkx##n (type S##n arg) \ +{ \ + ops \ +} diff --git a/gcc/testsuite/g++.dg/compat/struct-layout-1_y1.h b/gcc/testsuite/g++.dg/compat/struct-layout-1_y1.h new file mode 100644 index 000000000..9a5d2468a --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/struct-layout-1_y1.h @@ -0,0 +1,76 @@ +#include "struct-layout-1.h" + +#define F(n, x, v, w) \ + if (info.flds[i] != &s##n.x) \ + FAIL (n, 50); \ + if (info.sizes[i] != sizeof (s##n.x)) \ + FAIL (n, 51); \ + if (info.aligns[i] != __alignof__ (s##n.x)) \ + FAIL (n, 52); \ + if (s##n.x != (__typeof__ (s##n.x)) v) \ + FAIL (n, 53); \ + if (a##n[2].x != (__typeof__ (s##n.x)) w) \ + FAIL (n, 54); \ + if (arg0.x != s##n.x) \ + FAIL (n, 55); \ + if (arg2.x != a##n[2].x) \ + FAIL (n, 56); \ + ret.x = s##n.x; \ + ++i; +#define N(n, x) \ + if (info.flds[i] != &s##n.x) \ + FAIL (n, 50); \ + if (info.sizes[i] != sizeof (s##n.x)) \ + FAIL (n, 51); \ + if (info.aligns[i] != __alignof__ (s##n.x)) \ + FAIL (n, 52); \ + ++i; +#define B(n, x, v, w) \ + b1.x = v; b2.x = w; \ + if (s##n.x != b1.x) \ + FAIL (n, 53); \ + if (a##n[2].x != b2.x) \ + FAIL (n, 54); \ + if (arg0.x != s##n.x) \ + FAIL (n, 55); \ + if (arg2.x != a##n[2].x) \ + FAIL (n, 56); \ + ret.x = s##n.x; \ + ++j; +#define TX(n, type, attrs, fields, ops) \ +type S##n { fields } attrs; \ +extern type S##n s##n; \ +type S##n a##n[5]; \ +type S##n \ +check##n (type S##n arg0, type S##n *arg1, type S##n arg2) \ +{ \ + type S##n ret; \ + type S##n b1, b2; \ + int i, j; \ + \ + memset (&ret, 0, sizeof (ret)); \ + memset (&b1, 0, sizeof (b1)); \ + memset (&b2, 0, sizeof (b2)); \ + if (info.sp != &s##n) \ + FAIL (n, 10); \ + if (info.a0p != &a##n[0]) \ + FAIL (n, 11); \ + if (info.a3p != &a##n[3]) \ + FAIL (n, 12); \ + if (info.sz != sizeof (s##n)) \ + FAIL (n, 13); \ + if (info.als != __alignof__ (s##n)) \ + FAIL (n, 14); \ + if (info.ala0 != __alignof__ (a##n[0])) \ + FAIL (n, 15); \ + if (info.ala3 != __alignof__ (a##n[3])) \ + FAIL (n, 16); \ + if (arg1 != &a##n[1]) \ + FAIL (n, 17); \ + i = 0; j = 0; \ + ops \ + if (i != info.nfields || j != info.nbitfields) \ + FAIL (n, 18); \ + \ + return ret; \ +} diff --git a/gcc/testsuite/g++.dg/compat/struct-layout-1_y2.h b/gcc/testsuite/g++.dg/compat/struct-layout-1_y2.h new file mode 100644 index 000000000..02a341e1c --- /dev/null +++ b/gcc/testsuite/g++.dg/compat/struct-layout-1_y2.h @@ -0,0 +1,69 @@ +#undef F +#undef N +#undef B +#undef TX + +#ifdef SKIP_VA +const int test_va = 0; +#else +const int test_va = 1; +#endif + +#define F(n, x, v, w) \ + if (p->x != arg.x) FAIL (n, 74); +#define N(n, x) +#define B(n, x, v, w) \ + if (p->x != arg.x) FAIL (n, 74); +#define TX(n, type, attrs, fields, ops) \ +void \ +check##n##va (int z, ...) \ +{ \ + type S##n arg, *p; \ + va_list ap; \ + int i; \ + \ + if (test_va) \ + { \ + va_start (ap, z); \ + for (i = 0; i < 5; ++i) \ + { \ + p = NULL; \ + switch ((z << 4) | i) \ + { \ + case 0x10: \ + if (va_arg (ap, double) != 1.0) \ + FAIL (n, 70); \ + break; \ + case 0x12: \ + if (va_arg (ap, long long) != 2LL) \ + FAIL (n, 71); \ + break; \ + case 0x22: \ + if (va_arg (ap, long double) != 2.0L) \ + FAIL (n, 72); \ + break; \ + case 0x11: \ + case 0x20: \ + case 0x21: \ + case 0x24: \ + p = &s##n; \ + arg = va_arg (ap, type S##n); \ + break; \ + case 0x13: \ + case 0x14: \ + case 0x23: \ + p = &a##n[2]; \ + arg = va_arg (ap, type S##n); \ + break; \ + default: \ + FAIL (n, 73); \ + break; \ + } \ + if (p) \ + { \ + ops \ + } \ + } \ + va_end (ap); \ + } \ +} |