[GHC] #10517: Unexpected behavior of unsafeCoerce converting Word32 to Word8

GHC ghc-devs at haskell.org
Sat Jun 13 21:39:36 UTC 2015


#10517: Unexpected behavior of unsafeCoerce converting Word32 to Word8
-------------------------------------+-------------------------------------
              Reporter:  svenk       |             Owner:
                  Type:  bug         |            Status:  new
              Priority:  normal      |         Milestone:
             Component:  Compiler    |           Version:  7.10.1
              Keywords:              |  Operating System:  Linux
          Architecture:  x86_64      |   Type of failure:  Incorrect result
  (amd64)                            |  at runtime
             Test Case:              |        Blocked By:
              Blocking:              |   Related Tickets:
Differential Revisions:              |
-------------------------------------+-------------------------------------
 The function `unsafeCoerce` behaves unexpected if it is used to convert
 `Word32` to `Word8`:

 {{{#!hs

 main = do
   -- prints 135
   print (fromIntegral (1234567 :: Word32) :: Word8)

   -- prints 1234567
   print (unsafeCoerce (1234567 :: Word32) :: Word8)
 }}}

 On the other hand coercing `Ptr Word32` to `Ptr Word8` or the other way
 around works perfectly fine.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10517>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list