diff options
| author | Paul Eggert | 2018-08-17 00:25:20 -0700 |
|---|---|---|
| committer | Paul Eggert | 2018-08-17 00:26:19 -0700 |
| commit | 64eb9b71da7c3c34541929c1b0dfb7f0c11d3d88 (patch) | |
| tree | 0b905edf417cb3e62706d84e5776a2a26065453f /test | |
| parent | 3b9017b5ba6b7041fbf70691092533286cc9b98d (diff) | |
| download | emacs-64eb9b71da7c3c34541929c1b0dfb7f0c11d3d88.tar.gz emacs-64eb9b71da7c3c34541929c1b0dfb7f0c11d3d88.zip | |
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')
| -rw-r--r-- | test/src/data-tests.el | 14 |
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." | |||
| 597 | (should (< (1- most-negative-fixnum) most-negative-fixnum)) | 597 | (should (< (1- most-negative-fixnum) most-negative-fixnum)) |
| 598 | (should (fixnump (1- (1+ most-positive-fixnum))))) | 598 | (should (fixnump (1- (1+ most-positive-fixnum))))) |
| 599 | 599 | ||
| 600 | (ert-deftest data-tests-logand () | ||
| 601 | (should (= -1 (logand -1))) | ||
| 602 | (let ((n (* 2 most-negative-fixnum))) | ||
| 603 | (should (= (logand -1 n) n)))) | ||
| 604 | |||
| 600 | (ert-deftest data-tests-logcount () | 605 | (ert-deftest data-tests-logcount () |
| 601 | (should (= (logcount (read "#xffffffffffffffffffffffffffffffff")) 128))) | 606 | (should (= (logcount (read "#xffffffffffffffffffffffffffffffff")) 128))) |
| 602 | 607 | ||
| 608 | (ert-deftest data-tests-logior () | ||
| 609 | (should (= -1 (logior -1))) | ||
| 610 | (should (= -1 (logior most-positive-fixnum most-negative-fixnum)))) | ||
| 611 | |||
| 612 | (ert-deftest data-tests-logxor () | ||
| 613 | (should (= -1 (logxor -1))) | ||
| 614 | (let ((n (1+ most-positive-fixnum))) | ||
| 615 | (should (= (logxor -1 n) (lognot n))))) | ||
| 616 | |||
| 603 | (ert-deftest data-tests-minmax () | 617 | (ert-deftest data-tests-minmax () |
| 604 | (let ((a (- most-negative-fixnum 1)) | 618 | (let ((a (- most-negative-fixnum 1)) |
| 605 | (b (+ most-positive-fixnum 1)) | 619 | (b (+ most-positive-fixnum 1)) |