linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Bogus warning when comparing nocast short variables
@ 2010-07-21 16:51 Pavel Roskin
  2010-07-22 22:35 ` Chris Li
  0 siblings, 1 reply; 2+ messages in thread
From: Pavel Roskin @ 2010-07-21 16:51 UTC (permalink / raw)
  To: linux-sparse

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-07-22 22:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-21 16:51 Bogus warning when comparing nocast short variables Pavel Roskin
2010-07-22 22:35 ` Chris Li

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).