[gnu.g++.bug] incorrect code gen'd for destructor?

rpj%cadillac.cad.mcc.com@MCC.COM (Rich Johns) (02/13/90)

sun3 OS4.03
g++1.36.4 (from tar 1/31/90 off labrea)


Micheal, I'm seeing some strange behavior in the following destructor,
(which worked fine 2 or 3 compilers ago). I am getting a segmentation
violation at the line indicated by "-->" (line # 419). In this case,
behavior is 0.  Doing a 'delete 0' is legal, right? Right.  So, seeing
no reason for a segv I am suspicious that incorrect code is getting
generated.  Could you have a look? Please find below some gdb output
that should be helpful. Farther below is an assembly listing. I
realize that this destructor suffers tremendously, but I am forced to
live with it for the time being. 

Selection::~Selection () {
  printf ("~Selection, type of icon %i\n", type);
  DeleteHandles();
  SetBtag(nil);                  
  delete contacts;
  
  switch (type) {
  case PRIMITIVE:                  
    printf("just before del on Primitive behavior\n");
--> delete behavior;
    break;
  case MODEL:  case SUBMODEL:           
    for (First(); !AtEnd(); Next()) {
      printf("going through Model\n");
      ((Selection*) GetCurrent())->SetBehavior(nil);
    }
    printf("just before del model behavior\n");
    delete behavior;
    break;
  }
  if (header) { 
    if (header->GetStatus() == UNEXPOSED_MOD || header->GetStatus() == UNEXPOSED_UNMOD) {
      delete header;
    }
  }
  SetLabelstring(nil);   
  delete iattributes;    
}

-----debug session------------------ 

It appears that register a3 holds the address of the Selection object.
Register a2 is getting loaded with the behavior field of the Selection
object. With behavior being 0, the 'tstl a2@' is segv'ing.


 Bpt 3, 0x2649e in _$_Selection ($this=(Selection *) 0x147520, __in$charge__=1) (selection.cc line 419)
419         delete behavior;
(gdb) display/i $pc
1: x/i $pc  0x2649e <_$_Selection+104>: tstl a3@(56)
(gdb) print $a3
$29 = 1340704
(gdb) print/x $a3
$30 = 0x00147520
(gdb) print/x *($a3 + 56)
$31 = 0x00000000
(gdb) stepi
0x264a2 419         delete behavior;
1: x/i $pc  0x264a2 <_$_Selection+108>: beq 0x264be <_$_Selection+136>
(gdb) stepi
0x264be 419         delete behavior;
1: x/i $pc  0x264be <_$_Selection+136>: moveal a3@(56),a2
(gdb) stepi
0x264c2 419         delete behavior;
1: x/i $pc  0x264c2 <_$_Selection+140>: tstl a2@
(gdb) print $a2
$32 = 0
(gdb) stepi

Program received signal 11, Segmentation fault
0x264c2 in _$_Selection ($this=(Selection *) 0x147520, __in$charge__=1) (selection.cc line 419)
419         delete behavior;
1: x/i $pc  0x264c2 <_$_Selection+140>: tstl a2@


----------- assembly------------------

0x2643a <_$_Selection+4>:       moveml a2-a3,sp@-
0x2643e <_$_Selection+8>:       moveal fp@(8),a3
0x26442 <_$_Selection+12>:      movel a3@(80),sp@-
0x26446 <_$_Selection+16>:      pea 0x263bc <CreateModelAtt__9Selectioni+248>
0x2644a <_$_Selection+20>:      bsr 0xb2d70 <printf>
0x26450 <_$_Selection+26>:      movel a3,sp@-
0x26452 <_$_Selection+28>:      bsr 0x28b58 <DeleteHandles__9Selection>
---Type <return> to continue---
0x26456 <_$_Selection+32>:      clrl sp@-
0x26458 <_$_Selection+34>:      movel a3,sp@-
0x2645a <_$_Selection+36>:      bsr 0x265f0 <SetBtag__9SelectionPCc>
0x2645e <_$_Selection+40>:      addaw #20,sp
0x26462 <_$_Selection+44>:      tstl a3@(64)
0x26466 <_$_Selection+48>:      beq 0x26478 <_$_Selection+66>
0x26468 <_$_Selection+50>:      pea @#0x1 <_DYNAMIC+1>
0x2646c <_$_Selection+54>:      movel a3@(64),sp@-
0x26470 <_$_Selection+58>:      bsr 0x1d17c <_$_BaseList>
---Type <return> to continue---
0x26476 <_$_Selection+64>:      addqw #8,sp
0x26478 <_$_Selection+66>:      movel a3@(80),d0
0x2647c <_$_Selection+70>:      movel #1,d1
0x2647e <_$_Selection+72>:      cmpl d0,d1
0x26480 <_$_Selection+74>:      bgt 0x26576 <_$_Selection+320>
0x26484 <_$_Selection+78>:      movel #2,d1
0x26486 <_$_Selection+80>:      cmpl d0,d1
0x26488 <_$_Selection+82>:      bge 0x264ea <_$_Selection+180>
0x2648a <_$_Selection+84>:      movel #3,d1
---Type <return> to continue---
0x2648c <_$_Selection+86>:      cmpl d0,d1
0x2648e <_$_Selection+88>:      bne 0x26576 <_$_Selection+320>
0x26492 <_$_Selection+92>:      pea 0x263d9 <CreateModelAtt__9Selectioni+277>
0x26496 <_$_Selection+96>:      bsr 0xb2d70 <printf>
0x2649c <_$_Selection+102>:     addqw #4,sp
0x2649e <_$_Selection+104>:     tstl a3@(56)
0x264a2 <_$_Selection+108>:     beq 0x264be <_$_Selection+136>
0x264a4 <_$_Selection+110>:     moveal a3@(56),a1
0x264a8 <_$_Selection+114>:     moveal a1@,a0
---Type <return> to continue---
0x264aa <_$_Selection+116>:     moveal a0@,a0
0x264ac <_$_Selection+118>:     clrl sp@-
0x264ae <_$_Selection+120>:     moveaw a0@(8),a2
0x264b2 <_$_Selection+124>:     addal a1@,a2
0x264b4 <_$_Selection+126>:     movel a2,sp@-
0x264b6 <_$_Selection+128>:     moveal a0@(12),a0
0x264ba <_$_Selection+132>:     jsr a0@
0x264bc <_$_Selection+134>:     addqw #8,sp
0x264be <_$_Selection+136>:     moveal a3@(56),a2
---Type <return> to continue---
0x264c2 <_$_Selection+140>:     tstl a2@
0x264c4 <_$_Selection+142>:     beq 0x264dc <_$_Selection+166>
0x264c6 <_$_Selection+144>:     moveal a2@,a0
0x264c8 <_$_Selection+146>:     moveal a0@,a0
0x264ca <_$_Selection+148>:     clrl sp@-
0x264cc <_$_Selection+150>:     moveaw a0@(8),a1
0x264d0 <_$_Selection+154>:     addal a2@,a1
0x264d2 <_$_Selection+156>:     movel a1,sp@-
0x264d4 <_$_Selection+158>:     moveal a0@(12),a0


thanks.