Path: utzoo!telly!ddsw1!lll-winken!killer!mit-eddie!bloom-beacon!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.30 Message-ID: <8810191547.AA06977@moose.cita.utoronto.ca> Date: 19 Oct 88 15:47:55 GMT Sender: daemon@tut.cis.ohio-state.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 124 The following code prints "65135" instead of the expected "401" when compiled with the "-O" flag. The problem is at line 72: the shorts are not signed extended before subtracting and stored in the int "adx". This gcc version 1.30 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 mfbline.c gcc version 1.30 /usr/local/lib/gcc-cpp -v -undef -D__GNU__ -D__GNUC__ -Dmc68000 -Dsun -Dunix -D__OPTIMIZE__ -D__HAVE_68881__ -Dmc68020 mfbline.c /tmp/cca02948.cpp GNU CPP version 1.30 /usr/local/lib/gcc-cc1 /tmp/cca02948.cpp -quiet -dumpbase mfbline.c -g -O -version -o /tmp/cca02948.s GNU C version 1.30 (68k, MIT syntax) compiled by GNU C version 1.30. as -mc68020 /tmp/cca02948.s -o mfbline.o gcc -v mfbline.o gcc version 1.30 ld /lib/crt0.o /lib/Mcrt1.o mfbline.o /usr/local/lib/gcc-gnulib -lc 150}a.out 65135 The code: ------------------------------------------------------------------------ typedef struct _DDXPoint *DDXPointPtr; typedef struct _Box *BoxPtr; typedef struct _DDXPoint { short x, y; } DDXPointRec; typedef struct _Box { short x1, y1, x2, y2; } BoxRec; main() { DDXPointPtr ptinit; ptinit = (DDXPointPtr) malloc(2*sizeof(DDXPointRec)); ptinit[0].x = -1; ptinit[1].x = 400; ptinit[0].y = 400; ptinit[1].y = 900; mfbLineSS(0, 2, ptinit); } mfbLineSS( mode, npt, pptInit) int mode; int npt; DDXPointPtr pptInit; { int nboxInit; register int nbox; BoxPtr pboxInit; register BoxPtr pbox; int nptTmp; DDXPointPtr ppt; DDXPointRec pt1; DDXPointRec pt2; int xorg, yorg; int adx; int ady; int signdx; int signdy; int e, e1, e2; int axis; DDXPointRec pt1Orig; DDXPointRec pt2Orig; xorg = yorg = 0; ppt = pptInit; nptTmp = npt; if (mode == 0 ) { while(nptTmp--) { ppt->x += xorg; ppt++->y += yorg; } } else { ppt->x += xorg; ppt->y += yorg; nptTmp--; while(nptTmp--) { ppt++; ppt->x += (ppt-1)->x; ppt->y += (ppt-1)->y; } } ppt = pptInit; while(--npt) { nbox = nboxInit; pbox = pboxInit; 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) { axis = 0 ; e1 = ady*2; e2 = e1 - 2*adx; e = e1 - adx; } else { axis = 1 ; e1 = adx*2; e2 = e1 - 2*ady; e = e1 - ady; } pt1Orig = pt1; pt2Orig = pt2; printf("%d\n", adx); } } }