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

trq@moose.cita.toronto.edu (Tom Quinn) (10/11/88)

The following code causes gcc to get a fatal signal.  This is gcc
version 1.29 on a Sun 3/50 running SunOS 3.5.

Tom Quinn                 Canadian Institute for Theoretical Astrophysics
trq@moose.cita.toronto.edu
SOON TO BE 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.29
 /usr/local/lib/gcc-cpp -v -undef -D__GNU__ -D__GNUC__ -Dmc68000 -Dsun -Dunix -D__OPTIMIZE__ -D__HAVE_68881__ -Dmc68020 colormap.c /tmp/cca22036.cpp
GNU CPP version 1.29
 /usr/local/lib/gcc-cc1 /tmp/cca22036.cpp -quiet -dumpbase colormap.c -g -O -version -o /tmp/cca22036.s
GNU C version 1.29 (68k, MIT syntax) compiled by GNU C version 1.29.
gcc: Program cc1 got fatal signal 6.

The code:
------------------------------------------------------------------------
typedef unsigned char *pointer;
typedef int Bool;
char *alloca();
unsigned long *Xrealloc();
typedef unsigned long	Pixel;
typedef struct _ColormapRec *ColormapPtr;
typedef struct _Visual *VisualPtr;
typedef struct _CMEntry
{
    short	refcnt;
} Entry;
typedef struct _ColormapRec
{
    VisualPtr	pVisual;
    int		freeRed;
    int		freeGreen;
    int		freeBlue;
    int		*numPixelsRed;	
    int		*numPixelsGreen;	
    int		*numPixelsBlue;	
    Pixel	**clientPixelsRed;
    Pixel	**clientPixelsGreen;
    Pixel	**clientPixelsBlue;
    Entry	*red;
    Entry 	*green;
    Entry	*blue;
} ColormapRec;
typedef struct _Visual {
    int		offsetRed, offsetGreen, offsetBlue;
  } VisualRec;
static int
AllocDirect (client, pmap, c, r, g, b, contig, pixels, prmask, pgmask, pbmask)
    int		client;
    ColormapPtr	pmap;
    int		c, r, g, b;
    Bool	contig;
    Pixel	*pixels;
    Pixel	*prmask, *pgmask, *pbmask;
{
    Pixel	*ppixRed, *ppixGreen, *ppixBlue;
    Pixel	*ppix, *pDst, *p;
    int		npix;
    Bool	okR, okG, okB;
    for(p = pixels; p < pixels + c; p++)
	*p = 0;
    ppixRed = (Pixel *)alloca((int)((c << r) * sizeof(Pixel))) ;
    ppixGreen = (Pixel *)alloca((int)((c << g) * sizeof(Pixel))) ;
    ppixBlue = (Pixel *)alloca((int)((c << b) * sizeof(Pixel))) ;
    if (!ppixRed || !ppixGreen || !ppixBlue)
    {
	if (ppixBlue)  ;
	if (ppixGreen)  ;
	if (ppixRed)  ;
	return(  11	);
    }
    okR = AllocCP(pmap, pmap->red, c, pmap->freeRed, r, contig,
		  ppixRed, prmask);
    okG = AllocCP(pmap, pmap->green, c, pmap->freeGreen, g, contig,
		  ppixGreen, pgmask);
    okB = AllocCP(pmap, pmap->blue, c, pmap->freeBlue, b, contig,
		  ppixBlue, pbmask);
    if (!okR || !okG || !okB)
    {
	if (okR)
	    for(ppix = ppixRed, npix = (c << r); --npix >= 0; ppix++)
		pmap->red[*ppix].refcnt = 0;
	if (okG)
	    for(ppix = ppixGreen, npix = (c << g); --npix >= 0; ppix++)
		pmap->green[*ppix].refcnt = 0;
	if (okB)
	    for(ppix = ppixBlue, npix = (c << b); --npix >= 0; ppix++)
		pmap->blue[*ppix].refcnt = 0;
	 ;
	 ;
	 ;
	return(  11	);
    }
    *prmask <<= pmap->pVisual->offsetRed;
    *pgmask <<= pmap->pVisual->offsetGreen;
    *pbmask <<= pmap->pVisual->offsetBlue;
    npix = c << r;
    ppix = (Pixel *) Xrealloc((pointer)((pmap->clientPixelsRed)[client]), (unsigned long)(
			((pmap->numPixelsRed)[client] + npix) * sizeof(Pixel))) ;
    (pmap->clientPixelsRed)[client] = ppix;
    ppix += (pmap->numPixelsRed)[client];
    for (pDst = pixels, p = ppixRed; p < ppixRed + npix; p++)
    {
	*ppix++ = *p;
	if(p < ppixRed + c)
	    *pDst++ |= *p << pmap->pVisual->offsetRed;
    }
    (pmap->numPixelsRed)[client] += npix;
    pmap->freeRed -= npix;
    npix = c << g;
    ppix = (Pixel *) Xrealloc((pointer)((pmap->clientPixelsGreen)[client]), (unsigned long)(
			((pmap->numPixelsGreen)[client] + npix) * sizeof(Pixel))) ;
    (pmap->clientPixelsGreen)[client] = ppix;
    ppix += (pmap->numPixelsGreen)[client];
    for (pDst = pixels, p = ppixGreen; p < ppixGreen + npix; p++)
    {
	*ppix++ = *p;
	if(p < ppixGreen + c)
	    *pDst++ |= *p << pmap->pVisual->offsetGreen;
    }
    (pmap->numPixelsGreen)[client] += npix;
    pmap->freeGreen -= npix;
    npix = c << b;
    ppix = (Pixel *) Xrealloc((pointer)((pmap->clientPixelsBlue)[client]), (unsigned long)(
			((pmap->numPixelsBlue)[client] + npix) * sizeof(Pixel))) ;
    (pmap->clientPixelsBlue)[client] = ppix;
    ppix += (pmap->numPixelsBlue)[client];
    for (pDst = pixels, p = ppixBlue; p < ppixBlue + npix; p++)
    {
	*ppix++ = *p;
	if(p < ppixBlue + c)
	    *pDst++ |= *p << pmap->pVisual->offsetBlue;
    }
    (pmap->numPixelsBlue)[client] += npix;
    pmap->freeBlue -= npix;
     ;
     ;
     ;
    return (	   0	);
}

rms@WHEATIES.AI.MIT.EDU (Richard Stallman) (10/11/88)

I think this change in push_reload (reload.c) fixes that bug.
Please try it.

	    (out != 0 && MATCHES (reload_out[i], out)
	     && (in == 0 || reload_in[i] == 0 || MATCHES (reload_in[i], in)))))
      break;

!  /* Reloading a plain reg for input can match a reload to postincrement
!     that reg, since the postincrement's value is the right value.
!     Likewise, it can match a preincrement reload, since we regard
!     the preincrementation as happening before any ref in this insn
!     to that register.  */
!  for (i = 0; i < n_reloads; i++)
!    if (reload_reg_class[i] == class
!	&& reload_strict_low[i] == strict_low
!	&& out == 0 && reload_out[i] == 0
!	&& ((GET_CODE (in) == REG
!	     && (GET_CODE (reload_in[i]) == POST_INC
!		 || GET_CODE (reload_in[i]) == POST_DEC
!		 || GET_CODE (reload_in[i]) == PRE_INC
!		 || GET_CODE (reload_in[i]) == PRE_DEC)
!	     && MATCHES (XEXP (reload_in[i], 0), in))
!	    ||
!	    (GET_CODE (reload_in[i]) == REG
!	     && (GET_CODE (in) == POST_INC
!		 || GET_CODE (in) == POST_DEC
!		 || GET_CODE (in) == PRE_INC
!		 || GET_CODE (in) == PRE_DEC)
!	     && MATCHES (XEXP (in, 0), reload_in[i]))))
!      break;

  if (i == n_reloads)
    {
      /* We found no existing reload suitable for re-use.
	 So add an additional reload.  */

trq@moose.cita.toronto.edu (Tom Quinn) (10/11/88)

The following code causes gcc to get a fatal error if compiled with
the "-O" option.  This is gcc version 1.29 with or without the posted
fix from RMS on a Sun3/50 running SunOS 3.5.

Tom Quinn                 Canadian Institute for Theoretical Astrophysics
trq@moose.cita.toronto.edu
SOON TO BE 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 mibstore.c
gcc version 1.29
 /usr/local/lib/gcc-cpp -v -undef -D__GNU__ -D__GNUC__ -Dmc68000 -Dsun -Dunix -D__OPTIMIZE__ -D__HAVE_68881__ -Dmc68020 mibstore.c /tmp/cca01173.cpp
GNU CPP version 1.29
 /usr/local/lib/gcc-cc1 /tmp/cca01173.cpp -quiet -dumpbase mibstore.c -g -O -version -o /tmp/cca01173.s
GNU C version 1.29 (68k, MIT syntax) compiled by GNU C version 1.29.
gcc: Program cc1 got fatal signal 6.

The code:
------------------------------------------------------------------------
typedef short          INT16;
typedef unsigned short CARD16;
typedef struct _xRectangle {
    INT16 x  , y  ;
    CARD16  width  , height  ;
} xRectangle;
typedef unsigned char *pointer;
typedef int Bool;
typedef unsigned long ATOM;
typedef struct _DDXPoint *DDXPointPtr;
typedef struct _Box *BoxPtr;
typedef struct _Region *RegionPtr;
typedef struct _DDXPoint {
    short x, y;
} DDXPointRec;
typedef struct _Box {
    short x1, y1, x2, y2;
} BoxRec;
typedef struct _Region {
    short	size;
    short 	numRects;
    BoxPtr	rects;
    BoxRec 	extents;
} RegionRec;
typedef struct _Screen *ScreenPtr;
typedef struct _DrawInfo *DrawablePtr;	
typedef struct _GC    *GCPtr;
typedef struct _Screen {
    ATOM id;
    short		width, height;
    RegionPtr (* RegionCreate)(); 	 
    void (* RegionCopy)();		 
    int (* Intersect)();		 
    int (* Inverse)();			 
    void (* RegionReset)();		 
    void (* TranslateRegion)();		 
} ScreenRec;
typedef struct _GC{
    ScreenPtr	pScreen;		
    pointer 	devBackingStore;    	 
    int         depth;    
    unsigned long        serialNumber;
    int		alu;
    unsigned long	planemask;
    int		lineWidth;          
    int		arcMode;
    DDXPointRec	patOrg;			 
    int		subWindowMode;
    Bool	graphicsExposures;
    DDXPointRec	clipOrg;
    pointer	clientClip;
    int		clientClipType;		 
    int		dashOffset;
    int		numInDashList;		 
    unsigned long	stateChanges;	 
    void (* ChangeClip) ();
} GC;
typedef struct _Window *WindowPtr;
typedef struct _DrawInfo {
    short	type;
    unsigned long        serialNumber;
} DrawableRec;
typedef struct _Window {
	DrawableRec drawable;		 
	RegionPtr clipList;                
	xRectangle clientWinSize;        
	DDXPointRec  absCorner;
	pointer devBackingStore;		 
} WindowRec;
typedef struct {
    unsigned long serialNumber;	     
} MIBackingStoreRec, *MIBackingStorePtr;
extern void miValidateBackingStore();
typedef struct {
    GCPtr   	  pBackingGC;	     
    RegionPtr	  pTransClientClip;  
} MIBSGCPrivRec, *MIBSGCPrivPtr;
void
miValidateBackingStore(pWin, pGC, procChanges)
    WindowPtr 	  pWin;
    GCPtr   	  pGC;
    int	    	  procChanges;	 
{
    GCPtr   	  	pBackingGC;
    MIBackingStorePtr	pBackingStore;
    MIBSGCPrivPtr 	pPriv;
    int	    	  	stateChanges;
    register int  	index, mask;
    pBackingStore = (MIBackingStorePtr)pWin->devBackingStore;
    pPriv = (MIBSGCPrivPtr)pGC->devBackingStore;
    if ((pWin->drawable.serialNumber != pBackingStore->serialNumber) ||
	(stateChanges&(	(1L<<17) |	(1L<<18) |	(1L<<19) )))
    {
	RegionPtr tempRgn;
	BoxRec	  winBounds;
	pBackingStore->serialNumber = pWin->drawable.serialNumber;
	if (pGC->clientClipType == 		0 )
	{
	    BoxRec	bounds;
	    bounds.x1 = bounds.y1 = 0;
	    bounds.x2 = pWin->clientWinSize.width;
	    bounds.y2 = pWin->clientWinSize.height;
	    (*pGC->pScreen->RegionReset) (pPriv->pTransClientClip,
					  &bounds);
	}
	else if (stateChanges & (	(1L<<17) |	(1L<<18) |	(1L<<19) ))
	{
	    if (pGC->clientClipType != 	2 ) {
		FatalError("miValidateBackingStore: client clip not a region");
	    }
	    (*pGC->pScreen->RegionCopy) (pPriv->pTransClientClip,
					 pGC->clientClip);
	    if (stateChanges & (	(1L<<17) |	(1L<<18) ))
	    {
		(*pGC->pScreen->TranslateRegion) (pPriv->pTransClientClip,
						  pGC->clipOrg.x,
						  pGC->clipOrg.y);
	    }
	}
	tempRgn = (*pGC->pScreen->RegionCreate) (           0 , 1);
	winBounds.x1 = pWin->absCorner.x;
	winBounds.x2 = pWin->absCorner.x + pWin->clientWinSize.width;
	winBounds.y1 = pWin->absCorner.y;
	winBounds.y2 = pWin->absCorner.y + pWin->clientWinSize.height;
	(*pGC->pScreen->Inverse) (tempRgn,
				  pWin->clipList,
				  &winBounds);
	(*pGC->pScreen->TranslateRegion) (tempRgn,
					  -pWin->absCorner.x,
					  -pWin->absCorner.y);
	(*pGC->pScreen->Intersect) (tempRgn,
				    tempRgn,
				    pPriv->pTransClientClip);
	(*pBackingGC->ChangeClip) (pBackingGC, 	2 , tempRgn, 0);
    }
}

trq@moose.cita.utoronto.ca (Tom Quinn) (10/13/88)

The following code causes gcc to get a fatal signal when compiled with
the "-O" option.  This is gcc version 1.29 with the second fix posted
by RMS 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 comile:
gcc -g -v -O -c midash.c
gcc version 1.29
 /usr/local/lib/gcc-cpp -v -undef -D__GNU__ -D__GNUC__ -Dmc68000 -Dsun -Dunix -D__OPTIMIZE__ -D__HAVE_68881__ -Dmc68020 midash.c /tmp/cca00683.cpp
GNU CPP version 1.29
 /usr/local/lib/gcc-cc1 /tmp/cca00683.cpp -quiet -dumpbase midash.c -g -O -version -o /tmp/cca00683.s
GNU C version 1.29 (68k, MIT syntax) compiled by GNU C version 1.29.
gcc: Program cc1 got fatal signal 11.

The code:
------------------------------------------------------------------------
typedef struct _DDXPoint *DDXPointPtr;
typedef struct _DDXPoint {
    short x, y;
} DDXPointRec;
typedef struct _miDash *miDashPtr;
extern miDashPtr   miDashLine();
typedef struct _miDash {
    DDXPointRec	pt;
    int		e1, e2;	 
    int		e;	 
    int		which;
    int		newLine; 
    } miDashRec;
static miDashPtr CheckDashStorage();
miDashPtr
miDashLine(npt, ppt, nDash, pDash, offset, pnseg)
int npt;
DDXPointPtr ppt;
int nDash;
unsigned char *pDash;
int offset;
int *pnseg;
{
    DDXPointRec pt1, pt2;
    int lenCur;		 
    int lenMax;		 
    int iDash = 0;	 
    int which;		 
    miDashPtr pseg;	 
    miDashPtr psegBase;	 
    int nseg = 0;	 
    int nsegMax = 0;	 
    int x, y, len;
    int adx, ady, signdx, signdy;
    int du, dv, e1, e2, e;
    lenCur = offset;
    which = 0 ;
    while(lenCur > pDash[iDash]) {
	lenCur -= pDash[iDash];
	iDash++;
	if (iDash >= nDash) iDash = 0;
	which = ~which;
    }
    lenMax = pDash[iDash];
    psegBase = (miDashPtr)           0 ;
    while(--npt) {
	pt1 = *ppt++;
	pt2 = *ppt;
	adx = pt2.x - pt1.x;
	ady = pt2.y - pt1.y;
	signdx = ((adx) < 0 ? -1 : ((adx) > 0 ? 1 : 0)) ;
	signdy = ((ady) < 0 ? -1 : ((ady) > 0 ? 1 : 0)) ;
	adx = ((adx) > 0 ? (adx) : -(adx)) ;
	ady = ((ady) > 0 ? (ady) : -(ady)) ;
	if (adx > ady) {
	    du = adx;
	    dv = ady;
	    len = adx;
	} else {
	    du = ady;
	    dv = adx;
	    len = ady;
	}
	e1 = dv * 2;
	e2 = e1 - 2*du;
	e = e1 - du;
	x = pt1.x;
	y = pt1.y;
	nseg++;
	pseg = CheckDashStorage(&psegBase, nseg, &nsegMax);
	pseg->pt = pt1;
	pseg->e1 = e1;
	pseg->e2 = e2;
	pseg->e = e;
	pseg->which = which;
	pseg->newLine = 1;
	while (len--) {
	    if (adx > ady) {
		if (((signdx > 0) && (e < 0)) || ((signdx <=0) && (e <=0))) {
		    e += e1;
		} else {
		    y += signdy;
		    e += e2;
		}
		x += signdx;
	    } else {
		if (((signdx > 0) && (e < 0)) || ((signdx <=0) && (e <=0))) {
		    e +=e1;
		} else {
		    x += signdx;
		    e += e2;
		}
		y += signdy;
	    }
	    lenCur++;
	    if (lenCur >= lenMax) {
		nseg++;
		pseg = CheckDashStorage(&psegBase, nseg, &nsegMax);
		pseg->pt.x = x;
		pseg->pt.y = y;
		pseg->e1 = e1;
		pseg->e2 = e2;
		pseg->e = e;
		which = ~which;
		pseg->which = which;
		pseg->newLine = 0;
		iDash++;
		if (iDash >= nDash) iDash = 0;
		lenMax = pDash[iDash];
		lenCur = 0;
	    }
	}  
    }  
    *pnseg = nseg;
    pseg = CheckDashStorage(&psegBase, nseg+1, &nsegMax);
    pseg->pt = pt2;
    return psegBase;
}