Re: Fixing "cast truncates bits from constant value"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Aug 17, 2009 at 2:02 PM, Pavel Roskin<proski@xxxxxxx> 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@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux