-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LLVM code generation bug: decode . encode != id #67
Comments
I couldn't reproduce issue. But here is observation |
I've written a tiny bit of code to put this bug in the regression suite, but can't reproduce this either. Can you specifically list what GHC version you're using and what platform you're running on? (e.g. GHC 7.10.3 on i386/Linux or amd64/OSX, etc). I'll push the test addition to a branch and report back here so you can test the reduced case and see if it triggers. |
I was using NixOS / amd64:
After I rebuild it without LLVM, it wasn't there; similarly for testing it in GHCi. So maybe it's a GHC codegen bug? Currently I'm rebuilding everything with LLVM again, to see if it's still there. Edit: yep, still there |
Thanks for investigating. Yes, not good. Should get to the bottom of it. |
Confirmed with GHC 7.10.3/LLVM 3.5 and GHC 8.0.1-rc4/LLVM 3.7 - the bug from a small reproducer trips this perfectly. |
This only trips under LLVM, however. Some other tests fail as well, but this one is specific and we might as well add it at the low-low cost of a few more seconds to run the tests. Signed-off-by: Austin Seipp <austin@well-typed.com>
This can now be tripped by simply compiling the tests with |
I've minimized this quite far (thanks to {-# LANGUAGE MagicHash #-}
module Main
( main -- :: IO ()
) where
import Foreign.ForeignPtr (withForeignPtr)
import Foreign.Ptr
import GHC.Exts
import Data.ByteString (ByteString)
import qualified Data.ByteString as B
import qualified Data.ByteString.Internal as BS
import qualified Data.ByteString.Unsafe as BU (unsafeTail)
withBsPtr :: (Ptr b -> a) -> ByteString -> a
withBsPtr f (BS.PS x off _) =
BS.accursedUnutterablePerformIO $ withForeignPtr x $
\(Ptr addr#) -> return $! (f (Ptr addr# `plusPtr` off))
{-# INLINE withBsPtr #-}
grabWord16 :: Ptr () -> Word
grabWord16 (Ptr ip#) = W# (byteSwap16# (indexWord16OffAddr# ip# 0#))
{-# INLINE grabWord16 #-}
trip :: ByteString -> Int
trip bs = fromIntegral (withBsPtr grabWord16 (BU.unsafeTail bs))
{-# INLINE trip #-}
main :: IO ()
main = print (trip $ B.pack [0x19, 0xcf, 0xb1]) Testing:
|
Even smaller: {-# LANGUAGE BangPatterns #-}
{-# LANGUAGE MagicHash #-}
module Main
( main -- :: IO ()
) where
import GHC.Prim
import GHC.Word
data T = T !Addr#
t :: T
t = T "\xcf\xb1"#
grabWord16 :: T -> Word
grabWord16 (T addr#) = W# (byteSwap16# (indexWord16OffAddr# addr# 0#))
trip :: Int
trip = fromIntegral (grabWord16 t)
main :: IO ()
main = print trip |
Reported as GHC bug #12095. |
Not actually a GHC bug, this is our bug! Commit incoming with a fix... |
@thoughtpolice nice work tracking it down! |
I was running the serial-bench tests with CBOR commit ab0f193, and this turned up:
The text was updated successfully, but these errors were encountered: