summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Z. Yang <ezyang@mit.edu>2011-06-28 08:20:50 -0400
committerEdward Z. Yang <ezyang@mit.edu>2011-06-28 08:20:50 -0400
commited6f0d62ef483ec01d443a630e3cf806a7a094df (patch)
tree9c909f096a631cf83afbe2731517d5bdc7663f96
parent3d99ee1507fedf9e583a4397e41e3310bcc70b6c (diff)
downloadhaskell-ed6f0d62ef483ec01d443a630e3cf806a7a094df.tar.gz
Another variant of hashStr, this one caught a Hoopl bug.
Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
-rw-r--r--testsuite/tests/ghc-regress/codeGen/should_compile/all.T1
-rw-r--r--testsuite/tests/ghc-regress/codeGen/should_compile/cg008.hs21
2 files changed, 22 insertions, 0 deletions
diff --git a/testsuite/tests/ghc-regress/codeGen/should_compile/all.T b/testsuite/tests/ghc-regress/codeGen/should_compile/all.T
index 2f61d79399..ba29c2a145 100644
--- a/testsuite/tests/ghc-regress/codeGen/should_compile/all.T
+++ b/testsuite/tests/ghc-regress/codeGen/should_compile/all.T
@@ -5,6 +5,7 @@ test('cg004', normal, compile, [''])
test('cg005', only_ways(['optasm']), compile, [''])
test('cg006', normal, compile, [''])
test('cg007', normal, compile, [''])
+test('cg008', normal, compile, [''])
test('1916', normal, compile, [''])
test('2388', normal, compile, [''])
diff --git a/testsuite/tests/ghc-regress/codeGen/should_compile/cg008.hs b/testsuite/tests/ghc-regress/codeGen/should_compile/cg008.hs
new file mode 100644
index 0000000000..10099c1b48
--- /dev/null
+++ b/testsuite/tests/ghc-regress/codeGen/should_compile/cg008.hs
@@ -0,0 +1,21 @@
+{-# LANGUAGE MagicHash, BangPatterns #-}
+{-# OPTIONS_GHC -O0 #-}
+
+-- Variant of cgrun066; compilation as a module is different.
+
+module Cg008 (hashStr) where
+
+import Foreign.C
+import Data.Word
+import Foreign.Ptr
+import GHC.Exts
+
+import Control.Exception
+
+hashStr :: Ptr Word8 -> Int -> Int
+hashStr (Ptr a#) (I# len#) = loop 0# 0#
+ where
+ loop h n | n GHC.Exts.==# len# = I# h
+ | otherwise = loop h2 (n GHC.Exts.+# 1#)
+ where !c = ord# (indexCharOffAddr# a# n)
+ !h2 = (c GHC.Exts.+# (h GHC.Exts.*# 128#)) `remInt#` 4091#