"sparse" warnings..

Linus Torvalds torvalds at osdl.org
Tue May 4 04:04:35 EST 2004


On Mon, 3 May 2004 linas at austin.ibm.com wrote:
>
> About a year ago, we fixed some real-live bugs due to comparisons to
> "-1" done on unsigned quantities.

That's a separate issue, since there the issue is not the implicit
conversion of the constant itself, but the implicit integer conversion
that happens in any integer expressions.

The particular example you cite can be (fairly trivially) caught by a
warning that checks whether a particular constant comparison can ever be
true or not, and in fact gcc will warn about this in at least some
incarnations ("comparison can never be true due to limited type" or
similar). So while I might add that warning to sparse, I don't have any
huge incentives simply because it already exists as a "regular C"
warning.

(It might happen, just because I do actually want the sparse front-end to
be usable for a real back-end too, if only for testing coverage reasons).

>    if (thingy() == (u16) ~0) { ...}
>
> I don't know if 'sparse' checks for this, but if it doesn't, it would
> be nice if it did.  (Personally, I dislike ~0, but that's a different
> matter).

One thing I've been considering adding is a "no-implicit-cast" attribute,
which would make it a warning if such a type is ever implicitly cast to
another type. That _would_ warn about things like the above, ie it would
have warned about "thingy()" being implicitly promoted to an "int" for the
comparison.

But I'm not sure how useful such an attribute would be.

			Linus

** Sent via the linuxppc64-dev mail list. See http://lists.linuxppc.org/





More information about the Linuxppc64-dev mailing list