GCC from SuSE8.2 has bug in handling of floating point constants
Joerg Wleklik
joerg@wleklik.de
Mon Jun 16 14:30:00 GMT 2003
Hi,
I detected an bug in the handling of floating point constants in the GCC 3.3
version, delivered with SuSE Linux 8.2.
If there is not explicit an other definition an floating point constant has to
be handled as a double value. The GCC version from the SuSE 8.2 does not so.
If the value of the constant is in the range of float the compiler handles the
value as float value. That seems to be OK but if you compare a double
variable against the constant, the double variable will be converted into
float and that may fail.
Example:
A simple if-statement in 'C'
if(Block > 999999.)
will be compiled to:
fldl 0xfffffff8(%ebp) <-- Load the value of Block
fstps 0xffffffec(%ebp) <-- Store the value and convert
convert it float
flds 0xffffffec(%ebp) <-- Load value of Block
flds 0x815a51c <-- Load the constant
fxch %st(1) <-- Load value of st(1) to st(0)
fucompp <-- Compare the values
: :
: :
If the value of Block is bigger as the range of 'float' this code results in
an FPU-OVERFLOW exception.
The official GCC 3.3 version from gnu.org compiles the if-statement to:
fldl 0xfffffff8(%ebp) <-- Load the value of Block
fldl 0x815a51c <-- Load the constant
fxch %st(1) <-- Load value of st(1) to st(0)
fucompp <-- Compare the values
: :
: :
This works as expected without an exception.
There is a short example attached.
Regards,
Joerg Wleklik
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.cpp.tgz
Type: application/x-tgz
Size: 845 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20030616/45e6d941/attachment.bin>
More information about the Gcc-help
mailing list