[poc] buildkernel + clang + -Werror

Warner Losh imp at bsdimp.com
Mon Nov 7 00:39:53 UTC 2011


On Nov 6, 2011, at 1:58 PM, Alexander Best wrote:

> On Sun Nov  6 11, Dimitry Andric wrote:
>> On 2011-11-06 21:33, Alexander Best wrote:
>> ... 
>>> the problem is, something like
>>> 
>>> uint x;
>>> 
>>> if (x < 0) ...
>>> 
>>> clang will warn about this, yet it is 100% valid code so my vote would be to
>>> make such an error into a warning.
>> 
>> Sorry, but checking something unsigned to be smaller than zero is bogus,
>> or at the least superfluous, and it's perfectly sane to warn about this,
>> especially since the compiler is not going to emit code for it at all.
> 
> there was a discussion with the topic
> "disable -Wtautological-compare for clang" on freebsd-toolchain@ and most of
> the devs considered this code *not* to be bogus. ;)

The code actually is bogus.  It may be masking a real problem, because often times it is a "sanity check" to make sure that you aren't doing something naughty, like passing -1 for the length.  However, if you then pass the unsigned through a signed value, it suddenly becomes negative, and you have a hard to spot bug.  IIR the the tread, there weren't too many people offering an opinion...

Warner


More information about the freebsd-toolchain mailing list