summaryrefslogtreecommitdiff
path: root/test/src/data-tests.el
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2018-08-17 00:25:20 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2018-08-17 00:26:19 -0700
commit64eb9b71da7c3c34541929c1b0dfb7f0c11d3d88 (patch)
tree0b905edf417cb3e62706d84e5776a2a26065453f /test/src/data-tests.el
parent3b9017b5ba6b7041fbf70691092533286cc9b98d (diff)
downloademacs-64eb9b71da7c3c34541929c1b0dfb7f0c11d3d88.tar.gz
Fix problems with logxor etc. and fixnums
These operations incorrectly treated negative fixnums as bignums greater than most-positive-fixnum. * src/alloc.c (mpz_set_intmax_slow): Avoid undefined behavior if signed unary negation overflows, while we’re in the neighborhood. (mpz_set_uintmax_slow): Remove. All uses removed. * src/data.c (arith_driver): Treat fixnums as signed, not unsigned, even for logical operations. * src/lisp.h (mpz_set_uintmax): Remove. All uses removed. * test/src/data-tests.el (data-tests-logand) (data-tests-logior, data-tests-logxor): New tests.
Diffstat (limited to 'test/src/data-tests.el')
-rw-r--r--test/src/data-tests.el14
1 files changed, 14 insertions, 0 deletions
diff --git a/test/src/data-tests.el b/test/src/data-tests.el
index 82649022576..a4c6b0e4915 100644
--- a/test/src/data-tests.el
+++ b/test/src/data-tests.el
@@ -597,9 +597,23 @@ comparing the subr with a much slower lisp implementation."
(should (< (1- most-negative-fixnum) most-negative-fixnum))
(should (fixnump (1- (1+ most-positive-fixnum)))))
+(ert-deftest data-tests-logand ()
+ (should (= -1 (logand -1)))
+ (let ((n (* 2 most-negative-fixnum)))
+ (should (= (logand -1 n) n))))
+
(ert-deftest data-tests-logcount ()
(should (= (logcount (read "#xffffffffffffffffffffffffffffffff")) 128)))
+(ert-deftest data-tests-logior ()
+ (should (= -1 (logior -1)))
+ (should (= -1 (logior most-positive-fixnum most-negative-fixnum))))
+
+(ert-deftest data-tests-logxor ()
+ (should (= -1 (logxor -1)))
+ (let ((n (1+ most-positive-fixnum)))
+ (should (= (logxor -1 n) (lognot n)))))
+
(ert-deftest data-tests-minmax ()
(let ((a (- most-negative-fixnum 1))
(b (+ most-positive-fixnum 1))