fix arithmetic-shift' with shifts close to (- (expt 2 31))' on 64-bit

The bug was caused by an accidental cast of a 64-bit integer to a
32-bit integer.

Closes PR 13923
This commit is contained in:
Matthew Flatt 2013-07-21 08:03:53 -06:00
parent e0dd75d52c
commit 22dbcaa77f
3 changed files with 9 additions and 1 deletions

View File

@ -45,6 +45,10 @@
(test (bitwise-arithmetic-shift -2 -1) -1)
(test (bitwise-arithmetic-shift -1 -1) -1)
(test (bitwise-arithmetic-shift-right 42 (greatest-fixnum)) 0)
(test (bitwise-arithmetic-shift-right 42 (+ 1 (greatest-fixnum))) 0)
(test (bitwise-arithmetic-shift-right 42 (+ 2 (greatest-fixnum))) 0)
(test (bitwise-reverse-bit-field #b1010010 1 4) 88) ; #b1011000
;; Originally from Ikarus test suite:

View File

@ -1181,6 +1181,10 @@
(test 0 arithmetic-shift (sub1 (expt 2 32)) -32)
(test 1 arithmetic-shift (expt 2 32) -32)
(for ([i (in-range -2 3)])
(test 0 arithmetic-shift 42 (+ i (- (expt 2 31))))
(test 0 arithmetic-shift 42 (+ i (- (expt 2 63)))))
(arity-test arithmetic-shift 2 2)
(err/rt-test (arithmetic-shift "a" 1))
(err/rt-test (arithmetic-shift 1 "a"))

View File

@ -4120,7 +4120,7 @@ scheme_bitwise_shift(int argc, Scheme_Object *argv[])
if (i > 0) {
if (shift < 0) {
int shft = -shift;
intptr_t shft = -shift;
if (shft < MAX_SHIFT_EVER) {
i = i >> shft;
return scheme_make_integer(i);