Path: utzoo!telly!attcan!dptcdc!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 m68k gcc 1.33 Message-ID: <8902161830.AA08262@moose.cita.utoronto.ca> Date: 16 Feb 89 18:30:33 GMT Sender: daemon@tut.cis.ohio-state.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 173 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 ); }