summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2019-06-04 18:02:11 -0400
committerBen Gamari <ben@smart-cactus.org>2019-06-04 18:02:11 -0400
commitd21c21fc9ba41b43675254d2b30cab68d936a8ae (patch)
treeeee59768bc5ccb8ee92cbe7d19db15d2c2f905bc
parenta91acd25e4ca1ac86c9700ef45e3ba4d29c643c5 (diff)
parentc26461fcab27fbad8abafedc085a0edc3d28eb59 (diff)
downloadhaskell-d21c21fc9ba41b43675254d2b30cab68d936a8ae.tar.gz
Merge remote-tracking branch 'osa1/port_16449_ghc_8_8' into wip/ghc-8.8-merges
-rw-r--r--compiler/prelude/PrelRules.hs5
-rw-r--r--testsuite/tests/codeGen/should_compile/T16449_1.hs8
-rw-r--r--testsuite/tests/codeGen/should_compile/all.T2
-rw-r--r--testsuite/tests/codeGen/should_run/T16449_2.hs9
-rw-r--r--testsuite/tests/codeGen/should_run/T16449_2.stderr1
-rw-r--r--testsuite/tests/codeGen/should_run/all.T1
6 files changed, 25 insertions, 1 deletions
diff --git a/compiler/prelude/PrelRules.hs b/compiler/prelude/PrelRules.hs
index 7111c7b07a..b0ad91db99 100644
--- a/compiler/prelude/PrelRules.hs
+++ b/compiler/prelude/PrelRules.hs
@@ -467,13 +467,16 @@ shiftRule :: (DynFlags -> Integer -> Int -> Integer) -> RuleM CoreExpr
-- Used for shift primops
-- ISllOp, ISraOp, ISrlOp :: Word# -> Int# -> Word#
-- SllOp, SrlOp :: Word# -> Int# -> Word#
--- See Note [Guarding against silly shifts]
shiftRule shift_op
= do { dflags <- getDynFlags
; [e1, Lit (LitNumber LitNumInt shift_len _)] <- getArgs
; case e1 of
_ | shift_len == 0
-> return e1
+ -- See Note [Guarding against silly shifts]
+ | shift_len < 0 || shift_len > wordSizeInBits dflags
+ -> return $ mkRuntimeErrorApp rUNTIME_ERROR_ID wordPrimTy
+ ("Bad shift length " ++ show shift_len)
-- Do the shift at type Integer, but shift length is Int
Lit (LitNumber nt x t)
diff --git a/testsuite/tests/codeGen/should_compile/T16449_1.hs b/testsuite/tests/codeGen/should_compile/T16449_1.hs
new file mode 100644
index 0000000000..b1ec71efef
--- /dev/null
+++ b/testsuite/tests/codeGen/should_compile/T16449_1.hs
@@ -0,0 +1,8 @@
+module T16449_1 where
+
+import Data.Bits (setBit)
+
+f :: Int
+f = foldl setter 0 $ zip [0..] [()]
+ where
+ setter v (ix, _) = setBit v ix
diff --git a/testsuite/tests/codeGen/should_compile/all.T b/testsuite/tests/codeGen/should_compile/all.T
index 7217d93e30..7a9229533d 100644
--- a/testsuite/tests/codeGen/should_compile/all.T
+++ b/testsuite/tests/codeGen/should_compile/all.T
@@ -52,3 +52,5 @@ test('T15723',
[ unless(have_profiling(), skip),
unless(have_dynamic(), skip),
], run_command, ['$MAKE -s --no-print-directory T15723'])
+
+test('T16449_1', normal, compile, [''])
diff --git a/testsuite/tests/codeGen/should_run/T16449_2.hs b/testsuite/tests/codeGen/should_run/T16449_2.hs
new file mode 100644
index 0000000000..3424d43e25
--- /dev/null
+++ b/testsuite/tests/codeGen/should_run/T16449_2.hs
@@ -0,0 +1,9 @@
+{-# LANGUAGE MagicHash #-}
+
+module Main where
+
+import GHC.Prim
+import GHC.Int
+
+-- Shift should be larger than the word size (e.g. 64 on 64-bit) for this test.
+main = print (I# (uncheckedIShiftL# 1# 1000#))
diff --git a/testsuite/tests/codeGen/should_run/T16449_2.stderr b/testsuite/tests/codeGen/should_run/T16449_2.stderr
new file mode 100644
index 0000000000..869a5b0f91
--- /dev/null
+++ b/testsuite/tests/codeGen/should_run/T16449_2.stderr
@@ -0,0 +1 @@
+T16449_2: Bad shift length 1000
diff --git a/testsuite/tests/codeGen/should_run/all.T b/testsuite/tests/codeGen/should_run/all.T
index 7f976b8107..ade88df6ab 100644
--- a/testsuite/tests/codeGen/should_run/all.T
+++ b/testsuite/tests/codeGen/should_run/all.T
@@ -192,3 +192,4 @@ test('T15892',
# happen, so -G1 -A32k:
extra_run_opts('+RTS -G1 -A32k -RTS') ],
compile_and_run, ['-O'])
+test('T16449_2', exit_code(1), compile_and_run, [''])