summaryrefslogtreecommitdiff
path: root/testsuite/tests/unboxedsums/unboxedsums2.hs
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/tests/unboxedsums/unboxedsums2.hs')
-rw-r--r--testsuite/tests/unboxedsums/unboxedsums2.hs34
1 files changed, 34 insertions, 0 deletions
diff --git a/testsuite/tests/unboxedsums/unboxedsums2.hs b/testsuite/tests/unboxedsums/unboxedsums2.hs
new file mode 100644
index 0000000000..115415f7c6
--- /dev/null
+++ b/testsuite/tests/unboxedsums/unboxedsums2.hs
@@ -0,0 +1,34 @@
+{-# LANGUAGE UnboxedSums, MagicHash, BangPatterns #-}
+
+module Main where
+
+import GHC.Prim
+import GHC.Types
+
+-- Code generator used to fail with illegal instruction errors when Float# is
+-- involved.
+
+toInt :: (# Int# | Float# #) -> Int#
+toInt (# i | #) = i
+toInt (# | f #) = let !(I# i) = ceiling (F# f) in i
+
+toFloat :: (# Int# | Float# #) -> Float#
+toFloat (# i | #) = let !(F# f) = fromIntegral (I# i) in f
+toFloat (# | f #) = f
+
+data D = D { f1 :: (# Int# | Float# #) }
+
+instance Show D where
+ show (D (# i | #)) = "D " ++ show (I# i)
+ show (D (# | f #)) = "D " ++ show (F# f)
+
+main :: IO ()
+main = do
+ !(F# f) <- readLn
+ print (I# (toInt (# | f #)))
+
+ !(I# i) <- readLn
+ print (F# (toFloat (# i | #)))
+
+ print (D (# | f #))
+ print (D (# i | #))