From: "H. Peter Anvin" <hpa@zytor.com>
To: Roland Dreier <rdreier@cisco.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: C language lawyers needed
Date: Wed, 27 Aug 2008 15:00:01 -0700 [thread overview]
Message-ID: <48B5CE61.8020809@zytor.com> (raw)
In-Reply-To: <adaod3ef82e.fsf@cisco.com>
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
next prev parent reply other threads:[~2008-08-27 22:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-27 21:43 C language lawyers needed Roland Dreier
2008-08-27 22:00 ` H. Peter Anvin [this message]
2008-08-27 22:17 ` Al Viro
2008-08-27 22:18 ` H. Peter Anvin
2008-08-27 22:06 ` Al Viro
2008-08-27 23:02 ` Roland Dreier
2008-09-01 6:25 ` Roland Dreier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=48B5CE61.8020809@zytor.com \
--to=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rdreier@cisco.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox