linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pavel Roskin <proski@gnu.org>
To: linux-sparse@vger.kernel.org
Subject: Bogus warning when comparing nocast short variables
Date: Wed, 21 Jul 2010 12:51:02 -0400	[thread overview]
Message-ID: <1279731062.9003.15.camel@mj> (raw)

Hello!

This test file causes a warning:

typedef short __attribute__((nocast)) u16;
int main(int argc, char **argv)
{
        u16 i = (u16)argc;
        u16 j = (u16)2;
        return (i == j);
}

$ sparse test1.c 
test1.c:6:17: warning: implicit cast from nocast type
test1.c:6:22: warning: implicit cast from nocast type

But this file doesn't cause any warning:

typedef short __attribute__((nocast)) u16;
int main(int argc, char **argv)
{
        u16 i = (u16)argc;
        u16 j = (u16)2;
        switch (i) {
                case j: return 1;;
                default: return 0;;
        }
}

I think the warnings are bogus.  No cast should be needed to compare
variables of the same type.

The warning was actually found in the current Linux kernel, driver
zd1121rw.  A fix was proposed, but I thing the fix belongs to the sparse
code.

-- 
Regards,
Pavel Roskin

             reply	other threads:[~2010-07-21 16:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-21 16:51 Pavel Roskin [this message]
2010-07-22 22:35 ` Bogus warning when comparing nocast short variables Chris 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=1279731062.9003.15.camel@mj \
    --to=proski@gnu.org \
    --cc=linux-sparse@vger.kernel.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).