🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #6074

optimizer fails in 2.7.2

#6074
From: Nathan Sidwell
Date: Mon, 16 Dec 1996 00:00
152 lines
5500 bytes
Hi,
gcc 2.7.2 for sparc produces incorrect code at -O2 optimization.

the system is an ultrasparc running Solaris 2.5. gcc is targeting
generic sparc.

here is the source code (anotated failed source line)
--start failed source
#include <stdio.h>

struct A {
int member;
};
static int _10_access_as_FC1A_si_2_PcC1A_sic(struct A *const _this, int
const
_val);

static int _3set_FC1A_si_2_PcC1A_sic(struct A *const _this, int const
_val);

static int _10_access_as_FC1A_si_2_PcC1A_sic(struct A *const _this, int
const
_val) 
{
        _this->member = _val;
  return _this->member;
}
static int _3set_FC1A_si_2_PcC1A_sic(struct A *const _this, int const
_val)
{
        _this->member = _val;
  return _val;
}
        
extern int main(int __unused_2_hello, char **__unused_3_hello)
{
  auto struct A const *_arg_7_hello;
  auto struct A _a_13_hello;
int t;
      _3set_FC1A_si_2_PcC1A_sic(&_a_13_hello, 5);     
  
      printf((char const *)"a access is %d\n",
          (_arg_7_hello = &_a_13_hello, _arg_7_hello->member));

      _10_access_as_FC1A_si_2_PcC1A_sic(&_a_13_hello, 10);
      
t = _a_13_hello.member; /* this source line goes wrong */

      printf((char const *)"a access is %d\n", t);
  return 0;
}     
-- end failed source
As you might guess this came out of a program generator.

The compile log is
-- start compile log
nathan@finlandia:383>gcc -O2 foo.c -o foo -v
Reading specs from
/inmos/gnu/sparc-sun-solaris2.4/lib/gcc-lib/sparc-sun-solaris2.4/2.7.2/specs
gcc version 2.7.2

/inmos/gnu/sparc-sun-solaris2.4/lib/gcc-lib/sparc-sun-solaris2.4/2.7.2/cpp
-lang-c89 -v -undef -D__GNUC__=2 -D__GNUC_MINOR__=7 -trigraphs -$
-D__STRICT_ANSI__ -D__sun__ -D__sparc__ -D__unix__ -D__svr4__ -D__SVR4
-D__GCC_NEW_VARARGS__ -D__sun -D__sparc -D__unix -Asystem(unix)
-Asystem(svr4) -Acpu(sparc) -Amachine(sparc) -D__OPTIMIZE__ -Wall
-Wpointer-arith -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes
foo.c /var/tmp/cca002Rr.i
GNU CPP version 2.7.2 (sparc)
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /inmos/gnu/sparc-sun-solaris2.4/sparc-sun-solaris2.4/include

/inmos/gnu/sparc-sun-solaris2.4/lib/gcc-lib/sparc-sun-solaris2.4/2.7.2/include
 /usr/include
End of search list.

/inmos/gnu/sparc-sun-solaris2.4/lib/gcc-lib/sparc-sun-solaris2.4/2.7.2/cc1
/var/tmp/cca002Rr.i -quiet -dumpbase foo.c -O2 -Wall -Wpointer-arith
-Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -ansi -version
-o /var/tmp/cca002Rr.s
GNU C version 2.7.2 (sparc) compiled by GNU C version 2.7.2.
 /usr/ccs/bin/as -V -Qy -s -o /var/tmp/cca002Rr1.o /var/tmp/cca002Rr.s
/usr/ccs/bin/as: SC4.0 dev 15 Feb 1995
 /usr/ccs/bin/ld -V -Y P,/usr/ccs/lib:/usr/lib -Qy -o foo
/inmos/gnu/sparc-sun-solaris2.4/lib/gcc-lib/sparc-sun-solaris2.4/2.7.2/crt1.o
/inmos/gnu/sparc-sun-solaris2.4/lib/gcc-lib/sparc-sun-solaris2.4/2.7.2/crti.o
/usr/ccs/lib/values-Xc.o
/inmos/gnu/sparc-sun-solaris2.4/lib/gcc-lib/sparc-sun-solaris2.4/2.7.2/crtbegin.o
-L/inmos/gnu/sparc-sun-solaris2.4/lib/gcc-lib/sparc-sun-solaris2.4/2.7.2
-L/usr/ccs/bin -L/usr/ccs/lib -L/inmos/gnu/sparc-sun-solaris2.4/lib
/var/tmp/cca002Rr1.o -lgcc -lc -lgcc
/inmos/gnu/sparc-sun-solaris2.4/lib/gcc-lib/sparc-sun-solaris2.4/2.7.2/crtend.o
/inmos/gnu/sparc-sun-solaris2.4/lib/gcc-lib/sparc-sun-solaris2.4/2.7.2/crtn.o
ld: Software Generation Utilities (SGU) SunOS/ELF (LK-2.0 (S/I) -
versioning)

-- end compile log

the correct output (obtain with -O optimization or no optimization) is

a access is 5
a access is 10

whereas the erronous output (at -O2) is

a access is 5
a access is 5

the assembly output is
--begin assembly output (of main only)
main:
        !#PROLOGUE# 0
        save %sp,-120,%sp
        !#PROLOGUE# 1
        add %fp,-20,%l0
        mov %l0,%o0
        call _3set_FC1A_si_2_PcC1A_sic,0
        mov 5,%o1
        sethi %hi(.LLC0),%l1
        or %l1,%lo(.LLC0),%l1
        ld [%fp-20],%l2
        mov %l1,%o0
        call printf,0
        mov %l2,%o1
        mov %l0,%o0
        call _10_access_as_FC1A_si_2_PcC1A_sic,0
        mov 10,%o1
        mov %l1,%o0
        call printf,0
        mov %l2,%o1 <-- this line is wrong
        ret
        restore %g0,0,%o0
.LLfe3:

--end assembly output
the noted instruction appears erroneous. It should be something like
	ld [%fp-20],%o1
The compiler appears to be assuming that
_a_13_hello is unchanged by the call to
_10_access_as_FC1A_si_2_PcC1A_sic and
propagating the previously read value in %l2 through to the second
printf.

nathan
-- 
Nathan Sidwell                    The windy road is more interesting
Chameleon Architecture Group at SGS-Thomson, formerly Inmos
http://www.pact.srf.ac.uk/~nathan/                  Tel 0117 9707182
nathan@pact.srf.ac.uk or nathan@bristol.st.com
Technical Details
Message-ID: <32B57296.7E28@pact.srf.ac.uk>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 113d02,f10a05a07c5cdc41,start
X-Google-Attributes: gid113d02,public
From: nathan@pact.srf.ac.uk (Nathan Sidwell)
Subject: optimizer fails in 2.7.2
Date: 1996/12/16
Message-ID: <32B57296.7E28@pact.srf.ac.uk>
X-Deja-AN: 204394863
sender: nathan@pact.srf.ac.uk
content-type: text/plain; charset=us-ascii
organization: Partnership In Advanced Computing Technologies
x-gateway: relay6.UU.NET from bug-gcc to gnu.gcc.bug; Mon, 16 Dec 1996 11:04:27 EST
mime-version: 1.0
newsgroups: gnu.gcc.bug
x-mailer: Mozilla 3.0 (X11; I; SunOS 5.5 sun4u)