summaryrefslogtreecommitdiff
path: root/testsuite
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2021-07-21 13:21:56 -0400
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-07-23 21:09:52 -0400
commita31aa2716b80e617c36db816460faa94ee952b64 (patch)
treed3d8fdc316fcb04a527e8c652c21b5d88c985ed7 /testsuite
parentb6434ed3f90f322bacc586ee08004bf4915002f9 (diff)
downloadhaskell-a31aa2716b80e617c36db816460faa94ee952b64.tar.gz
testsuite: Add test for #20142
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/tests/cmm/opt/T20142.hs30
-rw-r--r--testsuite/tests/cmm/opt/all.T1
2 files changed, 31 insertions, 0 deletions
diff --git a/testsuite/tests/cmm/opt/T20142.hs b/testsuite/tests/cmm/opt/T20142.hs
new file mode 100644
index 0000000000..c729265009
--- /dev/null
+++ b/testsuite/tests/cmm/opt/T20142.hs
@@ -0,0 +1,30 @@
+{-# LANGUAGE BangPatterns, CPP, MagicHash, RankNTypes, ScopedTypeVariables, UnboxedTuples #-}
+{-# OPTIONS_GHC -O2 -dcmm-lint #-}
+
+module Data.Text.Lazy.Builder.Int ( hexadecimal) where
+
+import GHC.Exts
+import Data.Int (Int8)
+import Prelude
+
+type Builder = [Char]
+
+singleton :: a -> [a]
+singleton x = [x]
+
+hexadecimal :: Int8 -> Builder
+hexadecimal i = go i
+ where
+ go n | n < 16 = hexDigit n
+ | otherwise = go (n `quot` 16) <> hexDigit (n `rem` 16)
+{-# NOINLINE[0] hexadecimal #-}
+
+hexDigit :: Integral a => a -> Builder
+hexDigit n
+ | n <= 9 = singleton $! i2d (fromIntegral n)
+ | otherwise = singleton $! toEnum (fromIntegral n + 87)
+{-# INLINE hexDigit #-}
+
+{-# INLINE i2d #-}
+i2d :: Int -> Char
+i2d (I# i#) = C# (chr# (ord# '0'# +# i#))
diff --git a/testsuite/tests/cmm/opt/all.T b/testsuite/tests/cmm/opt/all.T
index da7e95d5c4..0e4fc9abf2 100644
--- a/testsuite/tests/cmm/opt/all.T
+++ b/testsuite/tests/cmm/opt/all.T
@@ -2,3 +2,4 @@
# to the same target.
test('T15188', normal, makefile_test, [])
test('T18141', normal, compile, [''])
+test('T20142', normal, compile, [''])