petdance/scratch — Issue #381: possible problem with g++ --optimize (t/pmc/float.t failure)
Author: petdance
Created: 2011-11-01 05:42:11+00:00
State: open
Labels: bug, build, Pri-normal, Sev-medium

In testing t/pmc/float.t it failed a test when built with g++-4.5 with --optimize.
Failed test: 102 - comparison ops: cmp_p_p: equality (passes g++ without --optimize and gcc - Ubuntu 10.10 i386)

kid51 reported that the test passed for him using g++ v4.3.2

I did some further tests with Ubuntu 10.04 i386 and Ubuntu 10.10 i386 and it failed (g++ --optimize only) with g++ v4.4.3 and v4.5.1

NotFound and cotto both managed to reproduce the error using g++ v4.4.5

NotFound proposed a patch, which fixed the problem and cotto committed
{{{
diff --git a/src/pmc/float.pmc b/src/pmc/float.pmc
index e31cf55..dc8e06e 100644
--- a/src/pmc/float.pmc
+++ b/src/pmc/float.pmc
@@ -285,8 +285,9 @@ Returns the result of comparing the number with C<*value>.
}

MULTI INTVAL cmp_num(DEFAULT value) {
- const FLOATVAL diff =
- SELF.get_number() - VTABLE_get_number(INTERP, value);
+ volatile FLOATVAL n1 = SELF.get_number();
+ volatile FLOATVAL n2 = VTABLE_get_number(INTERP, value);
+ const FLOATVAL diff = n1 - n2;
return diff > 0 ? 1 : diff < 0 ? -1 : 0;
}

}}}

this fixed the failure.

The main reason for creating the ticket (apart from cotto asking me to) is that we had a failure with g++ --optimize 32 bit (later versions) that did not occur without --optimize or with gcc. The test did not fail on 64 bit (perhaps because of different ways of handling floating point).

Originally http://trac.parrot.org/parrot/ticket/1978