[gnu.g++.bug] objects not created/destroyed

rjc@CS.UCLA.EDU (Robert Collins) (01/08/90)

Sun4/330, SunOS 4.0.3, latest version of g++-1.36.2

Michael,

Here is a short piece of code, it's compilation and execution, and the
assembler produced for the code.

The code calculates the size of an array of objects, and creates the array.
The bug is that the array is not created (nor destroyed).  This was not
any easy one to track down--naturally the program didn't just die
immediately nor consistently...things are never that easy...

Thanks,
rob collins
rjc@cs.ucla.edu


Script started on Sun Jan  7 18:39:08 1990
pollux% cat a.cc
#include <stdio.h>

class foo {
  private:
    int i;
  public:
    foo(int i = 1);
    ~foo();
};

foo::foo(int init) : i(init) { printf("constructing foo\n"); }
foo::~foo() { printf("destructing foo\n"); }

void bar(const float, const unsigned);

main()
{
    bar(5.3, 1);
}

void bar(const float r, unsigned i)
{
    unsigned n = (unsigned) (r * (float) i);
    foo k[n];
}
    
pollux% g++ -v a.cc
g++ version 1.36.2 (based on GCC 1.36)
 /usr/local/lib/gcc-cpp -+ -v -undef -D__GNUC__ -D__GNUG__ -D__cplusplus -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ a.cc /usr/tmp/cca01001.cpp
GNU CPP version 1.36.91
 /usr/local/lib/gcc-cc1plus /usr/tmp/cca01001.cpp -quiet -dumpbase a.cc -version -o /usr/tmp/cca01001.s
GNU C++ version 1.36.2 (based on GCC 1.36) (sparc) compiled by GNU C version 1.36.
default target switches: -mfpu -mepilogue
 /usr/local/lib/gcc-as -o a.o /usr/tmp/cca01001.s
 /usr/local/lib/gcc-ld -e start -dc -dp /lib/crt0.o a.o -lg++ /usr/local/lib/gcc-gnulib -lc
pollux% a.out
pollux% g++ -S a.cc
pollux% cat a.s
gcc_compiled.:
.text
LC0:
	.ascii "constructing foo\12\0"
	.align 4
.global ___3fooi
	.proc 1
___3fooi:
	!#PROLOGUE# 0
	save %sp,-112,%sp
	!#PROLOGUE# 1
	mov %i0,%l0
	st %i1,[%fp+72]
	ld [%fp+72],%o1
	st %o1,[%l0]
	sethi %hi(LC0),%o0
	or %lo(LC0),%o0,%o0
	call _printf,0
	nop
	mov %l0,%i0
L1:
	ret
	restore
LC1:
	.ascii "destructing foo\12\0"
	.align 4
.global __$_foo
	.proc 1
__$_foo:
	!#PROLOGUE# 0
	save %sp,-112,%sp
	!#PROLOGUE# 1
	mov %i0,%l0
	st %i1,[%fp+72]
	sethi %hi(LC1),%o0
	or %lo(LC1),%o0,%o0
	call _printf,0
	nop
L3:
	ld [%fp+72],%o0
	tst %o0
	be L4
	nop
	mov %l0,%o0
	call ___builtin_delete,0
	nop
	b L5
	nop
L4:
L5:
L2:
	ret
	restore
	.align 4
LC2:
	.single 0r5.29999999999999982236e+00
	.align 4
.global _main
	.proc 1
_main:
	!#PROLOGUE# 0
	save %sp,-112,%sp
	!#PROLOGUE# 1
	call ___main,0
	nop
	mov %o0,%o0
	sethi %hi(LC2),%g1
	ld [%g1+%lo(LC2)],%o0
	mov 1,%o1
	call _bar__FfUi,0
	nop
	mov 0,%i0
	b L6
	nop
L6:
	ret
	restore
	.align 4
LC3:
	.single 0r4.29496729600000000000e+09
	.align 4
.global _bar__FfUi
	.proc 1
_bar__FfUi:
	!#PROLOGUE# 0
	save %sp,-120,%sp
	!#PROLOGUE# 1
	st %g0,[%fp-16]
	st %g0,[%fp-12]
	st %i0,[%fp+68]
	st %i1,[%fp+72]
	ld [%fp+72],%f2
	fitos %f2,%f2
	ld [%fp-16],%f0
	fcmpes %f2,%f0
	nop
	fbge L8
	nop
	sethi %hi(LC3),%g1
	ld [%g1+%lo(LC3)],%f3
	fadds %f2,%f3,%f2
L8:
	ld [%fp+68],%f3
	fmuls %f2,%f3,%f2
	fstod %f2,%f2
	std %f2,[%fp-8]
	ldd [%fp-8],%o0
	call ___fixunsdfsi,0
	nop
	st %o0,[%fp-20]
	ld [%fp-20],%o0
	sll %o0,2,%l0
	mov %sp,%l1
	mov %l0,%o0
	add %o0,7,%o1
	srl %o1,3,%o0
	sll %o0,3,%o0
	sub %sp,%o0,%sp
	mov %sp,%l2
	add %l2,92,%l2
	mov 0,%l3
	mov %l2,%l3
	mov %l2,%l4
	ld [%fp-20],%o0
	add %o0,-1,%l5
	tst %l5
	bl L9
	nop
L10:
	mov %l4,%o0
	mov 1,%o1
	call ___3fooi,0
	nop
	add %l4,4,%l4
L12:
	add %l5,-1,%l5
	cmp %l5,-1
	be L11
	nop
	b L10
	nop
L11:
L9:
	ld [%fp-20],%o0
	add %o0,-1,%l6
	tst %l6
	bl L13
	nop
	ld [%fp-20],%o0
	add %o0,-1,%o0
	add %o0,1,%o0
	sll %o0,2,%o0
	add %l2,%o0,%l7
L14:
	add %l7,-4,%l7
	tst %l7
	be L17
	nop
	mov %l7,%o0
	mov 0,%o1
	call __$_foo,0
	nop
	b L18
	nop
L17:
L18:
L16:
	add %l6,-1,%l6
	cmp %l6,-1
	be L15
	nop
	b L14
	nop
L15:
L13:
	mov %l1,%sp
L7:
	ret
	restore
pollux% 
script done on Sun Jan  7 18:40:21 1990

tiemann@AI.MIT.EDU (Micheal Tiemann) (01/08/90)

   Date: Sun, 7 Jan 90 18:48:54 -0800
   From: rjc@cs.ucla.edu (Robert Collins)

   Sun4/330, SunOS 4.0.3, latest version of g++-1.36.2

   Michael,

   Here is a short piece of code, it's compilation and execution, and the
   assembler produced for the code.

   The code calculates the size of an array of objects, and creates the array.
   The bug is that the array is not created (nor destroyed).  This was not
   any easy one to track down--naturally the program didn't just die
   immediately nor consistently...things are never that easy...

   Thanks,
   rob collins
   rjc@cs.ucla.edu


   Script started on Sun Jan  7 18:39:08 1990
   pollux% cat a.cc
   #include <stdio.h>

   class foo {
     private:
       int i;
     public:
       foo(int i = 1);
       ~foo();
   };

   foo::foo(int init) : i(init) { printf("constructing foo\n"); }
   foo::~foo() { printf("destructing foo\n"); }

   void bar(const float, const unsigned);

   main()
   {
       bar(5.3, 1);
   }

   void bar(const float r, unsigned i)
   {
       unsigned n = (unsigned) (r * (float) i);
       foo k[n];
   }

   pollux% g++ -v a.cc
   g++ version 1.36.2 (based on GCC 1.36)
    /usr/local/lib/gcc-cpp -+ -v -undef -D__GNUC__ -D__GNUG__ -D__cplusplus -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ a.cc /usr/tmp/cca01001.cpp
   GNU CPP version 1.36.91
    /usr/local/lib/gcc-cc1plus /usr/tmp/cca01001.cpp -quiet -dumpbase a.cc -version -o /usr/tmp/cca01001.s
   GNU C++ version 1.36.2 (based on GCC 1.36) (sparc) compiled by GNU C version 1.36.
   default target switches: -mfpu -mepilogue
    /usr/local/lib/gcc-as -o a.o /usr/tmp/cca01001.s
    /usr/local/lib/gcc-ld -e start -dc -dp /lib/crt0.o a.o -lg++ /usr/local/lib/gcc-gnulib -lc
   pollux% a.out
   pollux% g++ -S a.cc
   pollux% cat a.s
   gcc_compiled.:
   .text
   LC0:
	   .ascii "constructing foo\12\0"
	   .align 4
   .global ___3fooi
	   .proc 1
   ___3fooi:
	   !#PROLOGUE# 0
	   save %sp,-112,%sp
	   !#PROLOGUE# 1
	   mov %i0,%l0
	   st %i1,[%fp+72]
	   ld [%fp+72],%o1
	   st %o1,[%l0]
	   sethi %hi(LC0),%o0
	   or %lo(LC0),%o0,%o0
	   call _printf,0
	   nop
	   mov %l0,%i0
   L1:
	   ret
	   restore
   LC1:
	   .ascii "destructing foo\12\0"
	   .align 4
   .global __$_foo
	   .proc 1
   __$_foo:
	   !#PROLOGUE# 0
	   save %sp,-112,%sp
	   !#PROLOGUE# 1
	   mov %i0,%l0
	   st %i1,[%fp+72]
	   sethi %hi(LC1),%o0
	   or %lo(LC1),%o0,%o0
	   call _printf,0
	   nop
   L3:
	   ld [%fp+72],%o0
	   tst %o0
	   be L4
	   nop
	   mov %l0,%o0
	   call ___builtin_delete,0
	   nop
	   b L5
	   nop
   L4:
   L5:
   L2:
	   ret
	   restore
	   .align 4
   LC2:
	   .single 0r5.29999999999999982236e+00
	   .align 4
   .global _main
	   .proc 1
   _main:
	   !#PROLOGUE# 0
	   save %sp,-112,%sp
	   !#PROLOGUE# 1
	   call ___main,0
	   nop
	   mov %o0,%o0
	   sethi %hi(LC2),%g1
	   ld [%g1+%lo(LC2)],%o0
	   mov 1,%o1
	   call _bar__FfUi,0
	   nop
	   mov 0,%i0
	   b L6
	   nop
   L6:
	   ret
	   restore
	   .align 4
   LC3:
	   .single 0r4.29496729600000000000e+09
	   .align 4
   .global _bar__FfUi
	   .proc 1
   _bar__FfUi:
	   !#PROLOGUE# 0
	   save %sp,-120,%sp
	   !#PROLOGUE# 1
	   st %g0,[%fp-16]
	   st %g0,[%fp-12]
	   st %i0,[%fp+68]
	   st %i1,[%fp+72]
	   ld [%fp+72],%f2
	   fitos %f2,%f2
	   ld [%fp-16],%f0
	   fcmpes %f2,%f0
	   nop
	   fbge L8
	   nop
	   sethi %hi(LC3),%g1
	   ld [%g1+%lo(LC3)],%f3
	   fadds %f2,%f3,%f2
   L8:
	   ld [%fp+68],%f3
	   fmuls %f2,%f3,%f2
	   fstod %f2,%f2
	   std %f2,[%fp-8]
	   ldd [%fp-8],%o0
	   call ___fixunsdfsi,0
	   nop
	   st %o0,[%fp-20]
	   ld [%fp-20],%o0
	   sll %o0,2,%l0
	   mov %sp,%l1
	   mov %l0,%o0
	   add %o0,7,%o1
	   srl %o1,3,%o0
	   sll %o0,3,%o0
	   sub %sp,%o0,%sp
	   mov %sp,%l2
	   add %l2,92,%l2
	   mov 0,%l3
	   mov %l2,%l3
	   mov %l2,%l4
	   ld [%fp-20],%o0
	   add %o0,-1,%l5
	   tst %l5
	   bl L9
	   nop
   L10:
	   mov %l4,%o0
	   mov 1,%o1
	   call ___3fooi,0
	   nop
	   add %l4,4,%l4
   L12:
	   add %l5,-1,%l5
	   cmp %l5,-1
	   be L11
	   nop
	   b L10
	   nop
   L11:
   L9:
	   ld [%fp-20],%o0
	   add %o0,-1,%l6
	   tst %l6
	   bl L13
	   nop
	   ld [%fp-20],%o0
	   add %o0,-1,%o0
	   add %o0,1,%o0
	   sll %o0,2,%o0
	   add %l2,%o0,%l7
   L14:
	   add %l7,-4,%l7
	   tst %l7
	   be L17
	   nop
	   mov %l7,%o0
	   mov 0,%o1
	   call __$_foo,0
	   nop
	   b L18
	   nop
   L17:
   L18:
   L16:
	   add %l6,-1,%l6
	   cmp %l6,-1
	   be L15
	   nop
	   b L14
	   nop
   L15:
   L13:
	   mov %l1,%sp
   L7:
	   ret
	   restore
   pollux% 
   script done on Sun Jan  7 18:40:21 1990

Not a bug in g++.ztar.Z put on trix.ai.mit.edu (128.52.32.6) this
morning.  Please use that as "latest test release".

Michael