linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Casting 0 to a __bitwise type
@ 2017-02-14 21:36 Edward Cree
  2017-02-14 22:51 ` Luc Van Oostenryck
  0 siblings, 1 reply; 7+ messages in thread
From: Edward Cree @ 2017-02-14 21:36 UTC (permalink / raw)
  To: linux-sparse

I'm given to understand that bitwise types consider 0 'special', in that
 sparse will allow, say:
        typedef __u32 __bitwise __be32;
        __be32 value = 0;
However, it appears that if I try to cast a constant 0 to a bitwise type,
        static inline void ip6_fill_mask(__be32 *mask)
        {
                mask[0] = mask[1] = mask[2] = mask[3] = ~(__be32)0;
        }
sparse complains "warning: cast to restricted __be32".
Why is this?  Is there some subtle reason why the cast is incorrect, or
 is sparse just unable to notice that the value being cast is 0?
It allows it if I rewrite it with a local variable, making the cast
 implicit:
        static inline void ip6_fill_mask(__be32 *mask)
        {
                __be32 nothing = 0;

                mask[0] = mask[1] = mask[2] = mask[3] = ~nothing;
        }

-Ed
The information contained in this message is confidential and is intended for the addressee(s) only. If you have received this message in error, please notify the sender immediately and delete the message. Unless you are an addressee (or authorized to receive for an addressee), you may not use, copy or disclose to anyone this message or any information contained in this message. The unauthorized use, disclosure, copying or alteration of this message is strictly prohibited.

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

end of thread, other threads:[~2017-02-17 14:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-14 21:36 Casting 0 to a __bitwise type Edward Cree
2017-02-14 22:51 ` Luc Van Oostenryck
2017-02-17 11:01   ` Edward Cree
2017-02-17 12:37     ` Luc Van Oostenryck
2017-02-17 13:13       ` Edward Cree
2017-02-17 14:16         ` Luc Van Oostenryck
2017-02-17 14:56           ` Edward Cree

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