Re: C language lawyers needed
From: H. Peter Anvin
Date: Wed Aug 27 2008 - 18:00:28 EST
Roland Dreier wrote:
A fairly small test case that I don't understand either is:
unsigned foo(int x)
{
return (((x & 0xffffff) | (1 << 30)) & 0xff000000) >> 24;
}
just running "gcc -c" (ie no extra warnings enabled) on that produces
the same:
b.c: In function 'foo':
b.c:3: warning: integer overflow in expression
I'm sure there's some promotion rule or something that makes sense of
this, but it's a mystery to me...
Looks like a gcc bug to me.
0xff000000 is unsigned, like any hexadecimal constant.
unsigned foo(int x)
{
return ((x & 0xffffff) | (1 << 30)) & 0x80000000;
}
... is enough to reproduce the bug -- explicitly casting either side or
both of the & operator to unsigned doesn't affect the warning, either.
-hpa
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/