From owner-svn-src-head@FreeBSD.ORG Mon Mar 23 00:07:11 2015 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 6DB2C613; Mon, 23 Mar 2015 00:07:11 +0000 (UTC) Received: from mail106.syd.optusnet.com.au (mail106.syd.optusnet.com.au [211.29.132.42]) by mx1.freebsd.org (Postfix) with ESMTP id 2FD4FBCD; Mon, 23 Mar 2015 00:07:10 +0000 (UTC) Received: from c211-30-166-197.carlnfd1.nsw.optusnet.com.au (c211-30-166-197.carlnfd1.nsw.optusnet.com.au [211.30.166.197]) by mail106.syd.optusnet.com.au (Postfix) with ESMTPS id 4DBFA3C2993; Mon, 23 Mar 2015 10:50:05 +1100 (AEDT) Date: Mon, 23 Mar 2015 10:50:02 +1100 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Dimitry Andric Subject: Re: svn commit: r280357 - head/bin/expr In-Reply-To: <201503222240.t2MMeWJs061829@svn.freebsd.org> Message-ID: <20150323102927.U1476@besplex.bde.org> References: <201503222240.t2MMeWJs061829@svn.freebsd.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.1 cv=A5NVYcmG c=1 sm=1 tr=0 a=KA6XNC2GZCFrdESI5ZmdjQ==:117 a=PO7r1zJSAAAA:8 a=kj9zAlcOel0A:10 a=JzwRw_2MAAAA:8 a=UdIJsax14pPILPEZKswA:9 a=CjuIK1q_8ugA:10 Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 Mar 2015 00:07:11 -0000 On Sun, 22 Mar 2015, Dimitry Andric wrote: > Log: > Build expr with -fwrapv, since it relies on signed integer wrapping > having defined behavior. This was supposed to be fixed using a volatile hack, but I see that was only for multiplication. Wrapping is not undefined behaviour. You mean overflow. expr mainly relies on the undefined behaviour giving a result and not causing the tests that the result is correct being optimized away. All compilers on all normal systems give a result. The volatile hack prevents the excessive optimization. But expr uses sloppy tests for addition and subtraction. For multiplication and division, there is no simple correctness test and expr does a complete test. For addition and multiplication, it assumes that the overflow gives (2's complement) wrapping so that simple sign tests work. > Modified: head/bin/expr/Makefile > ============================================================================== > --- head/bin/expr/Makefile Sun Mar 22 22:00:29 2015 (r280356) > +++ head/bin/expr/Makefile Sun Mar 22 22:40:32 2015 (r280357) > @@ -6,6 +6,9 @@ PROG= expr > SRCS= expr.y > YFLAGS= > > +# expr relies on signed integer wrapping > +CFLAGS+= -fwrapv Hard-coded gcc flags make compiling with non-gcc compilers impossible. -fwrapv implies 2's complement, so might not be supported even by gcc. Bruce