[Bug c/41882] New: gcc bug when comparing x to -x (linux, 32-bit)
daven at model dot com
gcc-bugzilla@gcc.gnu.org
Fri Oct 30 22:19:00 GMT 2009
We have some legacy code that checks for INT_MIN via the
test "if (x != -x)".
With gcc 4.3.3 this test is optimized out.
Now is this wrong or right to do -- I don't know. If so, perhaps someone
could describe the reasons for me.
However -- consider the following simple code:
-- cut here (l.c) --
#include <stdio.h>
char *test(long a)
{
if (a < 0 && (a != -a)) {
return "right";
} else {
return "left";
}
}
int a;
main()
{
a = -2147483647;
printf("%s\n", test(a-1));
}
-- cut here (end of l.c) --
If I compile the code with gcc 4.3.3 and with -O2, the
function "test" seems to be inlined -- and it does what
I want:
$ gcc -O2 -m32 l.c -o ltst
$ ./ltst
left
HOWEVER if I turn off inlining, I get the "wrong" answer that's breaking
our legacy code:
$ gcc -O2 -fno-inline -m32 l.c -o ltst_noinline
$ ./ltst_noinline
right
So regardless of which is correct, they should be consistent, right?
--
Summary: gcc bug when comparing x to -x (linux, 32-bit)
Product: gcc
Version: 4.3.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: daven at model dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41882
More information about the Gcc-bugs
mailing list