linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christopher Li <sparse@chrisli.org>
To: Pavel Roskin <proski@gnu.org>
Cc: linux-sparse@vger.kernel.org
Subject: Re: Fixing "cast truncates bits from constant value"
Date: Tue, 18 Aug 2009 22:36:53 -0700	[thread overview]
Message-ID: <70318cbf0908182236h21c5d342o15bb658a445fc476@mail.gmail.com> (raw)
In-Reply-To: <1250542922.10511.38.camel@mj>

On Mon, Aug 17, 2009 at 2:02 PM, Pavel Roskin<proski@gnu.org> wrote:
> static unsigned short test(void)
> {
>        return (unsigned short)~0x8000;
> }
>
> test.c:3:32: warning: cast truncates bits from constant value (ffff7fff
> becomes 7fff)

That warning is legit because you ARE truncating constant value here.

> In my opinion, an explicit cast should be enough to suppress the
> warning.  But it's not.  Moreover, it's a "superwarning" that cannot
> even be suppressed by the "force" attribute!  This source still
> generates a warning:
>
> static unsigned short test(void)
> {
>        return (__attribute__((force)) unsigned short)~0x8000;

Sparse currently does not thing than just mark it as forced.


>
> But this source doesn't:
>
> static unsigned short test(void)
> {
>        return 0xfffff000U;
> }

I think sparse consider it as signed extend.
Truncating all 0xffff is consider OK for the negative case.

Chris
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2009-08-19  5:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-17 21:02 Fixing "cast truncates bits from constant value" Pavel Roskin
2009-08-19  5:36 ` Christopher Li [this message]
2009-08-19 23:28   ` Pavel Roskin
2009-08-20  6:55     ` Christopher Li

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=70318cbf0908182236h21c5d342o15bb658a445fc476@mail.gmail.com \
    --to=sparse@chrisli.org \
    --cc=linux-sparse@vger.kernel.org \
    --cc=proski@gnu.org \
    /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;
as well as URLs for NNTP newsgroup(s).