Article View: gnu.gcc.bug
Article #2598bug in sparc gcc 1.35
From: Tom Quinn
Date: Thu, 04 May 1989 15:02
Date: Thu, 04 May 1989 15:02
138 lines
5149 bytes
5149 bytes
GCC produces bad assembly when compiling the following code with "-O
-fforce-mem". This is on a Sun4/110 running SunOs 4.0. The test for
the while loop is performed incorrectly, usually causing an infinite
loop.
The compile:
gcc -g -v -S -O -fforce-mem -c make-docfile.c -o make-docfile.o
gcc version 1.35
/usr/local/lib/gcc-cpp -v -undef -D__GNUC__ -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ -D__OPTIMIZE__ make-docfile.c /tmp/cca07848.cpp
GNU CPP version 1.35
/usr/local/lib/gcc-cc1 /tmp/cca07848.cpp -quiet -dumpbase make-docfile.c -fforce-mem -g -O -version -o make-docfile.o
GNU C version 1.35 (sparc) compiled by GNU C version 1.35.
The bad assembly:
.stabn 68,0,106,LM73
LM73:
mov %l2,%o0
call _read_c_string,0
mov 1,%o1
L4:
andcc %l6,16,%g0 ! l6 is not even mentioned before this.
! This should be "ldsh [%l2+16] %l6; andcc ..."
be L97
nop
The code:
------------------------------------------------------------------------
extern struct _iobuf {
int _cnt;
unsigned char *_ptr;
unsigned char *_base;
int _bufsiz;
short _flag;
char _file;
} _iob[];
extern struct _iobuf *fopen();
struct _iobuf *outfile;
char buf[128];
scan_c_file (filename)
char *filename;
{
struct _iobuf *infile;
register int c;
register int commas;
register int defunflag;
register int defvarflag;
if (filename[strlen (filename) - 1] == 'o')
filename[strlen (filename) - 1] = 'c';
infile = fopen (filename, "r");
if (infile == 0 )
{
perror (filename);
return 0;
}
c = '\n';
while (! (((infile)->_flag&020 )!=0) )
{
if (c != '\n')
{
c = (--(infile)->_cnt>=0? ((int)*(infile)->_ptr++):_filbuf(infile)) ;
continue;
}
c = (--(infile)->_cnt>=0? ((int)*(infile)->_ptr++):_filbuf(infile)) ;
if (c == ' ')
{
while (c == ' ')
c = (--(infile)->_cnt>=0? ((int)*(infile)->_ptr++):_filbuf(infile)) ;
if (c != 'D')
continue;
c = (--(infile)->_cnt>=0? ((int)*(infile)->_ptr++):_filbuf(infile)) ;
if (c != 'E')
continue;
c = (--(infile)->_cnt>=0? ((int)*(infile)->_ptr++):_filbuf(infile)) ;
if (c != 'F')
continue;
c = (--(infile)->_cnt>=0? ((int)*(infile)->_ptr++):_filbuf(infile)) ;
if (c != 'V')
continue;
defvarflag = 1;
defunflag = 0;
c = (--(infile)->_cnt>=0? ((int)*(infile)->_ptr++):_filbuf(infile)) ;
}
else if (c == 'D')
{
c = (--(infile)->_cnt>=0? ((int)*(infile)->_ptr++):_filbuf(infile)) ;
if (c != 'E')
continue;
c = (--(infile)->_cnt>=0? ((int)*(infile)->_ptr++):_filbuf(infile)) ;
if (c != 'F')
continue;
c = (--(infile)->_cnt>=0? ((int)*(infile)->_ptr++):_filbuf(infile)) ;
defunflag = c == 'U';
defvarflag = 0;
}
else continue;
while (c != '(')
{
if (c < 0)
return 0;
c = (--(infile)->_cnt>=0? ((int)*(infile)->_ptr++):_filbuf(infile)) ;
}
c = (--(infile)->_cnt>=0? ((int)*(infile)->_ptr++):_filbuf(infile)) ;
if (c != '"')
continue;
c = read_c_string (infile, -1);
if (defunflag)
commas = 5;
else if (defvarflag)
commas = 1;
else
commas = 2;
while (commas)
{
if (c == ',') commas --;
if (c < 0)
return 0;
c = (--(infile)->_cnt>=0? ((int)*(infile)->_ptr++):_filbuf(infile)) ;
}
while (c == ' ' || c == '\n' || c == '\t')
c = (--(infile)->_cnt>=0? ((int)*(infile)->_ptr++):_filbuf(infile)) ;
if (c == '"')
c = read_c_string (infile, 0);
while (c != ',')
c = (--(infile)->_cnt>=0? ((int)*(infile)->_ptr++):_filbuf(infile)) ;
c = (--(infile)->_cnt>=0? ((int)*(infile)->_ptr++):_filbuf(infile)) ;
while (c == ' ' || c == '\n' || c == '\t')
c = (--(infile)->_cnt>=0? ((int)*(infile)->_ptr++):_filbuf(infile)) ;
if (c == '"')
{
(--( outfile)->_cnt >= 0 ? (int)(*( outfile)->_ptr++ = (unsigned char)(037)) : ((( outfile)->_flag & 0200 ) && -( outfile)->_cnt < ( outfile)->_bufsiz ? ((*( outfile)->_ptr = (unsigned char)(037)) != '\n' ? (int)(*( outfile)->_ptr++) : _flsbuf(*(unsigned char *)( outfile)->_ptr, outfile)) : _flsbuf((unsigned char)(037), outfile))) ;
(--( outfile)->_cnt >= 0 ? (int)(*( outfile)->_ptr++ = (unsigned char)(defvarflag ? 'V' : 'F')) : ((( outfile)->_flag & 0200 ) && -( outfile)->_cnt < ( outfile)->_bufsiz ? ((*( outfile)->_ptr = (unsigned char)(defvarflag ? 'V' : 'F')) != '\n' ? (int)(*( outfile)->_ptr++) : _flsbuf(*(unsigned char *)( outfile)->_ptr, outfile)) : _flsbuf((unsigned char)(defvarflag ? 'V' : 'F'), outfile))) ;
fprintf (outfile, "%s\n", buf);
read_c_string (infile, 1);
}
}
fclose (infile);
return 0;
}
Technical Details
Message-ID:
<8905041502.AA19040@moose.cita.utoronto.ca>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!MOOSE.CITA.UTORONTO.CA!trqShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!MOOSE.CITA.UTORONTO.CA!trq From: trq@MOOSE.CITA.UTORONTO.CA (Tom Quinn) Newsgroups: gnu.gcc.bug Subject: bug in sparc gcc 1.35 Message-ID: <8905041502.AA19040@moose.cita.utoronto.ca> Date: 4 May 89 15:02:05 GMT Sender: daemon@tut.cis.ohio-state.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 138