diff options
author | sjg <sjg@FreeBSD.org> | 2015-05-27 01:19:58 +0000 |
---|---|---|
committer | sjg <sjg@FreeBSD.org> | 2015-05-27 01:19:58 +0000 |
commit | 65145fa4c81da358fcbc3b650156dab705dfa34e (patch) | |
tree | 55c065b6730aaac2afb6c29933ee6ec5fa4c4249 /bin/expr | |
parent | 60ff4eb0dff94a04d75d0d52a3957aaaf5f8c693 (diff) | |
parent | e6b664c390af88d4a87208bc042ce503da664c3b (diff) | |
download | FreeBSD-src-65145fa4c81da358fcbc3b650156dab705dfa34e.zip FreeBSD-src-65145fa4c81da358fcbc3b650156dab705dfa34e.tar.gz |
Merge sync of head
Diffstat (limited to 'bin/expr')
-rw-r--r-- | bin/expr/Makefile | 9 | ||||
-rw-r--r-- | bin/expr/expr.1 | 8 | ||||
-rw-r--r-- | bin/expr/expr.y | 20 | ||||
-rw-r--r-- | bin/expr/tests/Makefile | 16 |
4 files changed, 45 insertions, 8 deletions
diff --git a/bin/expr/Makefile b/bin/expr/Makefile index b86cf66..1d741b7 100644 --- a/bin/expr/Makefile +++ b/bin/expr/Makefile @@ -1,9 +1,18 @@ # $FreeBSD$ +.include <src.opts.mk> + PROG= expr SRCS= expr.y YFLAGS= +# expr relies on signed integer wrapping +CFLAGS+= -fwrapv + NO_WMISSING_VARIABLE_DECLARATIONS= +.if ${MK_TESTS} != "no" +SUBDIR+= tests +.endif + .include <bsd.prog.mk> diff --git a/bin/expr/expr.1 b/bin/expr/expr.1 index 34be0b8f..d021055 100644 --- a/bin/expr/expr.1 +++ b/bin/expr/expr.1 @@ -90,17 +90,17 @@ Return the evaluation of .Ar expr1 if neither expression evaluates to an empty string or zero; otherwise, returns zero. -.It Ar expr1 Li "{=, >, >=, <, <=, !=}" Ar expr2 +.It Ar expr1 Bro =, >, >=, <, <=, != Brc Ar expr2 Return the results of integer comparison if both arguments are integers; otherwise, returns the results of string comparison using the locale-specific collation sequence. The result of each comparison is 1 if the specified relation is true, or 0 if the relation is false. -.It Ar expr1 Li "{+, -}" Ar expr2 +.It Ar expr1 Bro +, - Brc Ar expr2 Return the results of addition or subtraction of integer-valued arguments. -.It Ar expr1 Li "{*, /, %}" Ar expr2 +.It Ar expr1 Bro *, /, % Brc Ar expr2 Return the results of multiplication, integer division, or remainder of integer-valued arguments. -.It Ar expr1 Li : Ar expr2 +.It Ar expr1 Li \&: Ar expr2 The .Dq Li \&: operator matches diff --git a/bin/expr/expr.y b/bin/expr/expr.y index 1856ec8..0ddf399 100644 --- a/bin/expr/expr.y +++ b/bin/expr/expr.y @@ -444,14 +444,26 @@ op_minus(struct val *a, struct val *b) return (r); } +/* + * We depend on undefined behaviour giving a result (in r). + * To test this result, pass it as volatile. This prevents + * optimizing away of the test based on the undefined behaviour. + */ void -assert_times(intmax_t a, intmax_t b, intmax_t r) +assert_times(intmax_t a, intmax_t b, volatile intmax_t r) { /* - * if first operand is 0, no overflow is possible, - * else result of division test must match second operand + * If the first operand is 0, no overflow is possible, + * else the result of the division test must match the + * second operand. + * + * Be careful to avoid overflow in the overflow test, as + * in assert_div(). Overflow in division would kill us + * with a SIGFPE before getting the test wrong. In old + * buggy versions, optimization used to give a null test + * instead of a SIGFPE. */ - if (a != 0 && r / a != b) + if ((a == -1 && b == INTMAX_MIN) || (a != 0 && r / a != b)) errx(ERR_EXIT, "overflow"); } diff --git a/bin/expr/tests/Makefile b/bin/expr/tests/Makefile new file mode 100644 index 0000000..80c130c --- /dev/null +++ b/bin/expr/tests/Makefile @@ -0,0 +1,16 @@ +# $FreeBSD$ + +OBJTOP= ${.OBJDIR}/../../.. +SRCTOP= ${.CURDIR}/../../.. +TESTSRC= ${SRCTOP}/contrib/netbsd-tests/bin/expr + +TESTSDIR= ${TESTSBASE}/bin/expr + +NETBSD_ATF_TESTS_SH= expr_test + +ATF_TESTS_SH_SED_expr_test+= -e 's/eval expr/eval expr --/g' +ATF_TESTS_SH_SED_expr_test+= -e 's/"expr: integer overflow or underflow occurred for operation.*"/"expr: overflow"/g' + +.include <netbsd-tests.test.mk> + +.include <bsd.test.mk> |