Sun4 C compiler generates bad code under strange conditions
Felix Lee
flee at shire.cs.psu.edu
Thu Feb 9 13:38:21 AEST 1989
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 at shire.cs.psu.edu *!psuvax1!shire!flee
[[ Send it to Sun (if you haven't already)! They'll see it someday.
--wnl ]]
More information about the Comp.sys.sun
mailing list