summaryrefslogtreecommitdiff
path: root/testsuite/tests/codeGen/should_run/cgrun066.hs
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/tests/codeGen/should_run/cgrun066.hs')
-rw-r--r--testsuite/tests/codeGen/should_run/cgrun066.hs22
1 files changed, 22 insertions, 0 deletions
diff --git a/testsuite/tests/codeGen/should_run/cgrun066.hs b/testsuite/tests/codeGen/should_run/cgrun066.hs
new file mode 100644
index 0000000000..aa1c621d71
--- /dev/null
+++ b/testsuite/tests/codeGen/should_run/cgrun066.hs
@@ -0,0 +1,22 @@
+{-# LANGUAGE MagicHash, BangPatterns #-}
+{-# OPTIONS_GHC -O0 #-}
+
+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#
+
+-- Infinite loops with new code generator + C-- optimizations
+main = do
+ withCStringLen "ff" $ \(ptr, l) -> do
+ print (hashStr (castPtr ptr) l)