OMG, -10==10 in linux! (with gcc prior to 20071117)
Alexander E. Patrakov
patrakov at gmail.com
Tue Nov 20 01:20:54 MST 2007
Code from http://lkml.org/lkml/2007/11/19/493:
#include <stdio.h>
#include <stdlib.h>
int main( void )
{
int i=2;
if( -10*abs (i-1) == 10*abs(i-1) )
printf ("OMG,-10==10 in linux!\n");
else
printf ("nothing special here\n") ;
return 0 ;
}
GCC miscompiles this, because it thinks that, for builtin abs(),
A*abs(B) is the same as abs(A*B) even if A is negative (this is also
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34130). Patch is available
from http://gcc.gnu.org/viewcvs/trunk/gcc/fold-const.c?r1=130258&r2=130257&view=patch&pathrev=130258
Expectations on LKML are that distributions should handle this bug
with the same urgency as security vulnerabilities (but this is in fact
worse: one has to recompile almost anything with the new gcc to be
sure that all manifestations of this bug are removed). I.e., this is
an obvious candidate for the errata page, or even LFS-6.3.1 (because
of jhalfs).
--
Alexander E. Patrakov
More information about the lfs-dev
mailing list