[gnu.gcc.bug] bug in m68k gcc 1.33

trq@MOOSE.CITA.UTORONTO.CA (Tom Quinn) (02/05/89)

The following code will cause gcc to abort when compiled with the "-g
-O" option.  This is gcc version 1.33 on a Sun 3/50 running SunOS 3.5.

Tom Quinn                 Canadian Institute for Theoretical Astrophysics
trq@moose.cita.utoronto.ca
UUCP   - decvax!utgpu!moose!trq
BITNET - quinn@utorphys.bitnet
ARPA   - trq%moose.cita.toronto.edu@relay.cs.net

The compile:
gcc -g -v -O -c qmove.c
gcc version 1.33
 /usr/local/lib/gcc-cpp -v -undef -D__GNUC__ -Dmc68000 -Dsun -Dunix -D__mc68000__ -D__sun__ -D__unix__ -D__OPTIMIZE__ -D__HAVE_68881__ -Dmc68020 qmove.c /tmp/cca13863.cpp
GNU CPP version 1.33
 /usr/local/lib/gcc-cc1 /tmp/cca13863.cpp -quiet -dumpbase qmove.c -g -O -version -o /tmp/cca13863.s
GNU C version 1.33 (68k, MIT syntax) compiled by GNU C version 1.33.
gcc: Program cc1 got fatal signal 6.

The code:
------------------------------------------------------------------------
int
    pen_x, pen_y,	 
    level,		 
    Speed;		 
bounds(x0, y0, x1, y1, dx0, dy0, dx1, dy1)
register int x0, y0, x1, y1;
register int *dx0, *dy0, *dx1, *dy1;
{
    register int new_x0, new_y0, new_x1, new_y1;
    int count, loop_count = 0;
    if (!(	random () % 10)) {
	register int r;
	r = 	random ();
	*dx0 = (1 + r%(Speed-1)) * ((r&1) ? -1 : 1);
	r = 	random ();
	*dy0 = (1 + r%(Speed-1)) * ((r&1) ? -1 : 1);
	r = 	random ();
	*dx1 = (1 + r%(Speed-1)) * ((r&1) ? -1 : 1);
	r = 	random ();
	*dy1 = (1 + r%(Speed-1)) * ((r&1) ? -1 : 1);
	if (level > -2 && !(	random () % (6 - level))) {
	    if (pen_x - x0 > 0 && *dx0 < 0)
		*dx0 = -*dx0;
	    if (pen_x - x1 > 0 && *dx1 < 0)
		*dx1 = -*dx1;
	    if (pen_y - y0 > 0 && *dy0 < 0)
		*dy0 = -*dy0;
	    if (pen_y - y1 > 0 && *dy1 < 0)
		*dy1 = -*dy1;
	}
    }
    do  {
	if (x0 + *dx0 <= 1 || x0 + *dx0 >= ((	700  - 2 * 			10 )/		5 ) -2)
	    *dx0 = -*dx0;
	if (x1 + *dx1 <= 1 || x1 + *dx1 >= ((	700  - 2 * 			10 )/		5 ) -2)
	    *dx1 = -*dx1;
	if (y0 + *dy0 <= 1 || y0 + *dy0 >= ((	750 -			10 -		25 )/		5 ) -2)
	    *dy0 = -*dy0;
	if (y1 + *dy1 <= 1 || y1 + *dy1 >= ((	750 -			10 -		25 )/		5 ) -2)
	    *dy1 = -*dy1;
	new_x0 = x0 + *dx0;
	new_x1 = x1 + *dx1;
	new_y0 = y0 + *dy0;
	new_y1 = y1 + *dy1;
	if ((abs(new_x1 - new_x0) >  45	) || (abs((*dx0)-(*dx1)) <  ((4+level)/3)	))
	    if (	random ()&1)
		*dx1 += (x1<x0 ?  (Speed)  : - (Speed) ), new_x1 = x1 + *dx1;
	    else
		*dx0 += (x0<x1 ?  (Speed)  : - (Speed) ), new_x0 = x0 + *dx0;
	if ((abs(new_y1 - new_y0) >  45	) || (abs((*dy0)-(*dy1)) <  ((4+level)/3)	)) 
	    if (	random ()&1)
		(*dy1) += (y1<y0 ?  (Speed)  : - (Speed) ), new_y1 = y1 + *dy1;
	    else
		(*dy0) += (y0<y1 ?  (Speed)  : - (Speed) ), new_y0 = y0 + *dy0;
	if ((count = check_line(new_x0, new_y0, new_x1, new_y1)) == 1) {
	    register int r;
	    *dx0 = (1 + (r = 	random ())%Speed) * ((r&1) ? -1 : 1);
	    *dy0 = (1 + (r = 	random ())%Speed) * ((r&1) ? -1 : 1);
	    *dx1 = (1 + (r = 	random ())%Speed) * ((r&1) ? -1 : 1);
	    *dy1 = (1 + (r = 	random ())%Speed) * ((r&1) ? -1 : 1);
	}
	if (!(++loop_count % 100)) {
	    break;
	}
    } while(count == 1);
    return count;
}

trq@MOOSE.CITA.UTORONTO.CA (Tom Quinn) (02/17/89)

The following code will cause gcc to get a segmentation fault when
compiled with the "-g -O" options.  This is gcc version 1.33 on a Sun
3/50 running SunOs 3.5.

Tom Quinn                 Canadian Institute for Theoretical Astrophysics
trq@moose.cita.utoronto.ca
UUCP   - decvax!utgpu!moose!trq
BITNET - quinn@utorphys.bitnet
ARPA   - trq%moose.cita.toronto.edu@relay.cs.net

The compile:
gcc -g -v -O -c colormap.c
gcc version 1.33
 /usr/local/lib/gcc-cpp -v -undef -D__GNUC__ -Dmc68000 -Dsun -Dunix -D__mc68000__ -D__sun__ -D__unix__ -D__OPTIMIZE__ -D__HAVE_68881__ -Dmc68020 colormap.c /tmp/cca00035.cpp
GNU CPP version 1.33
 /usr/local/lib/gcc-cc1 /tmp/cca00035.cpp -quiet -dumpbase colormap.c -g -O -version -o /tmp/cca00035.s
GNU C version 1.33 (68k, MIT syntax) compiled by GNU C version 1.33.
gcc: Program cc1 got fatal signal 11.

The code:
------------------------------------------------------------------------
typedef unsigned long XID;
typedef XID Colormap;
typedef struct 
{
	Colormap	mid;
	int		client;
	} colorResource;
typedef struct _Visual {
    unsigned long	redMask, greenMask, blueMask;
    short	ColormapEntries;
    int		offsetRed, offsetGreen, offsetBlue;
  } VisualRec;
typedef unsigned long	Pixel;
typedef struct _Screen {
    void (* ResolveColor)();		 
} ScreenRec;
typedef struct _Visual *VisualPtr;
typedef unsigned short CARD16;
typedef struct {
    CARD16 red  , green  , blue  , pad  ;
} xrgb;
typedef struct _Screen *ScreenPtr;
typedef struct
{
    unsigned short	red, green, blue;
} LOCO;
typedef struct
{
    unsigned short color;
    short  refcnt;
} SHAREDCOLOR;
typedef struct 
{
    SHAREDCOLOR *red, *green, *blue;
} SHCO;
typedef struct _CMEntry
{
    union
    {
	LOCO	local;
	SHCO	shco;
    } co;
} Entry;
typedef struct _ColormapRec
{
    VisualPtr	pVisual;
    short	class;		 
    long	mid;		 
    ScreenPtr	pScreen;	 
    short	flags;		 
    int		*numPixelsRed;	
    Entry	*red;
    Entry 	*green;
    Entry	*blue;
} ColormapRec;
typedef struct _ColormapRec *ColormapPtr;
typedef unsigned char *pointer;

void AddResource();
static int   AllComp(), RedComp(), GreenComp(), BlueComp(), FreeClientPixels();
unsigned long FakeClientID();
static Pixel FindBestPixel();
extern Pixel FindColor();
static int FreeCo();
unsigned long	*Xalloc();

int
AllocColor (pmap, pred, pgreen, pblue, pPix, client)
    ColormapPtr		pmap;
    unsigned short 	*pred, *pgreen, *pblue;
    Pixel		*pPix;
    int			client;
{
    Pixel	pixR, pixG, pixB;
    int		entries;
    xrgb	rgb;
    int		class;
    VisualPtr	pVisual;
    pVisual = pmap->pVisual;
    (*pmap->pScreen->ResolveColor) (pred, pgreen, pblue, pVisual);
    rgb.red = *pred;
    rgb.green = *pgreen;
    rgb.blue = *pblue;
    class = pmap->class;
    entries = pVisual->ColormapEntries;
    if(pmap->flags & 4 )
	class |=  1 ;
    switch (class) {
    case 	2 :
    case 	0 :
	*pPix = pixR = FindBestPixel(pmap->red, entries, &rgb, 3 );
	*pred = pmap->red[pixR].co.local.red;
	*pgreen = pmap->red[pixR].co.local.green;
	*pblue = pmap->red[pixR].co.local.blue;
	return(	   0	);
    case 	4 :
	pixR = FindBestPixel(pmap->red, entries, &rgb, 0 );
	pixG = FindBestPixel(pmap->green, entries, &rgb, 1 );
	pixB = FindBestPixel(pmap->blue, entries, &rgb, 2 );
	*pPix = (pixR << pVisual->offsetRed) |
		(pixG << pVisual->offsetGreen) |
		(pixB << pVisual->offsetBlue);
	*pred = pmap->red[pixR].co.local.red;
	*pgreen = pmap->green[pixG].co.local.green;
	*pblue = pmap->blue[pixB].co.local.blue;
	return(	   0	);
    case 	1 :
    case 	3 :
	if (FindColor(pmap, pmap->red, entries, &rgb, pPix, 3 ,
		      client, AllComp) != 	   0	)
	{
	    return (  11	);
	}
        break;
    case 	5 :
	pixR = (*pPix & pVisual->redMask) >> pVisual->offsetRed; 
	if (FindColor(pmap, pmap->red, entries, &rgb, &pixR, 0 ,
		      client, RedComp) != 	   0	)
	{
	    return (  11	);
	}
	pixG = (*pPix & pVisual->greenMask) >> pVisual->offsetGreen; 
	if (FindColor(pmap, pmap->green, entries, &rgb, &pixG, 1 ,
		      client, GreenComp) != 	   0	)
	{
	    (void)FreeCo(pmap, client, 0 , 1, &pixR, (Pixel)0);
	    return (  11	);
	}
	pixB = (*pPix & pVisual->blueMask) >> pVisual->offsetBlue; 
	if (FindColor(pmap, pmap->blue, entries, &rgb, &pixB, 2 ,
		      client, BlueComp) != 	   0	)
	{
	    (void)FreeCo(pmap, client, 1 , 1, &pixG, (Pixel)0);
	    (void)FreeCo(pmap, client, 0 , 1, &pixR, (Pixel)0);
	    return (  11	);
	}
	*pPix = pixR | pixG | pixB;
	break;
    }
    if (((pmap->numPixelsRed)[client] == 1) &&
	(((int)(((pmap->mid) & 0xfff00000)		 >> 20					))	 != client) &&
	!(pmap->flags & 4 ))
    {
	colorResource	*pcr;
	pcr = (colorResource *) Xalloc((unsigned long)(sizeof(colorResource))) ;
	pcr->mid = pmap->mid;
	pcr->client = client;
	AddResource(FakeClientID(client),        1<<8 , (pointer)pcr,
		    FreeClientPixels, 	    0 );
    }
    return (	   0	);
}