Giter Site home page Giter Site logo

Comments (11)

Shimuuar avatar Shimuuar commented on August 16, 2024

I couldn't reproduce issue. But here is observation fromIntegral (53169::Word16) == -12367::Int16.

from cborg.

thoughtpolice avatar thoughtpolice commented on August 16, 2024

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.

Mathnerd314 avatar Mathnerd314 commented on August 16, 2024

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.

dcoutts avatar dcoutts commented on August 16, 2024

Thanks for investigating. Yes, not good. Should get to the bottom of it.

from cborg.

thoughtpolice avatar thoughtpolice commented on August 16, 2024

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.

thoughtpolice avatar thoughtpolice commented on August 16, 2024

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.

thoughtpolice avatar thoughtpolice commented on August 16, 2024

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.

thoughtpolice avatar thoughtpolice commented on August 16, 2024

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.

thoughtpolice avatar thoughtpolice commented on August 16, 2024

Reported as GHC bug #12095.

from cborg.

thoughtpolice avatar thoughtpolice commented on August 16, 2024

Not actually a GHC bug, this is our bug! Commit incoming with a fix...

from cborg.

dcoutts avatar dcoutts commented on August 16, 2024

@thoughtpolice nice work tracking it down!

from cborg.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.