From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Andy Wingo Newsgroups: gmane.lisp.guile.bugs Subject: bug#24630: guile-2.0.12: Comparison is always true warning - may cause problems. Date: Wed, 01 Mar 2017 10:18:28 +0100 Message-ID: <87mvd5icd7.fsf@pobox.com> References: <20161006224920484742.8f069ce7@plustv.dk> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1488360511 13393 195.159.176.226 (1 Mar 2017 09:28:31 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 1 Mar 2017 09:28:31 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) Cc: 24630-done@debbugs.gnu.org To: Jens Bauer Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Wed Mar 01 10:28:26 2017 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cj0YZ-0002lb-9G for guile-bugs@m.gmane.org; Wed, 01 Mar 2017 10:28:23 +0100 Original-Received: from localhost ([::1]:39282 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cj0Yf-0001RH-Av for guile-bugs@m.gmane.org; Wed, 01 Mar 2017 04:28:29 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50793) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cj0PZ-0006dc-Dx for bug-guile@gnu.org; Wed, 01 Mar 2017 04:19:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cj0PW-0006lD-9K for bug-guile@gnu.org; Wed, 01 Mar 2017 04:19:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:34570) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cj0PW-0006kx-4d for bug-guile@gnu.org; Wed, 01 Mar 2017 04:19:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cj0PV-000815-Sv for bug-guile@gnu.org; Wed, 01 Mar 2017 04:19:01 -0500 Resent-From: Andy Wingo Original-Sender: "Debbugs-submit" Resent-To: bug-guile@gnu.org Resent-Date: Wed, 01 Mar 2017 09:19:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 24630 X-GNU-PR-Package: guile X-GNU-PR-Keywords: Mail-Followup-To: 24630@debbugs.gnu.org, wingo@pobox.com, jens-guile-bug@plustv.dk Original-Received: via spool by 24630-done@debbugs.gnu.org id=D24630.148835992030784 (code D ref 24630); Wed, 01 Mar 2017 09:19:01 +0000 Original-Received: (at 24630-done) by debbugs.gnu.org; 1 Mar 2017 09:18:40 +0000 Original-Received: from localhost ([127.0.0.1]:32769 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cj0PA-00080R-4t for submit@debbugs.gnu.org; Wed, 01 Mar 2017 04:18:40 -0500 Original-Received: from pb-sasl1.pobox.com ([64.147.108.66]:56864 helo=sasl.smtp.pobox.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cj0P7-00080J-Eq for 24630-done@debbugs.gnu.org; Wed, 01 Mar 2017 04:18:38 -0500 Original-Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by pb-sasl1.pobox.com (Postfix) with ESMTP id 2AEE348F7F; Wed, 1 Mar 2017 04:18:36 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=sasl; bh=UytFoMfOpmA9qbR3hIIksHOaoQo=; b=Y5TvTA Oj+zdRj9UonlZwPugbaYzO+Xx4OYu1YgKPyFvqLl43q6pt9HjYFLeTwLXVvyjMFw cIpq2WzPIK29+sECPxjOac9fgz8V954N0AZY6su9oR78cSKxER4d07DffMyVACLJ DoaLWMgIqCyoz/SlXD2bgVO+RK9Rlz2YYE85o= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=sasl; b=VHyUqKJ88tSnHUbNTcC8TKioQIk96p3C 4abNHpoCk2oEk5TUXAS9PLb/KZ4+Ul3opQQqXyvKz2STyAuSto49FTZv8lhGeo5K rRGgpr74rx3VKxNHVPAxkktAV0hZ3GmY/I0+zHbqj1B6IPubID5IT3oZ7Lb0c2TC BJEUVRp4Lao= Original-Received: from pb-sasl1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-sasl1.pobox.com (Postfix) with ESMTP id 23F4948F7E; Wed, 1 Mar 2017 04:18:36 -0500 (EST) Original-Received: from clucks (unknown [109.190.228.233]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by pb-sasl1.pobox.com (Postfix) with ESMTPSA id 19FDC48F7D; Wed, 1 Mar 2017 04:18:34 -0500 (EST) In-Reply-To: <20161006224920484742.8f069ce7@plustv.dk> (Jens Bauer's message of "Thu, 6 Oct 2016 22:49:20 +0200") X-Pobox-Relay-ID: 0C02A622-FE60-11E6-8563-B667064AB293-02397024!pb-sasl1.pobox.com X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Original-Sender: "bug-guile" Xref: news.gmane.org gmane.lisp.guile.bugs:8609 Archived-At: Hi, On Thu 06 Oct 2016 22:49, Jens Bauer writes: > I get the following warnings, when building on Mac OS X. > (It should show up for all platforms, though): > > In file included from /Users/jens/open-source/Source/guile-2.0.12/libguile/numbers.c:9731: > /Users/jens/open-source/Source/guile-2.0.12/libguile/conv-integer.i.c: In function 'scm_to_int8': > /Users/jens/open-source/Source/guile-2.0.12/libguile/conv-integer.i.c:94: warning: comparison is always true due to limited range of data type > /Users/jens/open-source/Source/guile-2.0.12/libguile/conv-integer.i.c:94: warning: comparison is always true due to limited range of data type These are not really bugs. I mean, we shouldn't produce warnings, but GCC doesn't warn on these, so clearly there is a heuristic which clang has set differently; but the actual code is fine. In your investigations below there are some errors. I include a couple of inline comments for your enjoyment. > In file included from /Users/jens/open-source/Source/guile-2.0.12/libguile/numbers.c:9747: > /Users/jens/open-source/Source/guile-2.0.12/libguile/conv-integer.i.c: In function 'scm_to_int16': > /Users/jens/open-source/Source/guile-2.0.12/libguile/conv-integer.i.c:94: warning: comparison is always true due to limited range of data type > /Users/jens/open-source/Source/guile-2.0.12/libguile/conv-integer.i.c:94: warning: comparison is always true due to limited range of data type > > Notice that it's only from line 94, which reads... > if (n >= TYPE_MIN && n <= TYPE_MAX) > > ... looking at the top of the file, it says: "It is only for signed types", so I look in ... > > numbers.c:9731 > numbers.c:9747 > ... which is int8 and int16 (signed integers); this should be as intended. > > The variable 'n' is declared as scm_t_signed_bits, which is a scm_t_intptr, which is an intptr_t, which is just a 'long'. > > So my guess is that the problem must be with TYPE_MIN and TYPE_MAX. > > In numbers.c, line 9742, they're defined as follows: > #define TYPE scm_t_int16 > #define TYPE_MIN SCM_T_INT16_MIN > #define TYPE_MAX SCM_T_INT16_MAX > > ... looks good to me, but where's the definition of SCM_T_INT16_MIN and SCM_T_INT16_MAX ? > -It seems to be in __scm.h: > > #define SCM_I_UTYPE_MAX(type) ((type)-1) > #define SCM_I_TYPE_MAX(type,umax) ((type)((umax)/2)) > #define SCM_I_TYPE_MIN(type,umax) (-((type)((umax)/2))-1) > > #define SCM_T_UINT8_MAX SCM_I_UTYPE_MAX(scm_t_uint8) > #define SCM_T_INT8_MIN SCM_I_TYPE_MIN(scm_t_int8,SCM_T_UINT8_MAX) > #define SCM_T_INT8_MAX SCM_I_TYPE_MAX(scm_t_int8,SCM_T_UINT8_MAX) > > #define SCM_T_UINT16_MAX SCM_I_UTYPE_MAX(scm_t_uint16) > #define SCM_T_INT16_MIN SCM_I_TYPE_MIN(scm_t_int16,SCM_T_UINT16_MAX) > #define SCM_T_INT16_MAX SCM_I_TYPE_MAX(scm_t_int16,SCM_T_UINT16_MAX) > > Now, this is where things get interesting. The macros are cool, but I think the use seems to be incorrect. > > Let's try an example (SCM_T_INT16_MIN): > SCM_T_INT16_MIN = SCM_I_TYPE_MIN(scm_t_int16,SCM_T_UINT16_MAX) > Expands to ... > SCM_T_INT16_MIN = (-((scm_t_int16)((-1)/2))-1) SCM_T_UINT16_MAX expands to ((scm_t_uint16)-1) which expands to the uint16_t value 0xffff. (These intermediate expansions have type in addition to value.) SCM_T_INT16_MIN is -(0xffff/2)-1, which is (int16_t)-0x8000. > ... which can be cleaned up ... > > SCM_T_INT16_MIN = (-(((-1)/2))-1) > > A signed integer of value -1 divided by 2, is the same as bitshifting to the right by using ASR; the result will be -1. > > SCM_T_INT16_MIN = (-(((-1)))-1) > SCM_T_INT16_MIN = (-((-1))-1) > SCM_T_INT16_MIN = (-(-1)-1) > SCM_T_INT16_MIN = (+1-1) > SCM_T_INT16_MIN = (0) > > ... Ehm ... Did I do something wrong ? > I expected the value -32768, but got 0. > > Wouldn't it be correct to typecast as scm_t_uint16 instead of scm_t_int16 (and thus scm_t_uint8 instead of scm_t_int8) ? > Happy hacking, Andy