diff options
author | Daishi Nakajima <nakaji.dayo@gmail.com> | 2017-01-26 18:14:08 -0500 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2017-01-26 18:14:09 -0500 |
commit | 06b9561a2f10de68cc14b68a9bfa7617c0019bd9 (patch) | |
tree | 1ebb18fa1a6e417fda86ce45005c155dfb57a610 /libraries/integer-gmp/src | |
parent | 2ffcdfadaa53c9bc4b24606dc2e28a356a60d21e (diff) | |
download | haskell-06b9561a2f10de68cc14b68a9bfa7617c0019bd9.tar.gz |
Fix the right-shift operation for negative big integers (fixes #12136)
In `x shiftR y`, any of the following conditions cause an abort:
- `x` is a negative big integer
- The size of `x` and `y` is a multiple of `GMP_NUMB_BITS`
- The bit of the absolute value of `x` is filled with `1`
For example:
Assuming `GMP_NUMB_BITS = 2`, the processing of `-15 shiftR 2` is as
follows:
1. -15 = -1111 (twos complement: 10001)
2. right shift 2 (as a positive number) -> 0011
3. Due to the shift larger than GMP_NUMB_BITS, the size of the
destination is decreasing (2bit) -> 11
4. Add 1, and get carry: (1) 00
5. abort
I fixed it that the destination size does not decrease in such a case.
Test Plan: I tested the specific case being reported.
Reviewers: goldfire, austin, hvr, bgamari, rwbarton
Reviewed By: bgamari, rwbarton
Subscribers: mpickering, rwbarton, thomie
Differential Revision: https://phabricator.haskell.org/D2998
GHC Trac Issues: #12136
Diffstat (limited to 'libraries/integer-gmp/src')
-rw-r--r-- | libraries/integer-gmp/src/GHC/Integer/Type.hs | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/libraries/integer-gmp/src/GHC/Integer/Type.hs b/libraries/integer-gmp/src/GHC/Integer/Type.hs index 035cb1e7ba..0d279ef1cc 100644 --- a/libraries/integer-gmp/src/GHC/Integer/Type.hs +++ b/libraries/integer-gmp/src/GHC/Integer/Type.hs @@ -1142,7 +1142,7 @@ shiftRNegBigNat x@(BN# xba#) n# where xn# = sizeofBigNat# x yn# = xn# -# nlimbs# - nlimbs# = quotInt# n# GMP_LIMB_BITS# + nlimbs# = quotInt# (n# -# 1#) GMP_LIMB_BITS# orBigNat :: BigNat -> BigNat -> BigNat |