From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Jens Bauer Newsgroups: gmane.lisp.guile.bugs Subject: bug#24630: guile-2.0.12: Comparison is always true warning - may cause problems. Date: Thu, 6 Oct 2016 22:49:20 +0200 Message-ID: <20161006224920484742.8f069ce7@plustv.dk> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: blaine.gmane.org 1475789817 32143 195.159.176.226 (6 Oct 2016 21:36:57 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 6 Oct 2016 21:36:57 +0000 (UTC) To: 24630@debbugs.gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Thu Oct 06 23:36:53 2016 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 1bsGKt-0003pH-5d for guile-bugs@m.gmane.org; Thu, 06 Oct 2016 23:36:15 +0200 Original-Received: from localhost ([::1]:59510 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsGKr-0003Ui-LZ for guile-bugs@m.gmane.org; Thu, 06 Oct 2016 17:36:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59134) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsGKj-0003UQ-8C for bug-guile@gnu.org; Thu, 06 Oct 2016 17:36:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bsGKg-00008j-3X for bug-guile@gnu.org; Thu, 06 Oct 2016 17:36:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:40781) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsGKf-00008Q-W5 for bug-guile@gnu.org; Thu, 06 Oct 2016 17:36:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bsGKf-0005zE-LK for bug-guile@gnu.org; Thu, 06 Oct 2016 17:36:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Jens Bauer Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Thu, 06 Oct 2016 21:36:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 24630 X-GNU-PR-Package: guile X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-guile@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.147578975522990 (code B ref -1); Thu, 06 Oct 2016 21:36:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 6 Oct 2016 21:35:55 +0000 Original-Received: from localhost ([127.0.0.1]:46969 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bsGKY-0005yj-Tm for submit@debbugs.gnu.org; Thu, 06 Oct 2016 17:35:55 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:45735) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bsFdD-0004uZ-Lp for submit@debbugs.gnu.org; Thu, 06 Oct 2016 16:51:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bsFd7-0002WU-Bt for submit@debbugs.gnu.org; Thu, 06 Oct 2016 16:51:02 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:58322) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsFd7-0002WE-8s for submit@debbugs.gnu.org; Thu, 06 Oct 2016 16:51:01 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36698) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsFd4-0002LL-ED for bug-guile@gnu.org; Thu, 06 Oct 2016 16:50:59 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bsFd0-0002UV-65 for bug-guile@gnu.org; Thu, 06 Oct 2016 16:50:57 -0400 Original-Received: from multitrading.dk ([92.246.25.51]:58257 helo=mail.multitrading.dk) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsFcz-0002J7-Lu for bug-guile@gnu.org; Thu, 06 Oct 2016 16:50:54 -0400 Original-Received: (qmail 48040 invoked from network); 6 Oct 2016 20:50:17 -0000 Original-Received: from 80-62-116-58-mobile.dk.customer.tdc.net (HELO ?192.168.1.101?) (jb@multitrading.dk@80.62.116.58) by audiovideo.dk with ESMTPA; 6 Oct 2016 20:50:17 -0000 X-Mailer: GyazMail version 1.5.17 X-detected-operating-system: by eggs.gnu.org: Mac OS X 10.x X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Mailman-Approved-At: Thu, 06 Oct 2016 17:35:54 -0400 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:8416 Archived-At: 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 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) ... 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) ? Love Jens