Path: utzoo!telly!ddsw1!spl1!philabs!ttidca!quad1!psivax!csun!sm.unisys.com!oberon!bloom-beacon!apple!rutgers!mailrus!umix!teemc!rphroy!tkacik From: tkacik@rphroy.UUCP (Tom Tkacik) Newsgroups: gnu.gcc.bug Subject: gcc-1.28 generates wrong code for unsigned short to int Keywords: AT&T UnixPC Message-ID: <2501@rphroy.UUCP> Date: 3 Oct 88 14:19:27 GMT Organization: GM Research Labs, Warren, MI Lines: 97 PROBLEM: Gcc-1.28, (when not optimizing), produces incorrect code for moves from an unsigned short to either an int or an unsigned int. With the optimizer on, the correct code is emitted. (Does this happen on all versions, or only mine?) Tom Tkacik {umix!mcf, uunet!edsews}!rphroy!tetnix!tet SYSTEM: AT&T UnixPC UNIX: SYSV.? (ver 3.5) CONFIGURATION FILES: standard for the UnixPC tm.h ----> tm-3b1.h md ----> m68k.md aux-output.c ----> output-m68k.c COMMAND: gcc -v -S -gg bug.c The -gg option is for aiding in reading the output file. A program compiled with -gg cannot be assembled on the UnixPC. VERSION: gcc version 1.28 /usr/local/lib/gcc-cpp -v -undef -D__GNU__ -D__GNUC__ -Dmc68k -Dunix -Dunixpc bug.c /tmp/cca03586.cpp GNU CPP version 1.28 /usr/local/lib/gcc-cc1 /tmp/cca03586.cpp -quiet -dumpbase bug.c -version -symout /tmp/cca03586.sym -o bug.s GNU C version 1.28 (68k, SGS/AT&T unixpc syntax) compiled by GNU C version 1.28. --------------------------------------------------------------- /* bug.c -- gcc makes two errors in this code */ unsigned int ui; int i; unsigned short us; short s; f() { i = s; i = us; /* gcc gets this wrong */ ui = s; ui = us; /* this also */ } --------------------------------------------------------------- file "bug.c" .text 0 .gdbbeg 0 .gdbbeg 1 Ltext: .stabs "bug.c",100,0,0,Ltext .data 0 Ldata: lcomm Lbss,0 .gdbsym Ldata,52 .gdbsym Lbss,56 text even global f f: .gdbbeg 2 .gdbline 0,9 link.w %a6,&0 mov.l %d2,-(%sp) .gdbline 0,10 mov.w s,%a0 <---- short to int is correct mov.l %a0,i .gdbline 0,11 mov.w us,%d2 <---- unsigned short to int is wrong clr.l i mov.l i,%d0 mov.w %d2,%d0 mov.l %d0,%d0 .gdbline 0,12 mov.w s,%a0 <---- short to unsigned is correct mov.l %a0,ui .gdbline 0,13 mov.w us,%d2 <---- unsigned short to unsigned is wrong clr.l ui mov.l ui,%d0 mov.w %d2,%d0 mov.l %d0,%d0 .gdbline 0,14 L%1: .gdbend 2 mov.l -4(%a6),%d2 unlk %a6 rts .gdbblock 2,1188 comm s,2 comm us,2 comm i,4 comm ui,4 .text 0 .gdbend 0 .gdbblock 0,1328 .gdbend 1 .gdbblock 1,1864 .gdblinetab 0,2092