🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #861

Re: Bug on SUN4 with -O option

#861
From: Urs Hoelzle
Date: Fri, 21 Aug 1992 16:44
62 lines
2217 bytes
In gnu.g++.bug you write:

>   The following program has a SEGV when compiled with -O option on SUN4C
>  ( SunOs 4.1.1 ).
>

I think I just hit the same bug.  The problem is that teh delay slot
of a conditional branch is filled with an instruction that faults when
the condition is true.  Here's a small example:

struct A {
  virtual void print() { printf("xxx"); }
  void f();
};

void A::f() {
  if (this) {
    print();
  } else {
    printf("0");
  }
}

g++ -v -O -S x.c
Reading specs from /home/super/local/lib/gcc-lib/sparc-sun-sunos4.1/2.2.2/specs
gcc version 2.2.2
 /home/super/local/lib/gcc-lib/sparc-sun-sunos4.1/2.2.2/cpp -lang-c++ -v -undef\
 -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -Dsparc -Dsun -Dunix -D__sparc__ -D__s\
un__ -D__unix__ -D__sparc -D__sun -D__unix -D__OPTIMIZE__ x.c /usr/tmp/cca04347\
.i
GNU CPP version 2.2.2 (sparc)
 /home/super/local/lib/gcc-lib/sparc-sun-sunos4.1/2.2.2/cc1plus /usr/tmp/cca043\
47.i -quiet -dumpbase x.cc -O -version -o x.s
GNU C++ version 2.2.2 (sparc) compiled by GNU C version 2.2.2.

And here's the code generated for A::f:

_f__1A:
    !#PROLOGUE# 0
    save %sp,-112,%sp
    !#PROLOGUE# 1
    cmp %i0,0
    be L6
    ld [%i0],%o1      <---- this is wrong!  will deref this if this==0
    ldsh [%o1+8],%o0
    ld [%o1+12],%o1
    call %o1,0
    add %i0,%o0,%o0
    b,a L8
L6:
    sethi %hi(LC1),%o0
    call _printf,0
    or %o0,%lo(LC1),%o0
L8:
    ret
    restore

-Urs

----------------------------------------------------------------------------
Urs Hoelzle                                              urs@cs.stanford.EDU
Computer Systems Laboratory, CIS 57, Stanford University, Stanford, CA 94305
Technical Details
Message-ID: <hoelzle.714415465@Xenon.Stanford.EDU>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!xenon.stanford.edu!hoelzle
References: <9208141030.AA03717@rechser.total.fr.recherche>

Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!xenon.stanford.edu!hoelzle
From: hoelzle@xenon.stanford.edu (Urs Hoelzle)
Subject: Re: Bug on SUN4 with -O option
Message-ID: <hoelzle.714415465@Xenon.Stanford.EDU>
Sender: gnulists@ai.mit.edu
Organization: CS Department, Stanford University, California, USA
References: <9208141030.AA03717@rechser.total.fr.recherche>
Distribution: gnu
Date: Fri, 21 Aug 1992 16:44:25 GMT
Approved: bug-g++@prep.ai.mit.edu
Lines: 64