This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
GCSE bug
- To: egcs-bugs at cygnus dot com
- Subject: GCSE bug
- From: Daniel Jacobowitz <dmj at andrew dot cmu dot edu>
- Date: Fri, 18 Sep 1998 09:13:13 -0400
I've stumbled on a bug in the scheduler as of egcs 1.1 on both powerpc
and intel platforms. The original program in which I saw it was mpack
(ftp://ftp.andrew.cmu.edu/pub/mpack); a shorter test case (courtesy of
Richard Braakman, dark@debian.org) is appended, and some scripts and
test files to illustrate the problem are at:
http://drow.res.cmu.edu/~drow/mpack-test-case.tgz
bash-2.01$ gcc -v
Reading specs from /usr/lib/gcc-lib/powerpc-linux/egcs-2.91.57/specs
gcc version egcs-2.91.57 19980901 (egcs-1.1 release)
The problem appears whenever -fgcse is used, and disappears at any
optimization level with -fno-gcse.
The egcs was built with:
mkdir builddir; cd builddir
../configure --prefix=/usr --enable-threads --enable-shared -v
make -C builddir bootstrap CC='gcc -DEGCS' LDFLAGS=-s CFLAGS=-DEGCS
BOOT_CFLAGS='-DEGCS -O2'
(the -DEGCS is for gpc).
Daniel Jacobowitz
dan@debian.org
/* (C) Copyright 1993,1994 by Carnegie Mellon University
* All Rights Reserved.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without
* fee, provided that the above copyright notice appear in all copies
* and that both that copyright notice and this permission notice
* appear in supporting documentation, and that the name of Carnegie
* Mellon University not be used in advertising or publicity
* pertaining to distribution of the software without specific,
* written prior permission. Carnegie Mellon University makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied
* warranty.
*
* CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#define BUFSIZE 1024
/* Structure describing an input file from which we read MIME */
FILE *infile;
unsigned char inbuf[BUFSIZE];
unsigned char *ptr;
int cnt;
static int part_fill();
static int uudecodefiles(char *dir, int nparts);
static int saveUuFile(char *fname, int part, int nparts, char *firstline);
#define part_getc() ((cnt-- > 0 && ptr[0] != '\n') ? (int)*ptr++ : part_fill())
static char *part_gets();
int main(argc, argv)
int argc;
char **argv;
{
char buf[1024];
infile = fopen(argv[1], "r");
part_gets(buf, sizeof(buf));
saveUuFile((char *)0, 1, 0, buf);
exit(1);
}
/*
* Private function that is only called from the part_getc() macro.
*
* Fills the input buffer for 'part' if necessary. Returns the next
* input character or EOF if at a boundary or end of file.
*/
static int part_fill(void)
{
/* part_getc() decremented this before calling us, put it back */
cnt++;
/* Fill buffer if it is empty */
if (cnt == 0) {
ptr = inbuf;
cnt = fread(inbuf, 1, BUFSIZE, infile);
if (cnt == 0) {
return EOF;
}
}
cnt--;
return *ptr++;
}
/*
* Read a line into the array 's', of size 'n', from 'part'.
* Reads until 'n'-1 characters are read, a newline is read, or
* an EOF is encountered. The array is then nul-terminated and returned.
* If the first character read is an EOF, then a null pointer is instead
* returned.
*/
static char *
part_gets(char *s, int n)
{
int c;
char *p = s;
if (n == 0) return 0;
n--;
while (n-- && (c = part_getc()) != EOF) {
*p++ = c;
if (c == '\n') break;
}
if (p == s) return 0;
*p++ = '\0';
return s;
}
/*
* Handle a split-uuencode part
* If nparts is 0, then look for an "end" line to detect the last part.
* If fname is null, then we are attempting to decode a single-part message.
* If firstline is non-null, it is written as the first line of the saved part
*/
static int
saveUuFile(fname, part, nparts, firstline)
char *fname;
int part;
int nparts;
char *firstline;
{
char buf[1024];
char *dir;
FILE *partfile;
if (fname) {
sprintf(buf, "Saving part %d ", part);
if (nparts) sprintf(buf+strlen(buf), "of %d ", nparts);
strcat(buf, fname);
}
else fname = "unknown";
/* Create directory to store parts and copy this part there. */
dir = "./";
if (!dir) return 1;
sprintf(buf, "%s%d", dir, part);
partfile = fopen(buf, "w");
if (!partfile) {
perror(buf);
return 1;
}
if (firstline) fputs(firstline, partfile);
while (part_gets(buf, sizeof(buf))) {
fputs(buf, partfile);
if (nparts == 0 && strcmp(buf, "end\n") == 0) {
/* This is the last part. Remember the fact */
nparts = part;
fclose(partfile);
sprintf(buf, "%sCT", dir);
partfile = fopen(buf, "w");
if (!partfile) {
perror(buf);
}
else {
fprintf(partfile, "%d\n", nparts);
}
break;
}
}
fclose(partfile);
/* Retrieve any previously saved number of the last part */
if (nparts == 0) {
sprintf(buf, "%sCT", dir);
if ((partfile = fopen(buf, "r"))) {
if (fgets(buf, sizeof(buf), partfile)) {
nparts = atoi(buf);
if (nparts < 0) nparts = 0;
}
fclose(partfile);
}
}
if (nparts == 0) return 0;
/* Check to see if we have all parts. Start from the highest numbers
* as we are more likely not to have them.
*/
for (part = nparts; part; part--) {
sprintf(buf, "%s%d", dir, part);
partfile = fopen(buf, "r");
if (partfile) {
fclose(partfile);
}
else {
return 0;
}
}
return uudecodefiles(dir, nparts);
}
static int uudecodefiles(char *dir, int nparts) {
exit(0);
}