Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 23 Mar 2015 10:50:02 +1100 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        Dimitry Andric <dim@freebsd.org>
Cc:        svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org
Subject:   Re: svn commit: r280357 - head/bin/expr
Message-ID:  <20150323102927.U1476@besplex.bde.org>
In-Reply-To: <201503222240.t2MMeWJs061829@svn.freebsd.org>
References:  <201503222240.t2MMeWJs061829@svn.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20150323102927.U1476>