diff options
author | Per Bothner <per@bothner.com> | 1992-08-05 04:15:37 +0000 |
---|---|---|
committer | Per Bothner <per@bothner.com> | 1992-08-05 04:15:37 +0000 |
commit | 917bffa7f6dd3a04195a790595a2088683386227 (patch) | |
tree | fb5e23a8c1dcef367ae67cc63fed7ea9b45fe0f2 /ld | |
parent | c7a535938ed0ac4a601897462e0012ed7b2430e1 (diff) | |
download | gdb-917bffa7f6dd3a04195a790595a2088683386227.zip gdb-917bffa7f6dd3a04195a790595a2088683386227.tar.gz gdb-917bffa7f6dd3a04195a790595a2088683386227.tar.bz2 |
* cdtest-main.cc, cdtest-func.cc, cdtest-foo.h, cdtest-foo.cc,
cdtest.exp: A test program (copied from libg++/test-install)
that tests that constructor and destructors are handled
corrrectly.
Diffstat (limited to 'ld')
-rw-r--r-- | ld/.Sanitize | 13 | ||||
-rw-r--r-- | ld/ChangeLog | 7 | ||||
-rw-r--r-- | ld/Makefile.in | 21 | ||||
-rw-r--r-- | ld/cdtest-foo.cc | 89 | ||||
-rw-r--r-- | ld/cdtest-foo.h | 24 | ||||
-rw-r--r-- | ld/cdtest-func.cc | 17 | ||||
-rw-r--r-- | ld/cdtest-main.cc | 40 | ||||
-rw-r--r-- | ld/cdtest.exp | 15 |
8 files changed, 222 insertions, 4 deletions
diff --git a/ld/.Sanitize b/ld/.Sanitize index 122d6df..a874fc0 100644 --- a/ld/.Sanitize +++ b/ld/.Sanitize @@ -34,6 +34,11 @@ README a29k.sc-sh a29k.sh aout.sc-sh +cdtest-foo.cc +cdtest-foo.h +cdtest-func.cc +cdtest-main.cc +cdtest.exp config config.h configure.bat @@ -117,7 +122,13 @@ echo Done in `pwd`. # # # $Log$ -# Revision 1.37 1992/05/02 02:08:16 sac +# Revision 1.38 1992/08/05 04:15:24 bothner +# * cdtest-main.cc, cdtest-func.cc, cdtest-foo.h, cdtest-foo.cc, +# cdtest.exp: A test program (copied from libg++/test-install) +# that tests that constructor and destructors are handled +# corrrectly. +# +# Revision 1.37 1992/05/02 02:08:16 sac # New stuff for 29200 # # Revision 1.36 1992/05/01 22:08:40 sac diff --git a/ld/ChangeLog b/ld/ChangeLog index b7bf2d0..10ce196 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,10 @@ +Tue Aug 4 21:12:29 1992 Per Bothner (bothner@rtl.cygnus.com) + + * cdtest-main.cc, cdtest-func.cc, cdtest-foo.h, cdtest-foo.cc, + cdtest.exp: A test program (copied from libg++/test-install) + that tests that constructor and destructors are handled + corrrectly. + Mon Aug 3 14:58:19 1992 david d `zoo' zuhn (zoo at cirdan.cygnus.com) * Makefile.in (install): install from ld.new, renaming during the diff --git a/ld/Makefile.in b/ld/Makefile.in index e9c98b0..3d54a64 100644 --- a/ld/Makefile.in +++ b/ld/Makefile.in @@ -64,6 +64,8 @@ version= # Seach path to override the default search path for -lfoo libraries. # If LIB_PATH is empty, the ones in the script (if any) are left alone. +# (The default is usually /lib:usr/lib:/usr/local/lib, unless building +# a cross-linker, in which case the default is empty. See genscripts.sh.) # Otherwise, they are replaced with the ones given in LIB_PATH, # which may have the form: LIB_PATH=/lib:/usr/local/lib LIB_PATH = @@ -90,16 +92,21 @@ HOSTING_CRT0=/lib/crt0.o HOSTING_LIBS=`if [ -f ../gcc/libgcc.a ] ; then echo ../gcc/libgcc.a ; else echo $(libdir)/libgcc.a; fi` -lc HOSTING_EMU=LDEMULATION=$(EMUL); export LDEMULATION +C++ = g++ -fgnu-linker + ### Host, target, and site specific Makefile fragments come in here. ### LINTFLAGS = $(INCLUDES) $(EXTRA_DEF) -.SUFFIXES: .y .x .xr .xu .xn .xbn .sc .scu .scr .scn $(SUFFIXES) +.SUFFIXES: .y .x .xr .xu .xn .xbn .sc .scu .scr .scn $(SUFFIXES) .cc .c.o: $(CC) -c $(CFLAGS) $(INCLUDES) $(HDEFINES) $(TDEFINES) $(CDEFINES) $< +.cc.o: + $(C++) -c $(CFLAGS) -I$(srcdir) $< + # go directly to ld.new in case this ld isn't capable of # linking native object on this host. It can be renamed on # install. @@ -145,7 +152,7 @@ STAGESTUFF = *.x *.x[runN] *.sc[runN] $(GENERATED_SOURCES) $(GENERATED_HEADERS) all: Makefile $(LD_PROG) -check: bootstrap +check: bootstrap check-cdtest info: ld.info ldgram.h ldgram.c: ldgram.y @@ -252,6 +259,14 @@ ld3: ld2 bootstrap: ld3 cmp ld2 ld3 +cdtest: cdtest-main.o cdtest-func.o cdtest-foo.o + $(HOSTING_EMU); ./ld.new -o cdtest $(HOSTING_CRT0) \ + cdtest-main.o cdtest-func.o cdtest-foo.o $(HOSTING_LIBS) + +check-cdtest: cdtest $(srcdir)/cdtest.exp + ./cdtest >cdtest.out + diff $(srcdir)/cdtest.exp cdtest.out + ###################################################################### # DOCUMENTATION TARGETS # TeX output @@ -391,7 +406,7 @@ de-stage3: force clean: -rm -f TAGS $(STAGESTUFF) -rm -f ld.?? ld.??? ldlex.[qp] - -rm -f ld ld1 ld2 ld3 *.o y.output + -rm -f ld ld1 ld2 ld3 *.o y.output cdtest cdtest.out lintlog:$(SOURCES) Makefile $(LINT) -abhxzn $(LINTFLAGS) $(LINTSOURCES) \ diff --git a/ld/cdtest-foo.cc b/ld/cdtest-foo.cc new file mode 100644 index 0000000..f29930f --- /dev/null +++ b/ld/cdtest-foo.cc @@ -0,0 +1,89 @@ +// Class Foo +//#pragma implementation + + +// We don't use header files, since we only want to see, whether the +// compiler is installed properly. +// +#if (__GNUG__ == 2) +typedef __SIZE_TYPE__ size_t; +#else +typedef unsigned int size_t; +#endif + +extern "C" { + char *strncpy (char* dest, const char* dest, size_t len); + int printf (const char*, ...); +}; + +#include "cdtest-foo.h" + +int Foo::foos = 0; + +void Foo::init_foo () +{ + printf ("BROKENLY calling Foo::init_foo from __init_start; size_of(Foo) = %d\n", sizeof(Foo)); + foos = FOOLISH_NUMBER; +} + + +Foo::Foo () +{ + i = ++foos; + strncpy (message, "default-foo", len); +#ifdef WITH_ADDR + printf ("Constructing Foo(%d) \"default-foo\" at %08x\n", i, this); +#else + printf ("Constructing Foo(%d) \"default-foo\"\n", i); +#endif +} + +Foo::Foo (char* msg) +{ + i = ++foos; + strncpy( message, msg, len); +#ifdef WITH_ADDR + printf ( "Constructing Foo(%d) \"%s\" at %08x\n", i, message, this); +#else + printf ( "Constructing Foo(%d) \"%s\"\n", i, message); +#endif +} + + +Foo::Foo (const Foo& foo) +{ + i = ++foos; +#ifdef WITH_ADDR + printf ("Initializing Foo(%d) \"%s\" at %08x with Foo(%d) %08x\n", + i, foo.message, this, foo.i, &foo); +#else + printf ("Initializing Foo(%d) \"%s\" with Foo(%d)\n",i, foo.message, foo.i); +#endif + for ( int k = 0; k < FOO_MSG_LEN; k++) message[k] = foo.message[k]; +} + + +Foo& Foo::operator= (const Foo& foo) +{ +#ifdef WITH_ADDR + printf ("Copying Foo(%d) \"%s\" at %08x to Foo(%d) %08x\n", + foo.i, foo.message, &foo, i, this); +#else + printf ("Copying Foo(%d) \"%s\" to Foo(%d)\n", foo.i, foo.message, i); +#endif + for ( int k = 0; k < FOO_MSG_LEN; k++) message[k] = foo.message[k]; + return *this; +} + + +Foo::~Foo () +{ + foos--; +#ifdef WITH_ADDR + printf ("Destructing Foo(%d) \"%s\" at %08x (remaining foos: %d)\n", + i, message, this, foos); +#else + printf ("Destructing Foo(%d) \"%s\" (remaining foos: %d)\n", + i, message, foos); +#endif +} diff --git a/ld/cdtest-foo.h b/ld/cdtest-foo.h new file mode 100644 index 0000000..0ba2d37 --- /dev/null +++ b/ld/cdtest-foo.h @@ -0,0 +1,24 @@ +// Class Foo + +#pragma interface + +#define FOOLISH_NUMBER -4711 + +#ifndef FOO_MSG_LEN +#define FOO_MSG_LEN 80 +#endif + +class Foo { + static int foos; + int i; + const len = FOO_MSG_LEN; + char message[len]; +public: + static void init_foo (); + static int nb_foos() { return foos; } + Foo(); + Foo( char* message); + Foo(const Foo&); + Foo & operator= (const Foo&); + ~Foo (); +}; diff --git a/ld/cdtest-func.cc b/ld/cdtest-func.cc new file mode 100644 index 0000000..79000e3 --- /dev/null +++ b/ld/cdtest-func.cc @@ -0,0 +1,17 @@ +// test program for Class Foo + +#include "cdtest-foo.h" + +static Foo static_foo( "static_foo"); + +Foo f() +{ + Foo x; + return x; +} + +void g() +{ + Foo other_foo1 = Foo( "other_foo1"), other_foo2 = Foo( "other_foo2"); + other_foo2 = other_foo1; +} diff --git a/ld/cdtest-main.cc b/ld/cdtest-main.cc new file mode 100644 index 0000000..4b99b5c --- /dev/null +++ b/ld/cdtest-main.cc @@ -0,0 +1,40 @@ +// main program for Class Foo + +extern "C" { +// Some <assert.h> implementations (e.g. SUNOS 4.1) are broken, +// in that they require <stdio.h>. But, if gcc/g++ is installed +// correctly, you should get gcc's assert.h. +// If the compile fails, it means the wrong include files are in use! +#include <assert.h> +}; +#include "cdtest-foo.h" + +extern "C" void __init_start(); + +extern Foo f(void); +extern void g(void); + +/* This function should *not* be called by the environment. There is + no way in C++ to ``run something after the initializers but before main()''. + The library that depends on this (NIHCL) is broken. -- John Gilmore + We leave this here to test that future changes to the compiler + do not re-introduce this losing ``feature''. */ +void +__init_start() +{ + Foo::init_foo(); +} + +static Foo static_foo( "static_foo"); + +main() +{ + assert (Foo::nb_foos() == 2); + Foo automatic_foo( "automatic_foo"); + Foo bla_foo = f(); + assert (Foo::nb_foos() == 4); + g(); + assert (Foo::nb_foos() == 4); + // `automatic_foo' and `bla_foo' are destructed here +} + diff --git a/ld/cdtest.exp b/ld/cdtest.exp new file mode 100644 index 0000000..39be0db --- /dev/null +++ b/ld/cdtest.exp @@ -0,0 +1,15 @@ +Constructing Foo(1) "static_foo" +Constructing Foo(2) "static_foo" +Constructing Foo(3) "automatic_foo" +Constructing Foo(4) "default-foo" +Initializing Foo(5) "default-foo" with Foo(4) +Destructing Foo(4) "default-foo" (remaining foos: 4) +Constructing Foo(5) "other_foo1" +Constructing Foo(6) "other_foo2" +Copying Foo(5) "other_foo1" to Foo(6) +Destructing Foo(6) "other_foo1" (remaining foos: 5) +Destructing Foo(5) "other_foo1" (remaining foos: 4) +Destructing Foo(5) "default-foo" (remaining foos: 3) +Destructing Foo(3) "automatic_foo" (remaining foos: 2) +Destructing Foo(2) "static_foo" (remaining foos: 1) +Destructing Foo(1) "static_foo" (remaining foos: 0) |