From owner-freebsd-current@FreeBSD.ORG Wed Sep 5 20:25:30 2012 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 9D2F7106566C for ; Wed, 5 Sep 2012 20:25:30 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from tensor.andric.com (cl-327.ede-01.nl.sixxs.net [IPv6:2001:7b8:2ff:146::2]) by mx1.freebsd.org (Postfix) with ESMTP id 58B3B8FC0C for ; Wed, 5 Sep 2012 20:25:30 +0000 (UTC) Received: from [IPv6:2001:7b8:3a7:0:d43c:3039:49b5:2229] (unknown [IPv6:2001:7b8:3a7:0:d43c:3039:49b5:2229]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by tensor.andric.com (Postfix) with ESMTPSA id 8EE855C43; Wed, 5 Sep 2012 22:25:29 +0200 (CEST) Message-ID: <5047B539.3030000@FreeBSD.org> Date: Wed, 05 Sep 2012 22:25:29 +0200 From: Dimitry Andric Organization: The FreeBSD Project User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20120828 Thunderbird/16.0 MIME-Version: 1.0 To: Eir Nym References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-current@freebsd.org Subject: Re: Are clang unsigned comparison warnings in kern/kern_* ok? X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 05 Sep 2012 20:25:30 -0000 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.