Re: Are clang unsigned comparison warnings in kern/kern_* ok?

From: Dimitry Andric <dim_at_FreeBSD.org>
Date: Wed, 05 Sep 2012 22:25:29 +0200
On 2012-09-05 19:59, Eir Nym wrote:
> I've got following warnings [no errors had been generated while
> -Werror is in command line] and want to know if they are ok.

Most of these warnings are harmless, and just point out that the
compiler will optimize unused code away, such as tests that always
succeed or fail.  In some cases it would be nice to fix them, but there
is usually no urgent need.


> /usr/head/src/sys/kern/kern_cpuset.c:654:16: warning: comparison of
> unsigned expression < 0 is always false [-Wtautological-compare]
>          for (i = 0; i < (_NCPUWORDS - 1); i++) {
>                      ~ ^ ~~~~~~~~~~~~~~~~

For example, this warning is harmless.  It turns out _NCPUWORDS is 1, at
least by default, on i386 and amd64.  So the warning is correct, in the
sense that the body of the for loop will never be executed.  It will
almost certainly be optimized away.

Maybe the loop could be enclosed in a #if _NCPUWORDS > 1 clause, to
prevent this warning.

Also note, this warning only appeared after r239923, when the for loop
was reversed.


> /usr/head/src/sys/kern/kern_poll.c:173:10: warning: comparison of
> unsigned expression < 0 is always false [-Wtautological-compare]
>          if (val < 0 || val > 99)
>              ~~~ ^ ~

This one might be fixed, since 'val' is declared as uint32_t.


> /usr/head/src/sys/kern/kern_umtx.c:3312:19: warning: comparison of
> unsigned expression < 0 is always false [-Wtautological-compare]
>                  if (ts32.tv_sec < 0 ||
>                      ~~~~~~~~~~~ ^ ~

It looks like this part of kern_umtx.c (used for COMPAT_FREEBSD32)
declares its own version of struct timespec32, where the tv_sec member
is uint32_t.  Therefore, this particular test is superfluous.
Received on Wed Sep 05 2012 - 18:25:30 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:30 UTC