Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!rutgers!mit-eddie!uw-beaver!rice!sun-spots-request From: flee@shire.cs.psu.edu (Felix Lee) Newsgroups: comp.sys.sun Subject: Sun4 C compiler generates bad code under strange conditions Message-ID: <8902021245.AA22000@shire.cs.psu.edu> Date: 9 Feb 89 03:38:21 GMT Sender: usenet@rice.edu Organization: Sun-Spots Lines: 16 Approved: Sun-Spots@rice.edu Original-Date: Thu, 02 Feb 89 07:45:00 EST X-Sun-Spots-Digest: Volume 7, Issue 146, message 2 of 8 Compile and run the following (on a Sun4/260, SunOS4.0): main() { printf("%d %d\n", x(0), x(1)); } x(a) int a; { return (a==0) ? 99 : y() + y(); } y() { return 12; } Curiously enough, it prints 0 and 12, instead of 99 and 24. Looking at the assembly code, the compiler is putting the intermediate return value of x() into %i5, instead of somewhere useful, like %o0. If you compile with at least -O2 optimization, it works correctly. -- Felix Lee flee@shire.cs.psu.edu *!psuvax1!shire!flee [[ Send it to Sun (if you haven't already)! They'll see it someday. --wnl ]]