Comments (11)
I couldn't reproduce issue. But here is observation fromIntegral (53169::Word16) == -12367::Int16
.
from cborg.
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.
from cborg.
I was using NixOS / amd64:
- ghc 7.10.3 from NixOS/nixpkgs@1aff127, h1i19vw3ihg4qm143ypd92y2vqchy2c0-stack-1.1.0
- stack nightly-2016-05-08 resolver
- the LLVM backend with --nix-packages llvm35 --ghc-options "-fllvm"
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
from cborg.
Thanks for investigating. Yes, not good. Should get to the bottom of it.
from cborg.
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.
from cborg.
This can now be tripped by simply compiling the tests with -fllvm
enabled (by adding it to a package binary-serialise-cbor
in cabal.project
, fixing stack.yaml
or Nix expressions or whatever). Several tests fail, actually. I'll investigate a little and see if I can dig up anything.
from cborg.
I've minimized this quite far (thanks to -fhpc
):
{-# 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:
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.10.3
$ llc -version | head -2
LLVM (http://llvm.org/):
LLVM version 3.5.2
$
$ ghc -fforce-recomp -O2 Issue67.hs && ./Issue67
[1 of 1] Compiling Main ( Issue67.hs, Issue67.o )
Linking Issue67 ...
53169
$ ghc -fforce-recomp -O2 Issue67.hs -fllvm && ./Issue67
[1 of 1] Compiling Main ( Issue67.hs, Issue67.o )
Linking Issue67 ...
-12367
from cborg.
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
from cborg.
Reported as GHC bug #12095.
from cborg.
Not actually a GHC bug, this is our bug! Commit incoming with a fix...
from cborg.
@thoughtpolice nice work tracking it down!
from cborg.
Related Issues (20)
- Support GHC 9.4 HOT 1
- cborg-0.2.6+ fails to build for 32bit: Couldn't match expected type βInt64#β with actual type βInt#β etc HOT 3
- Alternative tags have now been standardised
- Build error on ghc 9.2.2 HOT 2
- `serialise` `versus` benchmark fails to parse internal cabal libraries
- Allow vector-0.13 (in serialise) HOT 2
- Add instances for wide-word
- cborg-0.2.8.0 fails to build with 32bit ghc9 HOT 2
- Support base-4.18, strict-0.5, these-1.2, criterion-1.6 (i.e. GHC-9.6) HOT 2
- ghc-9.4 build error on M1 HOT 6
- Test `decodeValue` against `Reference.termToJson`.
- hPutSerialise should use hPutBuilder? HOT 1
- Encoding allocates too many blocks in old generation HOT 3
- Remove dependency on `aeson-pretty`
- fromFlatTerm impl of PeekTokenType is insufficently precise
- Support ghc-9.8.1 HOT 4
- serialise: Usage without requiring `Serialise` instances HOT 3
- serialise: allow tar-0.6
- serialise: allow zlib-0.7
- Versions on master have fallen behind Hackage
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cborg.