[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <48B5CE61.8020809@zytor.com>
Date: Wed, 27 Aug 2008 15:00:01 -0700
From: "H. Peter Anvin" <hpa@...or.com>
To: Roland Dreier <rdreier@...co.com>
CC: linux-kernel@...r.kernel.org
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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists