Path: utzoo!utgpu!cs.utexas.edu!usc!sdd.hp.com!zaphod.mps.ohio-state.edu!rpi!uupsi!sunic!zyx!arndt From: arndt@zyx.ZYX.SE (Arndt Jonasson) Newsgroups: alt.sys.sun Subject: cc optimizer bug (arithmetic shifts). Message-ID: <1991Feb07.132335.13531@ZYX.SE> Date: 7 Feb 91 13:23:35 GMT Sender: arndt@ZYX.SE (Arndt Jonasson) Organization: ZYX Sweden AB, Stockholm, Sweden Lines: 46 The version of SunOS is 4.1. -------------------- start of script -------------------- % cat mc.c #include main() { int i; for (i=0; i<8; i++) test(i<<29); } test(j) int j; { printf("%d\n", j); } % cc -o mc mc.c % mc 0 536870912 1073741824 1610612736 -2147483648 -1610612736 -1073741824 -536870912 % cc -O -o mc mc.c % mc 0 % uname -srm SunOS 4.1 sun4c % -------------------- end of script -------------------- What seems to happen is that the optimizer sees a chance to avoid shifting 'i' all the time, and therefore keeps 'i' shifted left 29 steps, modifying the index arithmetic accordingly. It's basically a good idea, but it only works if the maximum shifted value of 'i' doesn't overflow, which it does here. -- Arndt Jonasson, ZYX AB, Styrmansgatan 6, 114 54 Stockholm, Sweden email address: arndt@zyx.SE or !mcsun!sunic!zyx!arndt