Messages in this thread | | | Date | Wed, 27 Aug 2008 15:00:01 -0700 | From | "H. Peter Anvin" <> | Subject | Re: C language lawyers needed |
| |
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
| |