#3948: unsafeCoerce leaks types
-------------------------------+--------------------------------------------
    Reporter:  ksf             |       Owner:                  
        Type:  bug             |      Status:  new             
    Priority:  normal          |   Component:  Template Haskell
     Version:  6.12.1          |    Keywords:                  
          Os:  Linux           |    Testcase:                  
Architecture:  x86_64 (amd64)  |     Failure:  None/Unknown    
-------------------------------+--------------------------------------------
 Forgive the cryptic summary, here's the code:

 {{{
 import Unsafe.Coerce
 import Foreign
 import Data.Bits

 foo = (unsafeCoerce (0.50094324::Float))::Int32
 bar = (unsafeCoerce (0.30295494::Float))::Int32

 main = print (foo, foo .&. 0xffffffff)
     >> print (bar, bar .&. 0xffffffff)
 }}}

 giving the output

 {{{
 % runhaskell bug.hs
 (1056980433,1056980433)
 (140502315506921,140502315506921)
 }}}

 {{{
 *Main> :t bar
 bar :: Int32
 *Main> bar
 140549560147177
 }}}

 where the too-big number changes from run to run, presumably because it
 has a different type-tag on each invocation. It does seem to include the
 correct data in the low 32 bits, though.

 I couldn't replicate this with compiled code, but both GHCi and TH exhibit
 this behaviour.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/3948>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to