From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Miroslav Lichvar Newsgroups: gmane.lisp.guile.devel Subject: Undefined behavior in conv-integer.i.c? Date: Wed, 17 Feb 2016 17:16:39 +0100 Message-ID: <20160217161639.GE6131@localhost> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1455725816 27262 80.91.229.3 (17 Feb 2016 16:16:56 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 17 Feb 2016 16:16:56 +0000 (UTC) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Wed Feb 17 17:16:50 2016 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aW4mY-00059R-HN for guile-devel@m.gmane.org; Wed, 17 Feb 2016 17:16:50 +0100 Original-Received: from localhost ([::1]:59201 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aW4mX-0003Ko-LO for guile-devel@m.gmane.org; Wed, 17 Feb 2016 11:16:49 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48934) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aW4mU-0003KE-Id for guile-devel@gnu.org; Wed, 17 Feb 2016 11:16:47 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aW4mQ-0005FL-HH for guile-devel@gnu.org; Wed, 17 Feb 2016 11:16:46 -0500 Original-Received: from mx1.redhat.com ([209.132.183.28]:33261) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aW4mQ-0005FC-BS for guile-devel@gnu.org; Wed, 17 Feb 2016 11:16:42 -0500 Original-Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 65DC37EBAC for ; Wed, 17 Feb 2016 16:16:41 +0000 (UTC) Original-Received: from localhost (dhcp-24-154.brq.redhat.com [10.34.24.154]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u1HGGdv4011160 for ; Wed, 17 Feb 2016 11:16:40 -0500 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:18183 Archived-At: Hi, I was looking at a problem with guile-1.8.8 when compiled with gcc-6.0. Two of the tests from the test suite were failing with strange "out of range" errors [1]. After some investigation I think the bug is that the code in libguile/conv-integer.i.c relies on overflow of signed integers in the following code (starting on line 77), specifically -TYPE_MIN being less than zero. Adding -fwrapv to CFLAGS worked as a workaround for me. if (mpz_sgn (SCM_I_BIG_MPZ (val)) >= 0) { if (n < 0) goto out_of_range; } else { n = -n; if (n >= 0) goto out_of_range; } Looking at the current guile code, conv-integer.i.c is identical to what it was in 1.8.8, but interestingly the tests didn't fail for me. Maybe something else is preventing gcc from using the optimization? I'm not sure what would be the best way to fix it. Maybe n should really be unsigned and compared to the maximum values, but what would be the absolute value of TYPE_MIN if it should work also with other integer representations than two's complement? [1] https://bugzilla.redhat.com/attachment.cgi?id=1124252 -- Miroslav Lichvar