summaryrefslogtreecommitdiff
path: root/testsuite
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/tests/numeric/should_run/T19931.hs35
-rw-r--r--testsuite/tests/numeric/should_run/T19931.stdout1
-rw-r--r--testsuite/tests/numeric/should_run/all.T1
3 files changed, 37 insertions, 0 deletions
diff --git a/testsuite/tests/numeric/should_run/T19931.hs b/testsuite/tests/numeric/should_run/T19931.hs
new file mode 100644
index 0000000000..1ab9002d2e
--- /dev/null
+++ b/testsuite/tests/numeric/should_run/T19931.hs
@@ -0,0 +1,35 @@
+{-# LANGUAGE MagicHash #-}
+{-# LANGUAGE UnboxedTuples #-}
+
+module Main where
+
+import GHC.Exts
+import GHC.Types
+import GHC.Num
+
+data T = T Word8#
+
+instance Num T where
+ fromInteger i = T (wordToWord8# (integerToWord# i))
+
+instance Eq T where
+ (==) (T a) (T b) = isTrue# (a `eqWord8#` b)
+ (/=) (T a) (T b) = isTrue# (a `neWord8#` b)
+
+main :: IO ()
+main = do
+ let !addr = "\0\1\2\3\4\5\6\7\8"#
+
+ w8 <- IO (\s -> case readWord8OffAddr# (plusAddr# addr 5#) 0# s of
+ (# s', w8 #) -> (# s', T w8 #))
+ -- w8 must be small enough for one of the branch to be taken.
+ -- we need several alternatives for a jump table to be used
+ print $ case w8 of
+ 0 -> 1000
+ 1 -> 1001
+ 2 -> 1002
+ 3 -> 1003
+ 4 -> 1004
+ 5 -> 1005
+ 6 -> 1006
+ _ -> 1010
diff --git a/testsuite/tests/numeric/should_run/T19931.stdout b/testsuite/tests/numeric/should_run/T19931.stdout
new file mode 100644
index 0000000000..49bc2728c7
--- /dev/null
+++ b/testsuite/tests/numeric/should_run/T19931.stdout
@@ -0,0 +1 @@
+1005
diff --git a/testsuite/tests/numeric/should_run/all.T b/testsuite/tests/numeric/should_run/all.T
index 028677e52d..1123984bdd 100644
--- a/testsuite/tests/numeric/should_run/all.T
+++ b/testsuite/tests/numeric/should_run/all.T
@@ -74,5 +74,6 @@ test('T18499', normal, compile_and_run, [''])
test('T18509', normal, compile_and_run, [''])
test('T18515', normal, compile_and_run, [''])
test('T18604', normal, compile_and_run, [''])
+test('T19931', normal, compile_and_run, ['-O2'])
test('IntegerToFloat', normal, compile_and_run, [''])