[GHC] #12184: unsafeCoerce# causing invalid assembly generation

#12184: unsafeCoerce# causing invalid assembly generation -------------------------------------+------------------------------------- Reporter: osa1 | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Discovered by MichaelBurge on IRC: {{{#!haskell {-# LANGUAGE MagicHash #-} import GHC.Prim import GHC.Types x = D# ((unsafeCoerce# (5# :: Int#) :: Double#) +## 5.0##) main = putStrLn $ show x }}} Compile with GHC 7.8, 8.0.1 or HEAD: {{{ [1 of 1] Compiling Main ( weird.hs, weird.o ) /tmp/ghc23262_0/ghc_2.s: Assembler messages: /tmp/ghc23262_0/ghc_2.s:43:0: error: Error: junk `naughty x86_64 register' after expression `gcc' failed in phase `Assembler'. (Exit code: 1) }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12184 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12184: unsafeCoerce# causing invalid assembly generation -------------------------------------+------------------------------------- Reporter: osa1 | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by rwbarton): I don't really think this is a bug. You used `unsafeCoerce#` in an invalid way, and you were lucky enough to get an error message. From the documentation of `unsafeCoerce#`:
The following uses of {\tt unsafeCoerce\#} are supposed to work (i.e. not lead to spurious compile-time or run-time crashes):
* Casting an unboxed type to another unboxed type of the same size (but not coercions between floating-point and integral types)
-- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12184#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12184: unsafeCoerce# causing invalid assembly generation -------------------------------------+------------------------------------- Reporter: osa1 | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by osa1):
you were lucky enough to get an error message
But I did not get an error message! GHC is happily generating an assembly file with `naughty x86_64 register` in it! I think it should at least panic at that point instead of printing this. But ideally, the code generator would know more about the register set and do something sensible e.g. a proper error message ("unsafeCoerce# between float and int not supported as they live in separate registers" etc.). Really, I should be getting a panic. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12184#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12184: unsafeCoerce# causing invalid assembly generation -------------------------------------+------------------------------------- Reporter: osa1 | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): I agree with Omer. Moreover CoreLint should check for bogus use of `unsafeCoerce#`. Is anyone up for doing this? Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12184#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC