[commit: ghc] master: Keep `shift{L, R}` on `Integer` from segfaulting (182c44d)

git at git.haskell.org git at git.haskell.org
Sat Oct 10 13:39:36 UTC 2015


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/182c44da50db028a432a81789048c87922bd30f4/ghc

>---------------------------------------------------------------

commit 182c44da50db028a432a81789048c87922bd30f4
Author: Ben Gamari <bgamari.foss at gmail.com>
Date:   Sat Oct 10 14:32:28 2015 +0200

    Keep `shift{L,R}` on `Integer` from segfaulting
    
    This can happen because the underlying primitive operations in
    `integer-gmp` don't support negative shift-amounts, and since
    `integer-gmp` can't throw proper exceptions and just provides a
    low-level API, it simply segfaults instead...
    
    This patch simply removes the `shift{L,R}` method definitions (and
    defines `unsafeShift{L,R}` instead) whose default-impls fallback on
    using `shift` which properly handles negative shift arguments.
    
    This addresses #10571
    
    Test Plan: harbormaster can do it
    
    Reviewers: hvr, austin, rwbarton
    
    Subscribers: rwbarton, thomie, bgamari
    
    Differential Revision: https://phabricator.haskell.org/D1018
    
    GHC Trac Issues: #10571


>---------------------------------------------------------------

182c44da50db028a432a81789048c87922bd30f4
 libraries/base/Data/Bits.hs | 8 --------
 libraries/base/changelog.md | 3 +++
 2 files changed, 3 insertions(+), 8 deletions(-)

diff --git a/libraries/base/Data/Bits.hs b/libraries/base/Data/Bits.hs
index 38025f8..9134e13 100644
--- a/libraries/base/Data/Bits.hs
+++ b/libraries/base/Data/Bits.hs
@@ -515,15 +515,7 @@ instance Bits Integer where
    complement = complementInteger
    shift x i@(I# i#) | i >= 0    = shiftLInteger x i#
                      | otherwise = shiftRInteger x (negateInt# i#)
-   shiftL x i@(I# i#)
-     | i < 0        = error "Bits.shiftL(Integer): negative shift"
-     | otherwise    = shiftLInteger x i#
-   shiftR x i@(I# i#)
-     | i < 0        = error "Bits.shiftR(Integer): negative shift"
-     | otherwise    = shiftRInteger x i#
-
    testBit x (I# i) = testBitInteger x i
-
    zeroBits   = 0
 
 #if HAVE_INTEGER_GMP1
diff --git a/libraries/base/changelog.md b/libraries/base/changelog.md
index 4874808..7c4bf77 100644
--- a/libraries/base/changelog.md
+++ b/libraries/base/changelog.md
@@ -66,6 +66,9 @@
     `GHC.Generics` as part of making GHC generics capable of handling
     unlifted types (#10868)
 
+  * Keep `shift{L,R}` on `Integer` with negative shift-arguments from
+	segfaulting (#10571)
+
 ## 4.8.1.0  *Jul 2015*
 
   * Bundled with GHC 7.10.2



More information about the ghc-commits mailing list