When compiling Scheme 48 with -O2, an overflow check in the internal arithmetic
gets elided. This bug showed up sometime after gcc 4.0.1. It's in 4.4.1, and
in the 4.5-20090723 snapshot. It's been seen on 32-bit Linux and 32-bit
FreeBSD.
The code snippet in question in c/scheme48vm-32.c is this:
L12553: {
b_1970X = arg0K0;
lo_a_1971X = 65535 & a_1687X;
lo_b_1972X = 65535 & b_1970X;
hi_a_1973X = 65535 & (((a_1687X)>>16));
hi_b_1974X = 65535 & (((b_1970X)>>16));
lo_c_1975X = SMALL_MULTIPLY(lo_a_1971X, lo_b_1972X);
v_1976X = SMALL_MULTIPLY(lo_a_1971X, hi_b_1974X);
v_1977X = SMALL_MULTIPLY(lo_b_1972X, hi_a_1973X);
mid_c_1978X = v_1976X + v_1977X;
c_1979X = lo_c_1975X + (((mid_c_1978X)<<16));
if ((0 < hi_a_1973X)) {
if ((0 < hi_b_1974X)) {
val_1980X = integer_multiply(arg2_1113X, y_1114X);
SvalS = val_1980X;
Scode_pointerS = ((Scode_pointerS) + 1);
arg3K0 = (Scode_pointerS);
goto L32913;}
else {
goto L12595;}}
else {
goto L12595;}}
...
L12595: {
if ((536870911 < lo_c_1975X)) {
val_2153X = integer_multiply(arg2_1113X, y_1114X);
SvalS = val_2153X;
Scode_pointerS = ((Scode_pointerS) + 1);
arg3K0 = (Scode_pointerS);
goto L32913;}
else {
if ((lo_c_1975X < 0)) {
That last test never gets run, and the consequent code does not get run, even
when lo_c_1975X is negative.
I've not been able to boil the code down to a smaller snippet: Smaller programs
containing this code compile OK.
--
Summary: -O2 generates incorrect code on i386
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: sperber at deinprogramm dot de
GCC build triplet: i386-unknown-freebsd7.2
GCC host triplet: i386-unknown-freebsd7.2
GCC target triplet: i386-unknown-freebsd7.2
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40907